From aab2c972ec31be990d2dbe8fa48a37bc457719f8 Mon Sep 17 00:00:00 2001 From: luisarevalo21 Date: Mon, 13 Nov 2023 20:08:49 -0800 Subject: [PATCH] added unassignUserInProject, assignUserInProject permission to creteInitalPermissions to the admin account --- src/utilities/createInitialPermissions.js | 53 +++++++++++++---------- 1 file changed, 31 insertions(+), 22 deletions(-) diff --git a/src/utilities/createInitialPermissions.js b/src/utilities/createInitialPermissions.js index 9cdf7f9e0..e05aa34d3 100644 --- a/src/utilities/createInitialPermissions.js +++ b/src/utilities/createInitialPermissions.js @@ -69,14 +69,13 @@ const permissionsRoles = [ // 'getReportsPage',? 'getTimeZoneAPIKey', 'checkLeadTeamOfXplus', + 'unassignUserInProject', + 'assignUserInProject', ], }, { roleName: 'Volunteer', - permissions: [ - 'getReporteesLimitRoles', - 'suggestTask', - ], + permissions: ['getReporteesLimitRoles', 'suggestTask'], }, { roleName: 'Core Team', @@ -219,7 +218,6 @@ const permissionsRoles = [ }, ]; - const createInitialPermissions = async () => { // Create Initial Owner const userEmail = { email: 'jae@onecommunityglobal.org' }; @@ -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) { @@ -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);