Skip to content

Commit

Permalink
Merge branch 'main' into IA-1940-add-permission-user-management
Browse files Browse the repository at this point in the history
  • Loading branch information
hakifran committed May 24, 2024
2 parents 66189d8 + 8be0f48 commit 01e1b3a
Show file tree
Hide file tree
Showing 25 changed files with 413 additions and 223 deletions.
13 changes: 11 additions & 2 deletions hat/assets/js/apps/Iaso/components/DisplayIfUserHasPerm.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { FunctionComponent, ReactElement } from 'react';
import { userHasOneOfPermissions } from '../domains/users/utils';
import {
userHasAllPermissions,
userHasOneOfPermissions,
} from '../domains/users/utils';
import { useCurrentUser } from '../utils/usersUtils';

type Props = {
Expand All @@ -10,10 +13,16 @@ type Props = {
export const DisplayIfUserHasPerm: FunctionComponent<Props> = ({
permissions,
children,
strict = false,
}) => {
const currentUser = useCurrentUser();
if (userHasOneOfPermissions(permissions, currentUser) && children) {
if (strict) {
if (userHasAllPermissions(permissions, currentUser) && children) {
return children;
}
} else if (userHasOneOfPermissions(permissions, currentUser) && children) {
return children;
}

return null;
};
62 changes: 31 additions & 31 deletions hat/assets/js/apps/Iaso/constants/routes.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
/* eslint-disable react/jsx-props-no-spreading */
import React, { ReactElement } from 'react';
import PageError from '../components/errors/PageError';
import { Assignments } from '../domains/assignments';
import Completeness from '../domains/completeness';
import { CompletenessStats } from '../domains/completenessStats';
import DataSources from '../domains/dataSources';
import { Details as DataSourceDetail } from '../domains/dataSources/details';
import Devices from '../domains/devices';
import { Beneficiaries } from '../domains/entities';
import { VisitDetails } from '../domains/entities/components/VisitDetails';
import { Details as BeneficiaryDetail } from '../domains/entities/details';
import { DuplicateDetails } from '../domains/entities/duplicates/details/DuplicateDetails';
import { Duplicates } from '../domains/entities/duplicates/list/Duplicates';
import { EntityTypes } from '../domains/entities/entityTypes';
import Forms from '../domains/forms';
import FormDetail from '../domains/forms/detail';
import FormsStats from '../domains/forms/stats';
import { OrgUnits } from '../domains/orgUnits';
import { Links } from '../domains/links';
import Runs from '../domains/links/Runs';
import OrgUnitDetail from '../domains/orgUnits/details';
import Completeness from '../domains/completeness';
import Instances from '../domains/instances';
import CompareSubmissions from '../domains/instances/compare';
import { CompareInstanceLogs } from '../domains/instances/compare/components/CompareInstanceLogs';
import InstanceDetail from '../domains/instances/details';
import { Links } from '../domains/links';
import Runs from '../domains/links/Runs';
import Mappings from '../domains/mappings';
import MappingDetails from '../domains/mappings/details';
import { Users } from '../domains/users';
import { UserRoles } from '../domains/userRoles';
import { Modules } from '../domains/modules';
import { Projects } from '../domains/projects';
import DataSources from '../domains/dataSources';
import { Details as DataSourceDetail } from '../domains/dataSources/details';
import Tasks from '../domains/tasks';
import Devices from '../domains/devices';
import { CompletenessStats } from '../domains/completenessStats';
import { OrgUnits } from '../domains/orgUnits';
import OrgUnitDetail from '../domains/orgUnits/details';
import Groups from '../domains/orgUnits/groups';
import Types from '../domains/orgUnits/orgUnitTypes';
import { Beneficiaries } from '../domains/entities';
import { Details as BeneficiaryDetail } from '../domains/entities/details';
import { EntityTypes } from '../domains/entities/entityTypes';
import PageError from '../components/errors/PageError';
import { baseUrls } from './urls';
import { ReviewOrgUnitChanges } from '../domains/orgUnits/reviewChanges/ReviewOrgUnitChanges';
import Pages from '../domains/pages';
import { LotsPayments } from '../domains/payments/LotsPayments';
import { PotentialPayments } from '../domains/payments/PotentialPayments';
import { Planning } from '../domains/plannings';
import { Teams } from '../domains/teams';
import { Projects } from '../domains/projects';
import { Registry } from '../domains/registry';
import { SetupAccount } from '../domains/setup';
import { Storages } from '../domains/storages';
import { Details as StorageDetails } from '../domains/storages/details';
import Tasks from '../domains/tasks';
import { Teams } from '../domains/teams';
import { UserRoles } from '../domains/userRoles';
import { Users } from '../domains/users';
import { Workflows } from '../domains/workflows';
import { Details as WorkflowDetails } from '../domains/workflows/details';
import { Details as StorageDetails } from '../domains/storages/details';
import { Assignments } from '../domains/assignments';
import { CompareInstanceLogs } from '../domains/instances/compare/components/CompareInstanceLogs';
import { Registry } from '../domains/registry';
import { SHOW_PAGES } from '../utils/featureFlags';
import { Duplicates } from '../domains/entities/duplicates/list/Duplicates';
import { DuplicateDetails } from '../domains/entities/duplicates/details/DuplicateDetails';
import { ReviewOrgUnitChanges } from '../domains/orgUnits/reviewChanges/ReviewOrgUnitChanges';
import { VisitDetails } from '../domains/entities/components/VisitDetails';
import * as Permission from '../utils/permissions';
import { SetupAccount } from '../domains/setup';
import { PotentialPayments } from '../domains/payments/PotentialPayments';
import { LotsPayments } from '../domains/payments/LotsPayments';
import { baseUrls } from './urls';

export type RoutePath = {
baseUrl: string;
Expand Down Expand Up @@ -165,7 +165,7 @@ export const orgUnitChangeRequestPath = {
export const registryPath = {
baseUrl: baseUrls.registry,
routerUrl: `${baseUrls.registry}/*`,
permissions: [Permission.REGISTRY],
permissions: [Permission.REGISTRY_READ, Permission.REGISTRY_WRITE],
element: <Registry />,
};

Expand Down
6 changes: 4 additions & 2 deletions hat/assets/js/apps/Iaso/domains/app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@
"iaso.permissions.iaso_polio_vaccine_supply_chain_read_tooltip": "See summary of vaccine supply chain, by country and vaccine",
"iaso.permissions.iaso_polio_vaccine_supply_chain_write": "Polio vaccine supply chain - Write",
"iaso.permissions.iaso_polio_vaccine_supply_chain_write_tooltip": "Edit and add supply chain data",
"iaso.permissions.iaso_registry": "Registry",
"iaso.permissions.iaso_registry_read": "Registry - Read",
"iaso.permissions.iaso_registry_write": "Registry - Write",
"iaso.permissions.iaso_workflows": "Workflows",
"iaso.permissions.iaso_write_sources": "Geo data sources - Read and Write",
"iaso.permissions.links": "Geo data sources matching",
Expand Down Expand Up @@ -972,7 +973,8 @@
"iaso.permissions.tooltip.iaso_org_unit_types": "Manage types of organisation units, i.e. define the different levels of the pyramid (eg Country/Region/District/Facility/etc)",
"iaso.permissions.tooltip.iaso_page_write": "External links management: create or edit an external link",
"iaso.permissions.tooltip.iaso_polio_notifications": "Manage polio notifications - Read and Write",
"iaso.permissions.tooltip.iaso_registry": "Summary view of data collected per organisation unit",
"iaso.permissions.tooltip.iaso_registry_read": "Summary view of data collected per organisation unit - Read",
"iaso.permissions.tooltip.iaso_registry_write": "Summary view of data collected per organisation unit - Write",
"iaso.permissions.tooltip.iaso_write_sources": "Manage multiple geo data sources: create or edit sources (name, description, project(s), default version, DHIS2 links)",
"iaso.permissions.tooltip.links": "Match multiple geo data sources according to specific criteria and algorithms",
"iaso.permissions.tooltip.mappings": "Match DHIS2 and IASO data elements for data exchanges",
Expand Down
6 changes: 4 additions & 2 deletions hat/assets/js/apps/Iaso/domains/app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -939,7 +939,8 @@
"iaso.permissions.iaso_polio_vaccine_supply_chain_read_tooltip": "Voir le résumé des données de chaîne d'approvisionnement",
"iaso.permissions.iaso_polio_vaccine_supply_chain_write": "Polio: chaîne d'approvisionnement - Ecriture",
"iaso.permissions.iaso_polio_vaccine_supply_chain_write_tooltip": "Editer et ajouter des données",
"iaso.permissions.iaso_registry": "Registre",
"iaso.permissions.iaso_registry_read": "Registre - Lecture",
"iaso.permissions.iaso_registry_write": "Registre - Ecriture",
"iaso.permissions.iaso_workflows": "Workflows",
"iaso.permissions.iaso_write_sources": "Sources de données géo - Lecture et écriture",
"iaso.permissions.links": "Liens entre sources de données géo",
Expand Down Expand Up @@ -972,7 +973,8 @@
"iaso.permissions.tooltip.iaso_org_unit_types": "Gestion des types d’unité d’organisation, i.e. définir les différents niveaux de la pyramide (ex: Pays/Région/Aire/Formation sanitaire)",
"iaso.permissions.tooltip.iaso_page_write": "Gestion des liens externes : créer ou modifier un lien externe",
"iaso.permissions.tooltip.iaso_polio_notifications": "Manage polio notifications - Read and Write",
"iaso.permissions.tooltip.iaso_registry": "Vue résumée des données collectées par unité d’organisation",
"iaso.permissions.tooltip.iaso_registry_read": "Vue résumée des données collectées par unité d’organisation - Lecture",
"iaso.permissions.tooltip.iaso_registry_write": "Vue résumée des données collectées par unité d’organisation - Ecriture",
"iaso.permissions.tooltip.iaso_write_sources": "Gestion des sources de données géographiques: créer ou éditer (nom, description, projet(s), version par défaut, liens DHIS2)",
"iaso.permissions.tooltip.links": "Liens entre les sources de données géographiques selon des critères spécifiques et des algorithmes",
"iaso.permissions.tooltip.mappings": "Edition des liens entre les éléments de données DHIS2 et IASO pour les échanges de données",
Expand Down
41 changes: 21 additions & 20 deletions hat/assets/js/apps/Iaso/domains/instances/utils/index.tsx
Original file line number Diff line number Diff line change
@@ -1,53 +1,53 @@
/* eslint-disable camelcase */
import React, {
FunctionComponent,
ReactElement,
useMemo,
useCallback,
} from 'react';
import moment from 'moment';
import { Tooltip } from '@mui/material';
import CompareArrowsIcon from '@mui/icons-material/CompareArrows';
import CallMade from '@mui/icons-material/CallMade';
import CompareArrowsIcon from '@mui/icons-material/CompareArrows';
import { Tooltip } from '@mui/material';
import {
truncateText,
getTableUrl,
Column,
Setting,
LinkWithLocation,
RenderCell,
Setting,
getTableUrl,
truncateText,
useSafeIntl,
LinkWithLocation,
} from 'bluesquare-components';
import moment from 'moment';
import React, {
FunctionComponent,
ReactElement,
useCallback,
useMemo,
} from 'react';

import instancesTableColumns from '../config';
import MESSAGES from '../messages';
import { VisibleColumn } from '../types/visibleColumns';
import { Instance, ShortFile } from '../types/instance';
import { VisibleColumn } from '../types/visibleColumns';

import { getCookie } from '../../../utils/cookies';
import {
apiDateTimeFormat,
apiDateFormat,
apiDateTimeFormat,
getFromDateString,
getToDateString,
} from '../../../utils/dates';
import ActionTableColumnComponent from '../components/ActionTableColumnComponent';
import { Form, PossibleField } from '../../forms/types/forms';
import { getCookie } from '../../../utils/cookies';
import ActionTableColumnComponent from '../components/ActionTableColumnComponent';

import DeleteDialog from '../components/DeleteInstanceDialog';
import ExportInstancesDialogComponent from '../components/ExportInstancesDialogComponent';

import { fetchLatestOrgUnitLevelId } from '../../orgUnits/utils';
import { baseUrls } from '../../../constants/urls';
import { fetchLatestOrgUnitLevelId } from '../../orgUnits/utils';

import { Selection } from '../../orgUnits/types/selection';

import { userHasOneOfPermissions, userHasPermission } from '../../users/utils';

import { useCurrentUser } from '../../../utils/usersUtils';
import * as Permission from '../../../utils/permissions';
import { INSTANCE_METAS_FIELDS } from '../constants';
import { useCurrentUser } from '../../../utils/usersUtils';
import { InstanceMetasField } from '../components/ColumnSelect';
import { INSTANCE_METAS_FIELDS } from '../constants';

const NO_VALUE = '/';
// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -287,6 +287,7 @@ export const useInstancesColumns = (
});
tableColumns = tableColumns.concat(childrenArray);
if (
userHasPermission(Permission.REGISTRY_WRITE, currentUser) &&
userHasOneOfPermissions(
[Permission.SUBMISSIONS_UPDATE, Permission.SUBMISSIONS],
currentUser,
Expand Down
19 changes: 9 additions & 10 deletions hat/assets/js/apps/Iaso/domains/registry/components/ActionCell.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,24 @@
import { IconButton as IconButtonComponent } from 'bluesquare-components';
import React, { FunctionComponent } from 'react';
import { useQueryClient } from 'react-query';
import { IconButton as IconButtonComponent } from 'bluesquare-components';

import MESSAGES from '../messages';
import { userHasPermission } from '../../users/utils';
import { useCurrentUser } from '../../../utils/usersUtils';

import EnketoIcon from '../../instances/components/EnketoIcon';
import DeleteDialog from '../../../components/dialogs/DeleteDialogComponent';
import EnketoIcon from '../../instances/components/EnketoIcon';

import { LinkToInstance } from '../../instances/components/LinkToInstance';

import { useGetEnketoUrl } from '../hooks/useGetEnketoUrl';
import { DisplayIfUserHasPerm } from '../../../components/DisplayIfUserHasPerm';
import * as Permissions from '../../../utils/permissions';
import { useDeleteInstance } from '../../instances/hooks/requests/useDeleteInstance';
import * as Permission from '../../../utils/permissions';
import { useGetEnketoUrl } from '../hooks/useGetEnketoUrl';

type Props = {
settings: any;
};

export const ActionCell: FunctionComponent<Props> = ({ settings }) => {
const user = useCurrentUser();

const queryClient = useQueryClient();
const getEnketoUrl = useGetEnketoUrl(
window.location.href,
Expand All @@ -37,7 +34,9 @@ export const ActionCell: FunctionComponent<Props> = ({ settings }) => {
return (
<section>
<LinkToInstance instanceId={settings.row.original.id} useIcon />
{userHasPermission(Permission.SUBMISSIONS_UPDATE, user) && (
<DisplayIfUserHasPerm
permissions={[Permissions.SUBMISSIONS_UPDATE]}
>
<>
<IconButtonComponent
onClick={() => getEnketoUrl()}
Expand All @@ -54,7 +53,7 @@ export const ActionCell: FunctionComponent<Props> = ({ settings }) => {
}
/>
</>
)}
</DisplayIfUserHasPerm>
</section>
);
};
Loading

0 comments on commit 01e1b3a

Please sign in to comment.