Skip to content

Commit

Permalink
Merge pull request #1775 from BLSQ/HOTFIX_prevent_overwrite_by_empty_…
Browse files Browse the repository at this point in the history
…projects

IA-3609: prevent edition of project field by non admin
  • Loading branch information
quang-le authored Nov 5, 2024
2 parents fe0344d + 047a5f3 commit 680cd6c
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 0 deletions.
1 change: 1 addition & 0 deletions hat/assets/js/apps/Iaso/domains/app/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -1455,6 +1455,7 @@
"iaso.users.selectAllHelperText": "Leave empty to select all",
"iaso.users.selectedOrgUnits": "Org units selected",
"iaso.users.update": "Update user",
"iaso.users.userAdminOnly": "Can only be edited by user admin",
"iaso.users.userPermissions": "User permissions",
"iaso.users.usersHistory": "Users history",
"iaso.users.warningModalMessage": "You are about to save a user with no permissions. This user will have access to the mobile application but not to the features of the web interface.",
Expand Down
1 change: 1 addition & 0 deletions hat/assets/js/apps/Iaso/domains/app/translations/fr.json
Original file line number Diff line number Diff line change
Expand Up @@ -1454,6 +1454,7 @@
"iaso.users.selectAllHelperText": "Laisser vide pour tout sélectionner",
"iaso.users.selectedOrgUnits": "Unité d'organisation sélectionnées",
"iaso.users.update": "Mettre l'utilisateur à jour",
"iaso.users.userAdminOnly": "Edition pour les administrateurs uniquement",
"iaso.users.userPermissions": "Permissions d'utilisateur",
"iaso.users.usersHistory": "Historique des utilisateurs",
"iaso.users.warningModalMessage": "Vous êtes sur le point de sauvegarder un utilisateur sans permissions. Cet utilisateur aura accès à l'application mobile mais pas aux fonctionnalités de l'interface web.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import { useGetProjectsDropdownOptions } from '../../projects/hooks/requests.ts'
import { InputWithInfos } from '../../../components/InputWithInfos.tsx';
import { useCurrentUser } from '../../../utils/usersUtils.ts';
import MESSAGES from '../messages.ts';
import { userHasPermission } from '../utils.js';
import { USERS_ADMIN } from '../../../utils/permissions';

const UsersInfos = ({
setFieldValue,
Expand All @@ -20,6 +22,7 @@ const UsersInfos = ({
allowSendEmailInvitation,
}) => {
const loggedUser = useCurrentUser();
const isLoggedUserAdmin = userHasPermission(USERS_ADMIN, loggedUser);
const { formatMessage } = useSafeIntl();
const isEmailAdressExist = isEmpty(currentUser.email.value);
const sendUserEmailInvitation = !!isEmailAdressExist;
Expand Down Expand Up @@ -170,6 +173,12 @@ const UsersInfos = ({
label={MESSAGES.projects}
options={availableProjects}
loading={isFetchingProjects}
disabled={!isLoggedUserAdmin}
helperText={
!isLoggedUserAdmin
? formatMessage(MESSAGES.userAdminOnly)
: undefined
}
/>
<InputComponent
keyValue="language"
Expand Down
4 changes: 4 additions & 0 deletions hat/assets/js/apps/Iaso/domains/users/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,10 @@ const MESSAGES = defineMessages({
id: 'iaso.users.selectAllHelperText',
defaultMessage: 'Leave empty to select all',
},
userAdminOnly: {
id: 'iaso.users.userAdminOnly',
defaultMessage: 'Can only be edited by user admin',
},
});

export default MESSAGES;

0 comments on commit 680cd6c

Please sign in to comment.