Skip to content

Commit

Permalink
Merge pull request #526 from OneCommunityGlobal/fix-overwriting-new-p…
Browse files Browse the repository at this point in the history
…ermissions-in-PMP

Nathan - New perms and no removing PMP perms on startup
  • Loading branch information
one-community authored Oct 16, 2023
2 parents aa329ed + e40e91c commit 728b83d
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions src/utilities/createInitialPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,10 @@ const permissionsRoles = [
},
{
roleName: 'Volunteer',
permissions: ['getReporteesLimitRoles'],
permissions: [
'getReporteesLimitRoles',
'suggestTask',
],
},
{
roleName: 'Core Team',
Expand Down Expand Up @@ -106,7 +109,8 @@ const permissionsRoles = [
'putUserProfile',
'infringementAuthorizer',
'getReporteesLimitRoles',
'suggestTask',
'updateTask',
'putTeam',
'getAllInvInProjectWBS',
'postInvInProjectWBS',
'getAllInvInProject',
Expand Down Expand Up @@ -242,12 +246,16 @@ const createInitialPermissions = async () => {
role.permissions = permissions;
role.save();

// If role exists in db and is not updated, update it
} else if (!roleDataBase.permissions.every(perm => permissions.includes(perm)) || !permissions.every(perm => roleDataBase.permissions.includes(perm))) {
// If role exists in db and does not have every permission, add the missing permissions
} else if (!permissions.every(perm => roleDataBase.permissions.includes(perm))) {
const roleId = roleDataBase._id;

promises.push(Role.findById(roleId, (_, record) => {
record.permissions = permissions;
permissions.forEach((perm) => {
if (!record.permissions.includes(perm)) {
record.permissions.push(perm);
}
});
record.save();
}));
}
Expand Down

0 comments on commit 728b83d

Please sign in to comment.