Skip to content

Commit

Permalink
added unassignUserInProject, assignUserInProject permission to creteI…
Browse files Browse the repository at this point in the history
…nitalPermissions to the admin account
  • Loading branch information
luisarevalo21 committed Nov 14, 2023
1 parent e9f78f3 commit aab2c97
Showing 1 changed file with 31 additions and 22 deletions.
53 changes: 31 additions & 22 deletions src/utilities/createInitialPermissions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,13 @@ const permissionsRoles = [
// 'getReportsPage',?
'getTimeZoneAPIKey',
'checkLeadTeamOfXplus',
'unassignUserInProject',
'assignUserInProject',
],
},
{
roleName: 'Volunteer',
permissions: [
'getReporteesLimitRoles',
'suggestTask',
],
permissions: ['getReporteesLimitRoles', 'suggestTask'],
},
{
roleName: 'Core Team',
Expand Down Expand Up @@ -219,7 +218,6 @@ const permissionsRoles = [
},
];


const createInitialPermissions = async () => {
// Create Initial Owner
const userEmail = { email: '[email protected]' };
Expand All @@ -246,23 +244,29 @@ const createInitialPermissions = async () => {
role.permissions = permissions;
role.save();

// If role exists in db and does not have every permission, add the missing permissions
} else if (!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) => {
permissions.forEach((perm) => {
if (!record.permissions.includes(perm)) {
record.permissions.push(perm);
}
});
record.save();
}));
promises.push(
Role.findById(roleId, (_, record) => {
permissions.forEach((perm) => {
if (!record.permissions.includes(perm)) {
record.permissions.push(perm);
}
});
record.save();
}),
);
}
}

// Update Default presets
const presetDataBase = allPresets.find(preset => preset.roleName === roleName && preset.presetName === 'default');
const presetDataBase = allPresets.find(
preset => preset.roleName === roleName && preset.presetName === 'default',
);

// If role does not exist in db, create it
if (!presetDataBase) {
Expand All @@ -272,14 +276,19 @@ const createInitialPermissions = async () => {
defaultPreset.permissions = permissions;
defaultPreset.save();

// If role exists in db and is not updated, update default
} else if (!presetDataBase.permissions.every(perm => permissions.includes(perm)) || !permissions.every(perm => presetDataBase.permissions.includes(perm))) {
// If role exists in db and is not updated, update default
} else if (
!presetDataBase.permissions.every(perm => permissions.includes(perm))
|| !permissions.every(perm => presetDataBase.permissions.includes(perm))
) {
const presetId = presetDataBase._id;

promises.push(RolePreset.findById(presetId, (_, record) => {
record.permissions = permissions;
record.save();
}));
promises.push(
RolePreset.findById(presetId, (_, record) => {
record.permissions = permissions;
record.save();
}),
);
}
}
await Promise.all(promises);
Expand Down

0 comments on commit aab2c97

Please sign in to comment.