Skip to content

Commit e5a0efc

Browse files
committed
[#225] Fix corner-case for canWriteUserInfo
The corner-case not covered was when both users were not assigned to organization.
1 parent 55b3697 commit e5a0efc

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/utils/RoleUtils.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,13 @@ export function canReadRecord(currentUser, record) {
6363
}
6464

6565
export function canWriteUserInfo(currentUser, user) {
66+
const hasSameInstitution =
67+
currentUser.institution !== null && currentUser.institution?.name === user?.institution?.name;
6668
return (
67-
hasSupersetOfPrivileges(currentUser, user) &&
68-
(hasRole(currentUser, ROLE.WRITE_ALL_USERS) ||
69-
(hasRole(currentUser, ROLE.WRITE_ORGANIZATION_USERS) &&
70-
currentUser.institution?.name === user?.institution?.name) ||
71-
currentUser.username === user?.username)
69+
(currentUser.username === user?.username ||
70+
hasRole(currentUser, ROLE.WRITE_ALL_USERS) ||
71+
(hasSameInstitution && hasRole(currentUser, ROLE.WRITE_ORGANIZATION_USERS))) &&
72+
hasSupersetOfPrivileges(currentUser, user)
7273
);
7374
}
7475

0 commit comments

Comments
 (0)