Skip to content

Commit

Permalink
Merge pull request #69 from bcgov/bugfix/last-manage
Browse files Browse the repository at this point in the history
Prevent removal of last manager when unticking READ
  • Loading branch information
TimCsaky authored Apr 12, 2023
2 parents b457f2c + c551b61 commit e5b74c1
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions frontend/src/components/object/ObjectPermission.vue
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,21 @@ const updateObjectPermission = (value: boolean, userId: string, permCode: string
else {
const managers = getMappedObjectToUserPermissions.value.filter( (x: UserPermissions) => x.manage );
const userPerms: UserPermissions = getMappedObjectToUserPermissions.value
.find( (x: UserPermissions) => x.userId === userId ) as UserPermissions;
// When READ is unticked check if they are the last remaining user with MANAGE
const lastManager = () => permCode === Permissions.READ && managers.length === 1 && userPerms.manage;
// Due to 2-way binding we check if there are no managers left when MANAGE is unticked
const noManagers = () => permCode === Permissions.MANAGE && !managers.length;
// Disallow removable of final MANAGE permission
if( permCode === Permissions.MANAGE && !managers.length ) {
if( lastManager() || noManagers() ) {
removeManageAlert.show();
// Set the value back as clicking will automatically change it
const perm: UserPermissions = getMappedObjectToUserPermissions.value
.find( (x: UserPermissions) => x.userId === userId ) as UserPermissions;
perm.manage = true;
if( permCode === Permissions.READ ) userPerms.read = true;
if( permCode === Permissions.MANAGE ) userPerms.manage = true;
}
else {
permissionStore.deleteObjectPermission(props.objectId, userId, permCode);
Expand Down

0 comments on commit e5b74c1

Please sign in to comment.