Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

luis fix admins permissions added unassignUserInProject, assignUserInProject permission to creteI… #610

Open
wants to merge 1 commit into
base: development
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading