-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added unassignUserInProject, assignUserInProject permission to creteI…
…nitalPermissions to the admin account
- Loading branch information
1 parent
e9f78f3
commit aab2c97
Showing
1 changed file
with
31 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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: '[email protected]' }; | ||
|
@@ -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); | ||
|