Skip to content

Commit f16bf7a

Browse files
authored
fix: give admins full permissions when they create their account (#679)
1 parent 79697fe commit f16bf7a

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

middlewares/auth.middleware.js

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -426,13 +426,15 @@ async function validateConfirmationToken(req, res, next) {
426426
}
427427

428428
/**
429-
*
429+
* Finds the confirmation token for this account. If there is no account ID associated with this
430+
* confirmation token, then the user was invited. Therefore, we should set the confirmation bit to
431+
* true by default (since they were invited).
430432
* @param {body: {decodedToken:{accountConfirmationId: String}}} req
431433
* @param {*} res
432434
* @param {*} next
433435
*/
434436
async function validateConfirmationTokenWithoutAccount(req, res, next) {
435-
if (!!req.body.decodedToken) {
437+
if (req.body.decodedToken) {
436438
const confirmationObj = await Services.AccountConfirmation.findById(
437439
req.body.decodedToken.accountConfirmationId
438440
);
@@ -468,17 +470,26 @@ function deleteResetToken(req, res, next) {
468470
* @param {(err?)=>void} next
469471
*/
470472
async function addCreationRoleBindings(req, res, next) {
471-
// Get the default role for the account type given
472-
const roleName = Constants.General.POST_ROLES[req.body.account.accountType];
473-
await Services.RoleBinding.createRoleBindingByRoleName(
474-
req.body.account.id,
475-
roleName
476-
);
477-
// Add default account role bindings
478-
await Services.RoleBinding.createRoleBindingByRoleName(
479-
req.body.account.id,
480-
Constants.Role.accountRole.name
481-
);
473+
if (req.body.account.accountType === Constants.General.STAFF) {
474+
// Staff do not have to create a STAFF object, so give them the full permissions immediately.
475+
await Services.RoleBinding.createRoleBindingByRoleName(
476+
req.body.account.id,
477+
Constants.Role.adminRole.name
478+
);
479+
} else {
480+
// Get the default role for the account type given
481+
const roleName =
482+
Constants.General.POST_ROLES[req.body.account.accountType];
483+
await Services.RoleBinding.createRoleBindingByRoleName(
484+
req.body.account.id,
485+
roleName
486+
);
487+
// Add default account role bindings
488+
await Services.RoleBinding.createRoleBindingByRoleName(
489+
req.body.account.id,
490+
Constants.Role.accountRole.name
491+
);
492+
}
482493
return next();
483494
}
484495

0 commit comments

Comments
 (0)