Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IA-3102: Permissions : Org unit “view only” permission #1558

Merged
merged 7 commits into from
Aug 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions hat/assets/js/apps/Iaso/constants/routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,14 +152,14 @@ export const mappingDetailPath = {
export const orgUnitsPath = {
baseUrl: baseUrls.orgUnits,
routerUrl: `${baseUrls.orgUnits}/*`,
permissions: [Permission.ORG_UNITS],
permissions: [Permission.ORG_UNITS, Permission.ORG_UNITS_READ],
element: <OrgUnits />,
};

export const orgUnitsDetailsPath = {
baseUrl: baseUrls.orgUnitDetails,
routerUrl: `${baseUrls.orgUnitDetails}/*`,
permissions: [Permission.ORG_UNITS],
permissions: [Permission.ORG_UNITS, Permission.ORG_UNITS_READ],
element: <OrgUnitDetail />,
};

Expand Down
2 changes: 2 additions & 0 deletions hat/assets/js/apps/Iaso/domains/app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@
"iaso.permissions.mappings": "DHIS2 mappings",
"iaso.permissions.modules": "Modules",
"iaso.permissions.orgUnits": "Organisation units management",
"iaso.permissions.orgUnits_read": "Organisation units - Read",
"iaso.permissions.pages": "Web embedded links management - Read only",
"iaso.permissions.planning": "Planning",
"iaso.permissions.planning_read": "Planning - Read",
Expand Down Expand Up @@ -998,6 +999,7 @@
"iaso.permissions.tooltip.mappings": "Match DHIS2 and IASO data elements for data exchanges",
"iaso.permissions.tooltip.modules": "View modules linked to the current account",
"iaso.permissions.tooltip.orgUnits": "Manage organisation units and pyramids, including uploading of geo data (GPS coordinates and shapes), and groups",
"iaso.permissions.tooltip.orgUnits_read": "See and read organisation units and pyramids",
"iaso.permissions.tooltip.pages": "List of external links (dashboards for instance)",
"iaso.permissions.tooltip.planning_read": "See and read planning",
"iaso.permissions.tooltip.planning_write": "Edit and add planning",
Expand Down
2 changes: 2 additions & 0 deletions hat/assets/js/apps/Iaso/domains/app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@
"iaso.permissions.mappings": "Liens avec DHIS2",
"iaso.permissions.modules": "Modules",
"iaso.permissions.orgUnits": "Gestion des unités d’organisation",
"iaso.permissions.orgUnits_read": "Unités d'organisation - Lecture",
"iaso.permissions.pages": "Gestion des liens intégrés web - lecture seule",
"iaso.permissions.planning": "Planning",
"iaso.permissions.planning_read": "Planification - Lire",
Expand Down Expand Up @@ -998,6 +999,7 @@
"iaso.permissions.tooltip.mappings": "Edition des liens entre les éléments de données DHIS2 et IASO pour les échanges de données",
"iaso.permissions.tooltip.modules": "Voir les modules liés au compte courant",
"iaso.permissions.tooltip.orgUnits": "Gestion des unités d’organisation et de la pyramide, y compris le chargement de données géographiques (points GPS et contours) et la gestion des groupes",
"iaso.permissions.tooltip.orgUnits_read": "Voir et lire les unités d'organisation et les pyramides",
"iaso.permissions.tooltip.pages": "Liste des liens externes (tableaux de bords par exemple)",
"iaso.permissions.tooltip.planning_read": "Voir et lire le planning",
"iaso.permissions.tooltip.planning_write": "Modifier et ajouter une planification",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ const SpeedDialInstance: FunctionComponent<Props> = props => {

const actions = [...baseActions, deleteRestore];

if (!isGpsEqual) {
if (!isGpsEqual && userHasPermission(Permission.ORG_UNITS, currentUser)) {
actions.unshift(editLocationWithInstanceGps);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import { Search } from '../types/search';
import { decodeSearch } from '../utils';

import MESSAGES from '../messages';
import { DisplayIfUserHasPerm } from '../../../components/DisplayIfUserHasPerm';
import { ORG_UNITS } from '../../../utils/permissions';

type Props = {
params: OrgUnitParams;
Expand Down Expand Up @@ -210,21 +212,23 @@ export const OrgUnitFiltersContainer: FunctionComponent<Props> = ({
</Box>
))}
<Box mt={2} justifyContent="flex-end" display="flex">
<Box display="inline-block" mr={2}>
<Button
variant="contained"
className={classnames(classes.button)}
color="primary"
onClick={() =>
redirectTo(baseUrls.orgUnitDetails, {
orgUnitId: '0',
})
}
>
<Add className={classes.buttonIcon} />
{formatMessage(MESSAGES.create)}
</Button>
</Box>
<DisplayIfUserHasPerm permissions={[ORG_UNITS]}>
<Box display="inline-block" mr={2}>
<Button
variant="contained"
className={classnames(classes.button)}
color="primary"
onClick={() =>
redirectTo(baseUrls.orgUnitDetails, {
orgUnitId: '0',
})
}
>
<Add className={classes.buttonIcon} />
{formatMessage(MESSAGES.create)}
</Button>
</Box>
</DisplayIfUserHasPerm>
<SearchButton
disabled={textSearchError || hasLocationLimitError}
onSearch={handleSearch}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import { Group, OrgUnit, OrgUnitState } from '../types/orgUnit';
import { OrgunitType } from '../types/orgunitTypes';
import { OrgUnitMultiReferenceInstances } from './OrgUnitMultiReferenceInstances';
import { useGetOrgUnit } from './TreeView/requests';
import { DisplayIfUserHasPerm } from '../../../components/DisplayIfUserHasPerm';
import { ORG_UNITS } from '../../../utils/permissions';

const useStyles = makeStyles(theme => ({
speedDialTop: {
Expand Down Expand Up @@ -191,42 +193,48 @@ export const OrgUnitInfos: FunctionComponent<Props> = ({
keyDateFrom="opening_date"
keyDateTo="closed_date"
onChangeDate={onChangeInfo}
dateFrom={orgUnitState.opening_date.value}
dateTo={orgUnitState.closed_date.value}
dateFrom={
orgUnitState.opening_date.value as string | undefined
}
dateTo={
orgUnitState.closed_date.value as string | undefined
}
labelFrom={MESSAGES.openingDate}
labelTo={MESSAGES.closingDate}
marginTop={0}
/>
<Grid
container
item
xs={12}
justifyContent="flex-end"
alignItems="center"
>
<Box mt={1}>
{!isNewOrgunit && (
<DisplayIfUserHasPerm permissions={[ORG_UNITS]}>
<Grid
container
item
xs={12}
justifyContent="flex-end"
alignItems="center"
>
<Box mt={1}>
{!isNewOrgunit && (
<Button
className={classes.marginLeft}
disabled={!orgUnitModified}
variant="contained"
onClick={() => handleReset()}
>
{formatMessage(MESSAGES.cancel)}
</Button>
)}
<Button
className={classes.marginLeft}
disabled={!orgUnitModified}
id="save-ou"
disabled={isSaveDisabled}
variant="contained"
onClick={() => handleReset()}
className={classes.marginLeft}
color="primary"
onClick={handleSave}
>
{formatMessage(MESSAGES.cancel)}
{formatMessage(MESSAGES.save)}
</Button>
)}
<Button
id="save-ou"
disabled={isSaveDisabled}
variant="contained"
className={classes.marginLeft}
color="primary"
onClick={handleSave}
>
{formatMessage(MESSAGES.save)}
</Button>
</Box>
</Grid>
</Box>
</Grid>
</DisplayIfUserHasPerm>
</Grid>

<Grid item xs={12} md={4}>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ import MESSAGES from '../messages';

// HOOKS
import { useGetOrgUnitsTableColumns } from '../hooks/useGetOrgUnitsTableColumns';
import { userHasPermission } from '../../users/utils';
import { ORG_UNITS } from '../../../utils/permissions';
import { useCurrentUser } from '../../../utils/usersUtils';
// HOOKS

type Props = {
Expand All @@ -54,7 +57,7 @@ export const TableList: FunctionComponent<Props> = ({
saveMulti,
}) => {
const { formatMessage } = useSafeIntl();

const currentUser = useCurrentUser();
const [multiActionPopupOpen, setMultiActionPopupOpen] =
useState<boolean>(false);
const [selection, setSelection] = useState<Selection<OrgUnit>>(
Expand All @@ -69,7 +72,8 @@ export const TableList: FunctionComponent<Props> = ({
const columns = useGetOrgUnitsTableColumns(searches);

const multiEditDisabled =
!selection.selectAll && selection.selectedItems.length === 0;
!userHasPermission(ORG_UNITS, currentUser) ||
(!selection.selectAll && selection.selectedItems.length === 0);

const handleTableSelection = useCallback(
(selectionType, items = [], totalCount = 0) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import { CustomZoomControl } from '../../../../../components/maps/tools/CustomZo
import * as Permission from '../../../../../utils/permissions';
import { DisplayIfUserHasPerm } from '../../../../../components/DisplayIfUserHasPerm';
import { InnerDrawer } from '../../../../../components/nav/InnerDrawer/Index';
import { userHasPermission } from '../../../../users/utils';

export const zoom = 5;
export const padding = [75, 75];
Expand Down Expand Up @@ -382,6 +383,12 @@ export const OrgUnitMap: FunctionComponent<Props> = ({
latitude: [],
longitude: [],
});

const hasEditPermission = userHasPermission(
Permission.ORG_UNITS,
currentUser,
);

return (
<Grid container spacing={0}>
<InnerDrawer
Expand Down Expand Up @@ -437,32 +444,38 @@ export const OrgUnitMap: FunctionComponent<Props> = ({
</>
}
editOptionComponent={
<EditOrgUnitOptionComponent
orgUnit={currentOrgUnit}
canEditLocation={state.canEditLocation.value}
canEditCatchment={state.canEditCatchment.value}
locationState={state.location.value}
catchmentState={state.catchment.value}
toggleEditShape={keyValue => toggleEditShape(keyValue)}
toggleDeleteShape={keyValue =>
toggleDeleteShape(keyValue)
}
isCreatingMarker={isCreatingMarker}
toggleAddShape={keyValue => toggleAddShape(keyValue)}
toggleAddMarker={() => {
setIsCreatingMarker(!isCreatingMarker);
state.locationGroup.value.toggleDrawMarker(
!isCreatingMarker,
);
}}
addShape={shapeType => addShape(shapeType)}
onChangeLocation={latLong => {
setIsCreatingMarker(false);
onChangeLocation(latLong);
}}
errorsCoordinates={errorsCoordinates}
setErrorsCoordinates={setErrorsCoordinates}
/>
hasEditPermission && (
<EditOrgUnitOptionComponent
orgUnit={currentOrgUnit}
canEditLocation={state.canEditLocation.value}
canEditCatchment={state.canEditCatchment.value}
locationState={state.location.value}
catchmentState={state.catchment.value}
toggleEditShape={keyValue =>
toggleEditShape(keyValue)
}
toggleDeleteShape={keyValue =>
toggleDeleteShape(keyValue)
}
isCreatingMarker={isCreatingMarker}
toggleAddShape={keyValue =>
toggleAddShape(keyValue)
}
toggleAddMarker={() => {
setIsCreatingMarker(!isCreatingMarker);
state.locationGroup.value.toggleDrawMarker(
!isCreatingMarker,
);
}}
addShape={shapeType => addShape(shapeType)}
onChangeLocation={latLong => {
setIsCreatingMarker(false);
onChangeLocation(latLong);
}}
errorsCoordinates={errorsCoordinates}
setErrorsCoordinates={setErrorsCoordinates}
/>
)
}
commentsOptionComponent={
<OrgUnitsMapComments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ import ValueWithErrorBoundary from './ValueWithErrorBoundary';

import MESSAGES from '../../forms/messages';
import { MESSAGES as LOG_MESSAGES } from './messages';
import { DisplayIfUserHasPerm } from '../../../components/DisplayIfUserHasPerm.tsx';
import { ORG_UNITS } from '../../../utils/permissions.ts';

const useStyles = makeStyles(theme => ({
...commonStyles(theme),
Expand Down Expand Up @@ -183,40 +185,42 @@ const LogCompareComponent = ({
alignItems="center"
justifyContent="center"
>
<Grid xs={6} item>
<ConfirmDialog
btnMessage={formatMessage(
LOG_MESSAGES.goToRevision,
)}
question={formatMessage(
LOG_MESSAGES.goToRevisionQuestion,
)}
message={formatMessage(
LOG_MESSAGES.goToRevisionText,
)}
confirm={() => goToRevision(l)}
/>
</Grid>
{isNewValue && (
<DisplayIfUserHasPerm permissions={[ORG_UNITS]}>
<Grid xs={6} item>
<ConfirmDialog
btnMessage={formatMessage(
LOG_MESSAGES.goToRevisionChanges,
LOG_MESSAGES.goToRevision,
)}
question={formatMessage(
LOG_MESSAGES.goToRevisionQuestion,
)}
message={formatMessage(
LOG_MESSAGES.goToRevisionTextChanges,
LOG_MESSAGES.goToRevisionText,
)}
confirm={() =>
goToRevision({
fields: differenceArray[i],
})
}
confirm={() => goToRevision(l)}
/>
</Grid>
)}
{isNewValue && (
<Grid xs={6} item>
<ConfirmDialog
btnMessage={formatMessage(
LOG_MESSAGES.goToRevisionChanges,
)}
question={formatMessage(
LOG_MESSAGES.goToRevisionQuestion,
)}
message={formatMessage(
LOG_MESSAGES.goToRevisionTextChanges,
)}
confirm={() =>
goToRevision({
fields: differenceArray[i],
})
}
/>
</Grid>
)}
</DisplayIfUserHasPerm>
</Grid>
</Paper>
);
Expand Down
Loading
Loading