Skip to content

Commit 09f6d97

Browse files
committed
fixing a bug with adding new roles
1 parent 94bb621 commit 09f6d97

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/controller/org.controller/org.controller.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -488,8 +488,7 @@ async function createUser (req, res, next) {
488488

489489
if (!await userRepo.isAdminOrSecretariat(orgShortName, req.ctx.user, req.ctx.org, { session }, !req.useRegistry)) {
490490
await session.abortTransaction()
491-
return res.status(123).json(error.notOrgAdminOrSecretariat())
492-
// return res.status(403).json(error.notOrgAdminOrSecretariat()) // The Admin user must belong to the new user's organization
491+
return res.status(403).json(error.notOrgAdminOrSecretariat()) // The Admin user must belong to the new user's organization
493492
}
494493

495494
const users = await userRepo.findUsersByOrgShortname(orgShortName, { session })
@@ -638,8 +637,7 @@ async function updateUser (req, res, next) {
638637
if (!isRequesterSecretariat && !isAdmin) {
639638
logger.info({ uuid: req.ctx.uuid, message: `User ${requesterUsername} (not Admin/Secretariat) trying to modify admin-only fields.` })
640639
await session.abortTransaction()
641-
return res.status(321).json(error.notOrgAdminOrSecretariatUpdate())
642-
// return res.status(403).json(error.notOrgAdminOrSecretariatUpdate())
640+
return res.status(403).json(error.notOrgAdminOrSecretariatUpdate())
643641
}
644642
}
645643

src/middleware/middleware.js

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,7 @@ async function onlySecretariatOrAdmin (req, res, next) {
236236
const isAdmin = await userRepo.isAdmin(username, org)
237237
if (!isSec && !isAdmin) {
238238
logger.info({ uuid: req.ctx.uuid, message: 'Request denied because \'' + org + '\' is NOT a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' and \'' + username + '\' is not an ' + CONSTANTS.USER_ROLE_ENUM.ADMIN + ' user.' })
239-
return res.status(987).json(error.notOrgAdminOrSecretariat())
240-
// return res.status(403).json(error.notOrgAdminOrSecretariat())
239+
return res.status(403).json(error.notOrgAdminOrSecretariat())
241240
}
242241

243242
logger.info({ uuid: req.ctx.uuid, message: 'Confirmed ' + org + ' as a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' or an ' + CONSTANTS.USER_ROLE_ENUM.ADMIN + ' user.' })
@@ -310,15 +309,13 @@ async function onlyOrgWithPartnerRole (req, res, next) {
310309
return res.status(404).json(error.orgDoesNotExist(shortName))
311310
} else if ((org.authority.length === 1 && org.authority[0] === 'BULK_DOWNLOAD') || (org.authority?.active_roles?.length === 1 && org.authority.active_roles[0] === 'BULK_DOWNLOAD')) {
312311
logger.info({ uuid: req.ctx.uuid, message: org.short_name + 'only has BULK_DOWNLOAD role ' })
313-
return res.status(789).json(error.orgHasNoPartnerRole(shortName))
314-
// return res.status(403).json(error.orgHasNoPartnerRole(shortName))
312+
return res.status(403).json(error.orgHasNoPartnerRole(shortName))
315313
} else if (org.authority.length > 0 || org.authority?.active_roles.length > 0) {
316314
logger.info({ uuid: req.ctx.uuid, message: org.short_name + ' has a role ' })
317315
next()
318316
} else {
319317
logger.info({ uuid: req.ctx.uuid, message: org.short_name + ' does NOT have a role ' })
320-
return res.status(999).json(error.orgHasNoPartnerRole(shortName))
321-
// return res.status(403).json(error.orgHasNoPartnerRole(shortName))
318+
return res.status(403).json(error.orgHasNoPartnerRole(shortName))
322319
}
323320
} catch (err) {
324321
next(err)

src/repositories/baseUserRepository.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,13 @@ class BaseUserRepository extends BaseRepository {
263263
const filteredUuids = registryOrg.admins.filter(uuid => uuid !== registryUser.UUID)
264264
registryOrg.admins = filteredUuids
265265
}
266+
267+
if (rolesToAdd.includes('ADMIN') && !incomingParameters?.org_short_name) {
268+
const orgUpdates = await baseOrgRepository.getOrgObject(orgShortname)
269+
orgUpdates.admins = [..._.get(orgUpdates, 'admins', []), registryUser.UUID]
270+
await orgUpdates.save({ options })
271+
}
272+
266273
const initialRoles = legacyUser.authority?.active_roles ?? []
267274
const finalRoles = [...new Set([...initialRoles, ...rolesToAdd])].filter(role => !rolesToRemove.includes(role))
268275
registryUser.role = finalRoles[0] ?? ''

0 commit comments

Comments
 (0)