Skip to content

Commit

Permalink
WIP for #310
Browse files Browse the repository at this point in the history
  • Loading branch information
oharsta committed Sep 18, 2024
1 parent 4d8fc7d commit ea3f199
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
17 changes: 17 additions & 0 deletions client/src/__tests__/utils/UserRole.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,23 @@ test("Allowed to renew UserRole", () => {

})

test("Allowed to renew guestIncluded UserRole as Inviter", () => {
const calendar = {
authority: AUTHORITIES.INVITER,
role: {id: "1", applicationUsages: applicationUsagesForManageId("1")}
};
const user = {userRoles: [calendar]}
expect(allowedToRenewUserRole(user, {
authority: AUTHORITIES.MANAGER,
role: {id: "1", applicationUsages: applicationUsagesForManageId("1")}
})).toBeFalsy();

expect(allowedToRenewUserRole(user, {
authority: AUTHORITIES.MANAGER,
role: {id: "1", applicationUsages: applicationUsagesForManageId("1")}
}, true, true)).toBeTruthy();
})

test("Allowed to delete Invitation", () => {
const mail = {authority: AUTHORITIES.INVITER, role: {id: "1", applicationUsages: applicationUsagesForManageId("10")}};
const research = {authority: AUTHORITIES.INVITER, role: {id: "2", applicationUsages: applicationUsagesForManageId("11")}};
Expand Down
2 changes: 1 addition & 1 deletion client/src/tabs/UserRoles.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const UserRoles = ({role, guests, userRoles}) => {
acc[userRole.id] = {
selected: false,
ref: userRole,
allowed: allowedToRenewUserRole(user, userRole, true)
allowed: allowedToRenewUserRole(user, userRole, true, guests)
};
return acc;
}, {}));
Expand Down
5 changes: 3 additions & 2 deletions client/src/utils/UserRole.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export const allowedToDeleteInvitation = (user, invitation) => {
}))
}

export const allowedToRenewUserRole = (user, userRole, deleteAction = false) => {
export const allowedToRenewUserRole = (user, userRole, deleteAction = false, targetGuestRole = false) => {
if (user.superUser) {
return true;
}
Expand All @@ -100,7 +100,8 @@ export const allowedToRenewUserRole = (user, userRole, deleteAction = false) =>
const allowedByApplicationForInstitutionAdmin = user.institutionAdmin && (user.applications || [])
.some(application => roleIsConnectedToApp(userRole.role, application));
const allowedByApplicationForManager = isApplicationManagerForUserRole(user, userRole);
switch (userRole.authority) {
const usedAuthority = targetGuestRole ? AUTHORITIES.GUEST : userRole.authority
switch (usedAuthority) {
case AUTHORITIES.SUPER_USER:
return false;
case AUTHORITIES.INSTITUTION_ADMIN:
Expand Down

0 comments on commit ea3f199

Please sign in to comment.