Skip to content

Commit

Permalink
#887 | Use updated privileges from models. Fix logic for CurrentUser…
Browse files Browse the repository at this point in the history
…Service.isAllowedToAccess
  • Loading branch information
Suhas Vishwanath committed Jul 21, 2023
1 parent c77d372 commit a8e5178
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 2,466 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"material-ui-rc-color-picker": "^1.0.4",
"moment": "^2.22.2",
"openchs-idi": "git+https://github.com/avniproject/openchs-idi#b6c57e051b91ed4bc2634f4f087dba51cc3a01c8",
"openchs-models": "1.30.43",
"openchs-models": "1.30.44",
"popper.js": "^1.14.3",
"prismjs": "^1.17.1",
"prop-types": "^15.7.2",
Expand Down
4 changes: 3 additions & 1 deletion src/common/service/CurrentUserService.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import UserInfo from "../model/UserInfo";
class CurrentUserService {
static isAllowedToAccess(userInfo: UserInfo, resourcePrivileges) {
let uInfo = userInfo || {};
let userPrivileges = uInfo.privileges || [];
let userPrivilegeTypes = userPrivileges.map(u => u.privilegeType);
return (
uInfo.hasAllPrivileges ||
_.isEmpty(resourcePrivileges) ||
!_.isEmpty(_.intersection(resourcePrivileges, uInfo.privileges))
!_.isEmpty(_.intersection(resourcePrivileges, userPrivilegeTypes))
);
}

Expand Down
35 changes: 21 additions & 14 deletions src/rootApp/views/Homepage.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,20 @@ const Homepage = ({ user }) => {
}, []);
const showAssignment = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.EditTask,
Privilege.PrivilegeType.DeleteTask
Privilege.PrivilegeType.DeleteTask,
Privilege.PrivilegeType.EditUserConfiguration
]);
const canEditOrganisationConfig = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.EditOrganisationConfiguration
const showNews = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.EditNews
]);
const showTranslations = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.EditLanguage
]);
const showDocumentation = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.EditDocumentation
]);
const showReports = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.Reports
const showAnalytics = CurrentUserService.isAllowedToAccess(userData, [
Privilege.PrivilegeType.Analytics
]);

return (
Expand All @@ -48,26 +52,29 @@ const Homepage = ({ user }) => {
customIcon={"assignment_turned_in"}
/>
)}
{canEditOrganisationConfig && (
{showNews && (
<HomePageCard
href={"/#/broadcast"}
name={"Broadcast"}
customIconComponent={<SurroundSound color="primary" style={{ fontSize: 100 }} />}
/>
)}
{canEditOrganisationConfig && (
{showTranslations && (
<HomePageCard href={"/#/translations"} name={"Translations"} customIcon={"translate"} />
)}
{showReports && (
{showAnalytics && (
<HomePageCard href={"/#/export"} name={"Reports"} customIcon={"assessment"} />
)}
<HomePageCard href={"/#/app"} name={"Data Entry App"} customIcon={"keyboard"} />
<HomePageCard
href={`/avni-media?orgID=${userData && userData.organisationId}&username=${userData &&
userData.username}`}
name={"Media Viewer "}
customIcon={"collections"}
/>

{showAnalytics && (
<HomePageCard
href={`/avni-media?orgID=${userData && userData.organisationId}&username=${userData &&
userData.username}`}
name={"Media Viewer "}
customIcon={"collections"}
/>
)}
<HomePageCard href={"/#/help"} name={"Support And Training"} customIcon={"help"} />
</Grid>
</ScreenWithAppBar>
Expand Down
Loading

0 comments on commit a8e5178

Please sign in to comment.