diff --git a/src/controller/format.constants.js b/src/controller/format.constants.js new file mode 100644 index 000000000..37a215e0a --- /dev/null +++ b/src/controller/format.constants.js @@ -0,0 +1,7 @@ +const LEGACY_FORMAT = true +const REGISTRY_FORMAT = false + +module.exports = { + LEGACY_FORMAT, + REGISTRY_FORMAT +} diff --git a/src/controller/org.controller/org.controller.js b/src/controller/org.controller/org.controller.js index 8fccc6b3b..19fcd0bac 100644 --- a/src/controller/org.controller/org.controller.js +++ b/src/controller/org.controller/org.controller.js @@ -7,11 +7,11 @@ const error = new errors.OrgControllerError() const validateUUID = require('uuid').validate const _ = require('lodash') const authContext = require('../../utils/authContext') +const { LEGACY_FORMAT, REGISTRY_FORMAT } = require('../format.constants') -const LEGACY_ORG_FORMAT = true -const REGISTRY_ORG_FORMAT = false -const LEGACY_USER_OBJECT = false -const REGISTRY_USER_OBJECT = true +function getObjectFormatForRequest (req) { + return req.useRegistry ? REGISTRY_FORMAT : LEGACY_FORMAT +} /** * Get the details of all orgs. @@ -37,7 +37,7 @@ async function getOrgs (req, res, next) { options.sort = { short_name: 'asc' } options.page = req.ctx.query.page ? parseInt(req.ctx.query.page) : CONSTANTS.PAGINATOR_PAGE // if 'page' query parameter is not defined, set 'page' to the default page value - const returnValue = await repo.getAllOrgs({ ...options }, LEGACY_ORG_FORMAT) + const returnValue = await repo.getAllOrgs({ ...options }, LEGACY_FORMAT) logger.info({ uuid: req.ctx.uuid, message: 'The orgs were sent to the user.' }) return res.status(200).json(returnValue) @@ -66,17 +66,17 @@ async function getOrg (req, res, next) { let returnValue try { - const requesterOrg = await authContext.getRequesterOrg(req, repo, {}, LEGACY_ORG_FORMAT) + const requesterOrg = await authContext.getRequesterOrg(req, repo, {}, LEGACY_FORMAT) // Ensure requester org exists if (!requesterOrg) { return res.status(404).json(error.orgDne(requesterOrgShortName, 'requesterOrgShortName', 'header')) } - const isSecretariat = await authContext.isRequesterSecretariat(req, repo, {}, LEGACY_ORG_FORMAT) + const isSecretariat = await authContext.isRequesterSecretariat(req, repo, {}, LEGACY_FORMAT) const isRequesterSameOrg = identifierIsUUID ? requesterOrg.UUID === identifier - : await authContext.isRequesterSameOrg(req, repo, identifier, {}, LEGACY_ORG_FORMAT) + : await authContext.isRequesterSameOrg(req, repo, identifier, {}, LEGACY_FORMAT) // Ensure that if the requester is not Secretariat, they can't view orgs other than their own if (!isRequesterSameOrg && !isSecretariat) { @@ -84,7 +84,7 @@ async function getOrg (req, res, next) { return res.status(403).json(error.notSameOrgOrSecretariat()) } - returnValue = await repo.getOrg(identifier, identifierIsUUID, {}, LEGACY_ORG_FORMAT) + returnValue = await repo.getOrg(identifier, identifierIsUUID, {}, LEGACY_FORMAT) } catch (err) { // Handle the specific error thrown by BaseOrgRepository.getOrg if (err.message && err.message.includes('Unknown Org type requested')) { @@ -143,13 +143,13 @@ async function getUsers (req, res, next) { return res.status(404).json(error.orgDnePathParam(orgShortName)) } - const isSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, { UUID: orgUUID, short_name: orgShortName }, {}, LEGACY_ORG_FORMAT) + const isSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, { UUID: orgUUID, short_name: orgShortName }, {}, LEGACY_FORMAT) if (!isSameOrg && !isSecretariat) { logger.info({ uuid: req.ctx.uuid, message: orgShortName + ' organization can only be viewed by the users of the same organization or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) } - const payload = await userRepo.getAllUsersByOrgShortname(orgShortName, options, LEGACY_USER_OBJECT) + const payload = await userRepo.getAllUsersByOrgShortname(orgShortName, options, LEGACY_FORMAT) logger.info({ uuid: req.ctx.uuid, message: `The users of ${orgShortName} organization were sent to the user.` }) return res.status(200).json(payload) @@ -173,10 +173,10 @@ async function getUser (req, res, next) { const orgShortName = req.ctx.params.shortname const orgRepo = req.ctx.repositories.getBaseOrgRepository() - const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, LEGACY_ORG_FORMAT) + const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, LEGACY_FORMAT) const orgUUID = await orgRepo.getOrgUUID(orgShortName) - const isSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, { UUID: orgUUID, short_name: orgShortName }, {}, LEGACY_ORG_FORMAT) + const isSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, { UUID: orgUUID, short_name: orgShortName }, {}, LEGACY_FORMAT) if (!isSameOrg && !isSecretariat) { logger.info({ uuid: req.ctx.uuid, message: req.ctx.org + ' organization can only be viewed by that organization\'s users or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) @@ -189,7 +189,7 @@ async function getUser (req, res, next) { const userRepo = req.ctx.repositories.getBaseUserRepository() // This is simple, we can just call our function - const result = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName, {}, LEGACY_USER_OBJECT) + const result = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName, {}, LEGACY_FORMAT) if (!result) { logger.info({ uuid: req.ctx.uuid, message: username + ' does not exist.' }) @@ -222,24 +222,22 @@ async function getOrgIdQuota (req, res, next) { try { const orgRepo = req.ctx.repositories.getBaseOrgRepository() const shortName = req.ctx.params.shortname - const isRegistry = req.useRegistry === true - const returnLegacyFormat = isRegistry ? REGISTRY_ORG_FORMAT : LEGACY_ORG_FORMAT - - const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, returnLegacyFormat) - const isSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, shortName, {}, returnLegacyFormat) + const objectFormat = getObjectFormatForRequest(req) + const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, objectFormat) + const isSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, shortName, {}, objectFormat) if (!isSameOrg && !isSecretariat) { logger.info({ uuid: req.ctx.uuid, message: shortName + ' organization id quota can only be viewed by the users of the same organization or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) } - const org = await orgRepo.getOrg(shortName, false, {}, returnLegacyFormat) + const org = await orgRepo.getOrg(shortName, false, {}, objectFormat) if (!org) { // a null org can only happen if the requestor is the Secretariat logger.info({ uuid: req.ctx.uuid, message: shortName + ' organization does not exist.' }) return res.status(404).json(error.orgDnePathParam(shortName)) } - const returnPayload = await orgRepo.getOrgIdQuota(org, returnLegacyFormat) + const returnPayload = await orgRepo.getOrgIdQuota(org, objectFormat) logger.info({ uuid: req.ctx.uuid, message: 'The organization\'s id quota was returned to the user.', details: returnPayload }) return res.status(200).json(returnPayload) } catch (err) { @@ -271,7 +269,7 @@ async function createOrg (req, res, next) { session.startTransaction({ readPreference: 'primary' }) // Check to see if the org already exits - if (await repo.orgExists(body?.short_name, { session }, LEGACY_ORG_FORMAT)) { + if (await repo.orgExists(body?.short_name, { session }, LEGACY_FORMAT)) { logger.info({ uuid: req.ctx.uuid, message: body?.short_name + ' organization was not created because it already exists.' }) await session.abortTransaction() return res.status(400).json(error.orgExists(body?.short_name)) @@ -288,9 +286,9 @@ async function createOrg (req, res, next) { return res.status(400).json(error.aliasCollision(collisionString)) } const userRepo = req.ctx.repositories.getBaseUserRepository() - const isSecretariat = await authContext.isRequesterSecretariat(req, repo, { session }, LEGACY_ORG_FORMAT) - const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, repo, { session }, LEGACY_USER_OBJECT) - returnValue = await repo.createOrg(req.ctx.body, { session, upsert: true }, LEGACY_ORG_FORMAT, requestingUserUUID, isSecretariat) + const isSecretariat = await authContext.isRequesterSecretariat(req, repo, { session }, LEGACY_FORMAT) + const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, repo, { session }, LEGACY_FORMAT) + returnValue = await repo.createOrg(req.ctx.body, { session, upsert: true }, LEGACY_FORMAT, requestingUserUUID, isSecretariat) await session.commitTransaction() } catch (error) { @@ -368,9 +366,9 @@ async function updateOrg (req, res, next) { } const userRepo = req.ctx.repositories.getBaseUserRepository() - const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepository, { session }, LEGACY_USER_OBJECT) - const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepository, { session }, LEGACY_ORG_FORMAT) - const isAdmin = await authContext.isRequesterAdmin(req, userRepo, orgRepository, { session }, LEGACY_USER_OBJECT) + const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepository, { session }, LEGACY_FORMAT) + const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepository, { session }, LEGACY_FORMAT) + const isAdmin = await authContext.isRequesterAdmin(req, userRepo, orgRepository, { session }, LEGACY_FORMAT) if (!isSecretariat) { const secretariatOnlyFields = getConstants().SECRETARIAT_ONLY_FIELDS @@ -381,7 +379,7 @@ async function updateOrg (req, res, next) { return res.status(403).json(error.secretariatOnlyEditing(restrictedFieldsSent)) } } - const updatedOrg = await orgRepository.updateOrg(shortNameUrlParameter, queryParametersJson, { session }, LEGACY_ORG_FORMAT, requestingUserUUID, isAdmin, isSecretariat) + const updatedOrg = await orgRepository.updateOrg(shortNameUrlParameter, queryParametersJson, { session }, LEGACY_FORMAT, requestingUserUUID, isAdmin, isSecretariat) responseMessage = { message: `${updatedOrg.short_name} organization was successfully updated.`, updated: updatedOrg } // Clarify message payload = { @@ -450,7 +448,7 @@ async function createUser (req, res, next) { } // Ask repo if user already exists - if (await userRepo.orgHasUser(orgShortName, body?.username, { session }, LEGACY_USER_OBJECT)) { + if (await userRepo.orgHasUser(orgShortName, body?.username, { session }, LEGACY_FORMAT)) { logger.info({ uuid: req.ctx.uuid, message: `${body?.username} user was not created because it already exists.` }) await session.abortTransaction() return res.status(400).json(error.userExists(body?.username)) @@ -458,10 +456,10 @@ async function createUser (req, res, next) { let isRequesterAdminOrSecretariat if (!req.ctx.authenticated && !req.ctx.orgUUID && typeof userRepo.isAdminOrSecretariat === 'function') { - isRequesterAdminOrSecretariat = await userRepo.isAdminOrSecretariat(orgShortName, req.ctx.user, req.ctx.org, { session }, LEGACY_USER_OBJECT) + isRequesterAdminOrSecretariat = await userRepo.isAdminOrSecretariat(orgShortName, req.ctx.user, req.ctx.org, { session }, LEGACY_FORMAT) } else { - const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, LEGACY_ORG_FORMAT) - const isRequesterAdminOfTargetOrg = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, orgShortName, { session }, LEGACY_USER_OBJECT) + const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, LEGACY_FORMAT) + const isRequesterAdminOfTargetOrg = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, orgShortName, { session }, LEGACY_FORMAT) isRequesterAdminOrSecretariat = isRequesterSecretariat || isRequesterAdminOfTargetOrg } @@ -476,8 +474,8 @@ async function createUser (req, res, next) { return res.status(400).json(error.userLimitReached()) } - const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, LEGACY_USER_OBJECT) - returnValue = await userRepo.createUser(orgShortName, body, { session, upsert: true }, LEGACY_USER_OBJECT, requestingUserUUID) + const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, LEGACY_FORMAT) + returnValue = await userRepo.createUser(orgShortName, body, { session, upsert: true }, LEGACY_FORMAT, requestingUserUUID) await session.commitTransaction() } catch (error) { await session.abortTransaction() @@ -533,11 +531,11 @@ async function updateUser (req, res, next) { const queryParametersJson = req.ctx.query // Get requester UUID for later - const requesterUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, LEGACY_USER_OBJECT) - const targetUserUUID = await userRepo.getUserUUID(usernameParams, shortNameParams, { session }, LEGACY_USER_OBJECT) + const requesterUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, LEGACY_FORMAT) + const targetUserUUID = await userRepo.getUserUUID(usernameParams, shortNameParams, { session }, LEGACY_FORMAT) - const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, LEGACY_ORG_FORMAT) - const isAdmin = await authContext.isRequesterAdmin(req, userRepo, orgRepo, { session }, LEGACY_USER_OBJECT) + const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, LEGACY_FORMAT) + const isAdmin = await authContext.isRequesterAdmin(req, userRepo, orgRepo, { session }, LEGACY_FORMAT) const targetOrgUUID = await orgRepo.getOrgUUID(shortNameParams, { session }) if (!targetOrgUUID) { @@ -546,7 +544,7 @@ async function updateUser (req, res, next) { return res.status(404).json(error.orgDnePathParam(shortNameParams)) } - const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, { UUID: targetOrgUUID, short_name: shortNameParams }, { session }, LEGACY_ORG_FORMAT) + const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, { UUID: targetOrgUUID, short_name: shortNameParams }, { session }, LEGACY_FORMAT) if (!requesterSameOrg && !isRequesterSecretariat) { logger.info({ uuid: req.ctx.uuid, message: `${shortNameParams} organization data can only be modified by users of the same organization or the Secretariat.` }) await session.abortTransaction() @@ -646,7 +644,7 @@ async function updateUser (req, res, next) { } } - const payload = await userRepo.updateUser(usernameParams, shortNameParams, queryParametersJson, { session }, LEGACY_USER_OBJECT, requesterUUID) + const payload = await userRepo.updateUser(usernameParams, shortNameParams, queryParametersJson, { session }, LEGACY_FORMAT, requesterUUID) await session.commitTransaction() return res.status(200).json({ message: `${usernameParams} was successfully updated.`, updated: payload }) } catch (err) { @@ -682,15 +680,13 @@ async function resetSecret (req, res, next) { const orgRepo = req.ctx.repositories.getBaseOrgRepository() const userRepo = req.ctx.repositories.getBaseUserRepository() - const isRegistry = req.useRegistry === true - const returnLegacyFormat = isRegistry ? REGISTRY_ORG_FORMAT : LEGACY_ORG_FORMAT - const isRegistryUserObject = isRegistry ? REGISTRY_USER_OBJECT : LEGACY_USER_OBJECT + const objectFormat = getObjectFormatForRequest(req) try { session.startTransaction({ readPreference: 'primary' }) // Check if target org exists - const targetOrgUUID = await orgRepo.getOrgUUID(targetOrgShortName, { session }, returnLegacyFormat) + const targetOrgUUID = await orgRepo.getOrgUUID(targetOrgShortName, { session }, objectFormat) if (!targetOrgUUID) { logger.info({ uuid: req.ctx.uuid, message: 'Org DNE' }) await session.abortTransaction() @@ -698,11 +694,11 @@ async function resetSecret (req, res, next) { } const targetOrg = { UUID: targetOrgUUID, short_name: targetOrgShortName } - const requesterUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, isRegistryUserObject) - const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, returnLegacyFormat) + const requesterUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, objectFormat) + const isRequesterSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, { session }, objectFormat) if (!isRequesterSecretariat) { - const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg, { session }, returnLegacyFormat) + const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg, { session }, objectFormat) if (!requesterSameOrg) { logger.info({ uuid: req.ctx.uuid, message: 'The api secret can only be reset by the Secretariat, an Org admin or if the requester is the user.' }) await session.abortTransaction() @@ -711,7 +707,7 @@ async function resetSecret (req, res, next) { } // Check if target user exists in target org - const targetUserUUID = await userRepo.getUserUUID(targetUsername, targetOrgShortName, { session }, isRegistryUserObject) + const targetUserUUID = await userRepo.getUserUUID(targetUsername, targetOrgShortName, { session }, objectFormat) if (!targetUserUUID) { logger.info({ uuid: req.ctx.uuid, message: 'User DNE' }) await session.abortTransaction() @@ -723,7 +719,7 @@ async function resetSecret (req, res, next) { // 1. WE are not the same user if (requesterUserUUID !== targetUserUUID) { // Check to see if we are the admin of the target organization - const isAdminOfTargetOrg = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg, { session }, isRegistryUserObject) + const isAdminOfTargetOrg = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg, { session }, objectFormat) if (!isAdminOfTargetOrg) { logger.info({ uuid: req.ctx.uuid, message: 'The api secret can only be reset by the Secretariat, an Org admin or if the requester is the user.' }) @@ -733,7 +729,7 @@ async function resetSecret (req, res, next) { } } - const updatedSecret = await userRepo.resetSecret(targetUsername, targetOrgShortName, { session }, isRegistryUserObject) + const updatedSecret = await userRepo.resetSecret(targetUsername, targetOrgShortName, { session }, objectFormat) logger.info({ uuid: req.ctx.uuid, message: `The API secret was successfully reset and sent to ${targetUsername}` }) const payload = { diff --git a/src/controller/registry.controller/org.registry.controller.js b/src/controller/registry.controller/org.registry.controller.js index deb83fc3c..011be3aed 100644 --- a/src/controller/registry.controller/org.registry.controller.js +++ b/src/controller/registry.controller/org.registry.controller.js @@ -9,6 +9,7 @@ const conversationErrors = require('../conversation.controller/error') const convoError = new conversationErrors.ConversationControllerError() const validateUUID = require('uuid').validate const authContext = require('../../utils/authContext') +const { REGISTRY_FORMAT } = require('../format.constants') function addUUIDsToSet (uuidSet, values) { if (!Array.isArray(values)) return @@ -128,7 +129,7 @@ async function getAllOrgs (req, res, next) { options.page = req.ctx.query.page ? parseInt(req.ctx.query.page) : CONSTANTS.PAGINATOR_PAGE // if 'page' query parameter is not defined, set 'page' to the default page value try { - returnValue = await repo.getAllOrgs({ ...options }, false, isSecretariat) + returnValue = await repo.getAllOrgs({ ...options }, REGISTRY_FORMAT, isSecretariat) // fetch conversations for (let i = 0; i < returnValue.organizations.length; i++) { const conversation = await conversationRepo.getAllByTargetUUID(returnValue.organizations[i].UUID, isSecretariat) @@ -181,7 +182,7 @@ async function getOrg (req, res, next) { logger.info({ uuid: req.ctx.uuid, message: identifier + ' organization can only be viewed by the users of the same organization or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) } - returnValue = await repo.getOrg(identifier, identifierIsUUID, {}, false, isSecretariat) + returnValue = await repo.getOrg(identifier, identifierIsUUID, {}, REGISTRY_FORMAT, isSecretariat) if (returnValue) { let userRepo @@ -306,7 +307,7 @@ async function createOrg (req, res, next) { const userRepo = req.ctx.repositories.getBaseUserRepository() const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, repo, { session }) // Create the org – repo.createOrg will handle field mapping - createdOrg = await repo.createOrg(body, { session, upsert: true }, false, requestingUserUUID, isSecretariat) + createdOrg = await repo.createOrg(body, { session, upsert: true }, REGISTRY_FORMAT, requestingUserUUID, isSecretariat) await session.commitTransaction() } catch (createErr) { @@ -549,7 +550,7 @@ async function updateOrg (req, res, next) { // Update Org full will cause a write to the Conversations collection, to avoid a read-after-write issue, we need to get the previous conversation data first const previousConversation = await conversationRepo.getAllByTargetUUID(await repo.getOrgUUID(shortName, { session }), isSecretariat, { session }) || [] - updatedOrg = await repo.updateOrgFull(shortName, req.ctx.body, { session }, false, requestingUser.UUID, isAdmin, isSecretariat) + updatedOrg = await repo.updateOrgFull(shortName, req.ctx.body, { session }, REGISTRY_FORMAT, requestingUser.UUID, isAdmin, isSecretariat) jointApprovalRequired = _.get(updatedOrg, 'joint_approval_required', false) _.unset(updatedOrg, 'joint_approval_required') // append previous conversations to any conversations that are in the org already @@ -702,7 +703,7 @@ async function getUsers (req, res, next) { } // This should always return Registry typed - const payload = await userRepo.getAllUsersByOrgShortname(orgShortName, options, true) + const payload = await userRepo.getAllUsersByOrgShortname(orgShortName, options, REGISTRY_FORMAT) // Hydrate the role field const org = await orgRepo.findOneByShortName(orgShortName) @@ -738,7 +739,7 @@ async function createUserByOrg (req, res, next) { let returnValue // Check to make sure Org Exists first - const orgUUID = await orgRepo.getOrgUUID(orgShortName, {}, false) + const orgUUID = await orgRepo.getOrgUUID(orgShortName, {}, REGISTRY_FORMAT) if (!orgUUID) { logger.info({ uuid: req.ctx.uuid, message: 'The user could not be created because ' + orgShortName + ' organization does not exist.' }) return res.status(404).json(error.orgDnePathParam(orgShortName)) @@ -769,7 +770,7 @@ async function createUserByOrg (req, res, next) { } // Ask repo if user already exists - if (await userRepo.orgHasUser(orgShortName, body?.username, { session }, true)) { + if (await userRepo.orgHasUser(orgShortName, body?.username, { session }, REGISTRY_FORMAT)) { logger.info({ uuid: req.ctx.uuid, message: `${body?.username} user was not created because it already exists.` }) await session.abortTransaction() return res.status(400).json(error.userExists(body?.username)) @@ -789,7 +790,7 @@ async function createUserByOrg (req, res, next) { } const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }) - returnValue = await userRepo.createUser(orgShortName, body, { session, upsert: true }, true, requestingUserUUID) + returnValue = await userRepo.createUser(orgShortName, body, { session, upsert: true }, REGISTRY_FORMAT, requestingUserUUID) await session.commitTransaction() } catch (error) { await session.abortTransaction() @@ -849,7 +850,7 @@ async function editConversationForOrg (req, res, next) { const session = await mongoose.startSession({ causalConsistency: false }) try { - const orgUUID = await repo.getOrgUUID(orgShortName, {}, false) + const orgUUID = await repo.getOrgUUID(orgShortName, {}, REGISTRY_FORMAT) if (!orgUUID) { await session.endSession() return res.status(404).json(error.orgDnePathParam(orgShortName)) diff --git a/src/controller/registry.controller/user.registry.controller.js b/src/controller/registry.controller/user.registry.controller.js index 788e7c8c6..2ffddf442 100644 --- a/src/controller/registry.controller/user.registry.controller.js +++ b/src/controller/registry.controller/user.registry.controller.js @@ -7,6 +7,7 @@ const error = new errors.UserControllerError() const validateUUID = require('uuid').validate const _ = require('lodash') const authContext = require('../../utils/authContext') +const { REGISTRY_FORMAT } = require('../format.constants') const immutableUpdateFields = ['created', 'last_updated'] @@ -43,7 +44,7 @@ async function getAllUsers (req, res, next) { options.sort = { short_name: 'asc' } options.page = req.ctx.query.page ? parseInt(req.ctx.query.page) : CONSTANTS.PAGINATOR_PAGE // if 'page' query parameter is not defined, set 'page' to the default page value - const returnValue = await repo.getAllUsers(options) + const returnValue = await repo.getAllUsers(options, REGISTRY_FORMAT) // Hydrate roles const orgRepo = req.ctx.repositories.getBaseOrgRepository() const distinctOrgUUIDs = [...new Set(returnValue.users.map(u => u.org_UUID))] @@ -55,7 +56,7 @@ async function getAllUsers (req, res, next) { const orgMap = {} for (const uuid of distinctOrgUUIDs) { // We need the org content to get admins - const org = await orgRepo.findOneByUUID(uuid) + const org = await orgRepo.findOneByUUID(uuid, {}, REGISTRY_FORMAT) if (org) { orgMap[uuid] = org } @@ -110,14 +111,14 @@ async function getUser (req, res, next) { const userRepo = req.ctx.repositories.getBaseUserRepository() const repo = req.ctx.repositories.getBaseOrgRepository() - const isSecretariat = await authContext.isRequesterSecretariat(req, repo) + const isSecretariat = await authContext.isRequesterSecretariat(req, repo, {}, REGISTRY_FORMAT) try { let result let org if (identifier) { - result = await userRepo.findUserByUUID(identifier) + result = await userRepo.findUserByUUID(identifier, {}, REGISTRY_FORMAT) if (!result) { logger.info({ uuid: req.ctx.uuid, message: identifier + ' user could not be found.' }) return res.status(404).json(error.userDne(identifier)) @@ -129,22 +130,22 @@ async function getUser (req, res, next) { return res.status(404).json(error.userDne(identifier)) } - org = await repo.findOneByUUID(orgUUID) + org = await repo.findOneByUUID(orgUUID, {}, REGISTRY_FORMAT) userToGetParameters = { org: org.short_name, username: result.username } } else { - org = await repo.findOneByShortName(req.ctx.params.shortname) + org = await repo.findOneByShortName(req.ctx.params.shortname, {}, REGISTRY_FORMAT) - const isSameOrg = await authContext.isRequesterSameOrg(req, repo, org) + const isSameOrg = await authContext.isRequesterSameOrg(req, repo, org, {}, REGISTRY_FORMAT) if (!isSecretariat && !isSameOrg) { logger.info({ uuid: req.ctx.uuid, message: userToGetParameters.org + ' organization can only be viewed by the users of the same organization or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) } - result = await userRepo.findOneByUsernameAndOrgShortname(userToGetParameters.username, userToGetParameters.org) + result = await userRepo.findOneByUsernameAndOrgShortname(userToGetParameters.username, userToGetParameters.org, {}, REGISTRY_FORMAT) if (!result) { logger.info({ uuid: req.ctx.uuid, message: userToGetParameters.username + ' user could not be found.' }) return res.status(404).json(error.userDne(userToGetParameters.username)) @@ -157,7 +158,7 @@ async function getUser (req, res, next) { } if (identifier) { - const isSameOrg = await authContext.isRequesterSameOrg(req, repo, org) + const isSameOrg = await authContext.isRequesterSameOrg(req, repo, org, {}, REGISTRY_FORMAT) if (!isSecretariat && !isSameOrg) { logger.info({ uuid: req.ctx.uuid, message: identifier + ' organization can only be viewed by the users of the same organization or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) @@ -213,7 +214,7 @@ async function updateUser (req, res, next) { username: req.ctx.params.username } - const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo) + const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, REGISTRY_FORMAT) // TODO: This will need to be atomic at some point like revoke or grant // Specific check for org_short_name (Secretariat only) @@ -221,7 +222,7 @@ async function updateUser (req, res, next) { let userToEdit let org if (identifier) { - userToEdit = await userRepo.findUserByUUID(identifier) + userToEdit = await userRepo.findUserByUUID(identifier, {}, REGISTRY_FORMAT) if (!userToEdit) { logger.info({ uuid: req.ctx.uuid, message: identifier + ' user could not be found.' }) return res.status(404).json(error.userDne(identifier)) @@ -233,20 +234,20 @@ async function updateUser (req, res, next) { return res.status(404).json(error.orgDnePathParam(identifier)) } - org = await orgRepo.findOneByUUID(orgUUID) + org = await orgRepo.findOneByUUID(orgUUID, {}, REGISTRY_FORMAT) userToEditParameters.org = org.short_name userToEditParameters.username = userToEdit.username } else { - userToEdit = await userRepo.findOneByUsernameAndOrgShortname(userToEditParameters.username, userToEditParameters.org) - org = await orgRepo.findOneByShortName(userToEditParameters.org) + userToEdit = await userRepo.findOneByUsernameAndOrgShortname(userToEditParameters.username, userToEditParameters.org, {}, REGISTRY_FORMAT) + org = await orgRepo.findOneByShortName(userToEditParameters.org, {}, REGISTRY_FORMAT) if (!org) { logger.info({ uuid: req.ctx.uuid, message: `Target organization ${userToEditParameters.org} does not exist.` }) return res.status(404).json(error.orgDnePathParam(userToEditParameters.org)) } } - const isAdmin = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, org) - const requesterUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo) + const isAdmin = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, org, {}, REGISTRY_FORMAT) + const requesterUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, {}, REGISTRY_FORMAT) // Allow existing UUIDs to be passed, but block any attempts to mutate them if (userToEdit) { @@ -267,7 +268,7 @@ async function updateUser (req, res, next) { } if (body.org_short_name) { - const targetOrg = await orgRepo.findOneByShortName(body.org_short_name) + const targetOrg = await orgRepo.findOneByShortName(body.org_short_name, {}, REGISTRY_FORMAT) if (!targetOrg) { logger.info({ uuid: req.ctx.uuid, message: `Target organization ${body.org_short_name} does not exist.` }) return res.status(404).json(error.orgDnePathParam(body.org_short_name)) @@ -284,7 +285,7 @@ async function updateUser (req, res, next) { return res.status(404).json(error.orgDnePathParam(userToEditParameters.org)) } - const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, org) + const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, org, {}, REGISTRY_FORMAT) if (!isSecretariat && !isAdmin && !requesterSameOrg) { logger.info({ uuid: req.ctx.uuid, message: requestingUserParameters.org + ' user can only be updated by the user or admins of the same organization or the Secretariat.' }) return res.status(403).json(error.notSameOrgOrSecretariat()) @@ -341,7 +342,7 @@ async function updateUser (req, res, next) { // Ask repo if user already exists if (body?.username && body.username !== userToEdit.username) { - if (await userRepo.orgHasUser(userToEditParameters.org, body.username, { session })) { + if (await userRepo.orgHasUser(userToEditParameters.org, body.username, { session }, REGISTRY_FORMAT)) { logger.info({ uuid: req.ctx.uuid, message: 'The username ' + body.username + ' already exists.' }) await session.abortTransaction() return res.status(403).json(error.duplicateUsername()) @@ -352,7 +353,7 @@ async function updateUser (req, res, next) { const requestingUserUUID = requesterUserUUID updatedUserUUID = userToEdit.UUID - updatedUser = await userRepo.updateUserFull(userToEdit.UUID, body, { session }, true, requestingUserUUID) + updatedUser = await userRepo.updateUserFull(userToEdit.UUID, body, { session }, REGISTRY_FORMAT, requestingUserUUID) await session.commitTransaction() } catch (error) { await session.abortTransaction() @@ -397,14 +398,14 @@ async function deleteUser (req, res, next) { const orgRepo = req.ctx.repositories.getBaseOrgRepository() const orgShortName = req.ctx.params.shortname const username = req.ctx.params.username - const org = await orgRepo.findOneByShortName(orgShortName) + const org = await orgRepo.findOneByShortName(orgShortName, {}, REGISTRY_FORMAT) if (!org) { logger.info({ uuid: req.ctx.uuid, message: 'Org DNE' }) return res.status(404).json(error.orgDnePathParam(orgShortName)) } - const user = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName) + const user = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName, {}, REGISTRY_FORMAT) if (!user) { logger.info({ uuid: req.ctx.uuid, message: 'User DNE' }) @@ -412,7 +413,7 @@ async function deleteUser (req, res, next) { } const userUUID = user.UUID - const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo) + const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, {}, REGISTRY_FORMAT) await userRepo.deleteUserByUUID(userUUID, {}, requestingUserUUID) const payload = { @@ -459,21 +460,21 @@ async function grantRole (req, res, next) { return res.status(404).json(error.orgDnePathParam(orgShortName)) } - const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo) + const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, REGISTRY_FORMAT) const targetOrg = { UUID: targetOrgUUID, short_name: orgShortName } - const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg) + const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg, {}, REGISTRY_FORMAT) if (!requesterSameOrg && !isSecretariat) { return res.status(403).json(error.notSameOrgOrSecretariat()) } - const isAdmin = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg) + const isAdmin = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg, {}, REGISTRY_FORMAT) if (!isSecretariat && !isAdmin) { return res.status(403).json(error.notOrgAdminOrSecretariatUpdate()) } // Check if target user exists in target org - const targetUser = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName) + const targetUser = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName, {}, REGISTRY_FORMAT) if (!targetUser) { return res.status(404).json(error.userDne(username)) } @@ -482,7 +483,7 @@ async function grantRole (req, res, next) { try { session.startTransaction({ readPreference: 'primary' }) - const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }) + const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, REGISTRY_FORMAT) await orgRepo.addAdmin(orgShortName, targetUser.UUID, { session }, requestingUserUUID) await session.commitTransaction() } catch (error) { @@ -524,27 +525,27 @@ async function revokeRole (req, res, next) { return res.status(404).json(error.orgDnePathParam(orgShortName)) } - const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo) + const isSecretariat = await authContext.isRequesterSecretariat(req, orgRepo, {}, REGISTRY_FORMAT) const targetOrg = { UUID: targetOrgUUID, short_name: orgShortName } - const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg) + const requesterSameOrg = await authContext.isRequesterSameOrg(req, orgRepo, targetOrg, {}, REGISTRY_FORMAT) if (!requesterSameOrg && !isSecretariat) { return res.status(403).json(error.notSameOrgOrSecretariat()) } - const isAdmin = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg) + const isAdmin = await authContext.isRequesterAdminOfOrg(req, userRepo, orgRepo, targetOrg, {}, REGISTRY_FORMAT) if (!isSecretariat && !isAdmin) { return res.status(403).json(error.notOrgAdminOrSecretariatUpdate()) } // Check if target user exists in target org - const targetUser = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName) + const targetUser = await userRepo.findOneByUsernameAndOrgShortname(username, orgShortName, {}, REGISTRY_FORMAT) if (!targetUser) { return res.status(404).json(error.userDne(username)) } // Prevent Self-Demotion - const callingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo) + const callingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, {}, REGISTRY_FORMAT) if (callingUserUUID === targetUser.UUID) { return res.status(403).json({ error: 'NOT_ALLOWED_TO_SELF_DEMOTE', message: 'You cannot remove the ADMIN role from yourself.' }) } @@ -553,7 +554,7 @@ async function revokeRole (req, res, next) { try { session.startTransaction({ readPreference: 'primary' }) - const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }) + const requestingUserUUID = await authContext.getRequesterUserUUID(req, userRepo, orgRepo, { session }, REGISTRY_FORMAT) await orgRepo.removeAdmin(orgShortName, targetUser.UUID, { session }, requestingUserUUID) await session.commitTransaction() } catch (error) { diff --git a/src/controller/user.controller/user.controller.js b/src/controller/user.controller/user.controller.js index 0b9fc31d5..a5a8f1a4a 100644 --- a/src/controller/user.controller/user.controller.js +++ b/src/controller/user.controller/user.controller.js @@ -2,8 +2,7 @@ require('dotenv').config() const logger = require('../../middleware/logger') const getConstants = require('../../constants').getConstants - -const LEGACY_USER_OBJECT = false +const { LEGACY_FORMAT, REGISTRY_FORMAT } = require('../format.constants') /** * Get the details of all users @@ -24,7 +23,7 @@ async function getAllUsers (req, res, next) { options.sort = { username: 'asc' } options.page = req.ctx.query.page ? parseInt(req.ctx.query.page) : CONSTANTS.PAGINATOR_PAGE // if 'page' query parameter is not defined, set 'page' to the default page value - const returnValue = await repo.getAllUsers(options, LEGACY_USER_OBJECT) + const returnValue = await repo.getAllUsers(options, req.useRegistry ? REGISTRY_FORMAT : LEGACY_FORMAT) logger.info({ uuid: req.ctx.uuid, message: 'The user information was sent to the secretariat user.' }) return res.status(200).json(returnValue) diff --git a/src/repositories/baseOrgRepository.js b/src/repositories/baseOrgRepository.js index 5591e8e96..4c71d39f9 100644 --- a/src/repositories/baseOrgRepository.js +++ b/src/repositories/baseOrgRepository.js @@ -745,6 +745,7 @@ class BaseOrgRepository extends BaseRepository { options ) } catch (auditError) { + console.error('Audit entry creation failed:', auditError) } } @@ -970,6 +971,7 @@ class BaseOrgRepository extends BaseRepository { ) } } catch (auditError) { + console.error('Audit entry creation failed:', auditError) } } diff --git a/src/repositories/baseUserRepository.js b/src/repositories/baseUserRepository.js index 1875dd6c9..ae84f9764 100644 --- a/src/repositories/baseUserRepository.js +++ b/src/repositories/baseUserRepository.js @@ -83,10 +83,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} orgShortName - The short name of the organization. * @param {string} uuid - The UUID of the user. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - Unused parameter. + * @param {boolean} [isLegacyObject=false] - Unused parameter. * @returns {Promise} True if the organization has the user, false otherwise. */ - async orgHasUserByUUID (orgShortName, uuid, options = {}, isRegistryObject = true) { + async orgHasUserByUUID (orgShortName, uuid, options = {}, isLegacyObject = false) { const org = await BaseOrgModel.findOne({ short_name: orgShortName }, null, options) if (!org || !Array.isArray(org.users)) { return false @@ -103,10 +103,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} orgShortName - The short name of the organization. * @param {string} username - The username to check. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - Unused parameter. + * @param {boolean} [isLegacyObject=false] - Unused parameter. * @returns {Promise} True if the organization has the user, false otherwise. */ - async orgHasUser (orgShortName, username, options = {}, isRegistryObject = true) { + async orgHasUser (orgShortName, username, options = {}, isLegacyObject = false) { // 1. Find the org const org = await BaseOrgModel.findOne({ short_name: orgShortName }, null, options) if (!org || !Array.isArray(org.users)) { @@ -125,10 +125,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username to find. * @param {string} orgShortName - The short name of the organization. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, returns a legacy user object if found. + * @param {boolean} [isLegacyObject=false] - If true, returns a legacy user object if found. * @returns {Promise} The user object or null if not found. */ - async findOneByUsernameAndOrgShortname (username, orgShortName, options = {}, isRegistryObject = true) { + async findOneByUsernameAndOrgShortname (username, orgShortName, options = {}, isLegacyObject = false) { const legacyUserRepo = new UserRepository() const org = await BaseOrgModel.findOne({ short_name: orgShortName }, null, options) if (!org || !Array.isArray(org.users)) { @@ -137,7 +137,7 @@ class BaseUserRepository extends BaseRepository { const user = await BaseUser.findOne({ username: username, UUID: { $in: org.users } }, null, options) - if (!isRegistryObject && user) { + if (isLegacyObject && user) { return await legacyUserRepo.findOneByUUID(user.UUID) || null } return user || null @@ -150,10 +150,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username to find. * @param {string} orgUUID - The UUID of the organization. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, returns a legacy user object if found. + * @param {boolean} [isLegacyObject=false] - If true, returns a legacy user object if found. * @returns {Promise} The user object or null if not found. */ - async findOneByUserNameAndOrgUUID (username, orgUUID, options = {}, isRegistryObject = true) { + async findOneByUserNameAndOrgUUID (username, orgUUID, options = {}, isLegacyObject = false) { const legacyUserRepo = new UserRepository() const org = await BaseOrgModel.findOne({ UUID: orgUUID }, null, options) if (!org || !Array.isArray(org.users)) { @@ -162,7 +162,7 @@ class BaseUserRepository extends BaseRepository { const user = await BaseUser.findOne({ username: username, UUID: { $in: org.users } }, null, options) - if (!isRegistryObject && user) { + if (isLegacyObject && user) { return await legacyUserRepo.findOneByUUID(user.UUID) || null } return user || null @@ -175,11 +175,11 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username to find. * @param {string} orgUUID - The UUID of the organization. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, returns a legacy user object if found. + * @param {boolean} [isLegacyObject=false] - If true, returns a legacy user object if found. * @returns {Promise} The user object or null if not found. */ - async findUserByUsernameAndOrgUUID (username, orgUUID, options = {}, isRegistryObject = true) { - return this.findOneByUserNameAndOrgUUID(username, orgUUID, options, isRegistryObject) + async findUserByUsernameAndOrgUUID (username, orgUUID, options = {}, isLegacyObject = false) { + return this.findOneByUserNameAndOrgUUID(username, orgUUID, options, isLegacyObject) } /** @@ -188,17 +188,17 @@ class BaseUserRepository extends BaseRepository { * @description Finds a user by UUID. * @param {string} uuid - The UUID to find. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, returns a legacy user object if found. + * @param {boolean} [isLegacyObject=false] - If true, returns a legacy user object if found. * @returns {Promise} The user object or null if not found. */ - async findUserByUUID (uuid, options = {}, isRegistryObject = true) { + async findUserByUUID (uuid, options = {}, isLegacyObject = false) { const legacyUserRepo = new UserRepository() const user = await BaseUser.findOne({ UUID: uuid }, null, options) if (!user) { return null } - if (!isRegistryObject) { + if (isLegacyObject) { return await legacyUserRepo.findOneByUUID(user.UUID) || null } return user || null @@ -223,10 +223,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} userUUID - The user UUID to check. * @param {string} orgUUID - The organization UUID to check. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, retrieves the legacy user object for role fallback. + * @param {boolean} [isLegacyObject=false] - If true, retrieves the legacy user object for role fallback. * @returns {Promise} True if the user is an admin of the org, false otherwise. */ - async isUserAdminOfOrgUUID (userUUID, orgUUID, options = {}, isRegistryObject = true) { + async isUserAdminOfOrgUUID (userUUID, orgUUID, options = {}, isLegacyObject = false) { if (!userUUID || !orgUUID) { return false } @@ -244,7 +244,7 @@ class BaseUserRepository extends BaseRepository { return false } - const user = await this.findUserByUUID(userUUID, options, isRegistryObject) + const user = await this.findUserByUUID(userUUID, options, isLegacyObject) return user?.role === 'ADMIN' || (Array.isArray(user?.authority?.active_roles) && user.authority.active_roles.includes('ADMIN')) } @@ -292,11 +292,11 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username. * @param {string} orgShortname - The short name of the organization. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, checks for legacy user format compatibility. + * @param {boolean} [isLegacyObject=false] - If true, checks for legacy user format compatibility. * @returns {Promise} The user UUID or null if not found. */ - async getUserUUID (username, orgShortname, options = {}, isRegistryObject = true) { - const user = await this.findOneByUsernameAndOrgShortname(username, orgShortname, options, isRegistryObject) + async getUserUUID (username, orgShortname, options = {}, isLegacyObject = false) { + const user = await this.findOneByUsernameAndOrgShortname(username, orgShortname, options, isLegacyObject) if (user) { return user.UUID } @@ -337,10 +337,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username to check. * @param {string} orgShortName - The short name of the organization. * @param {object} options - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - Unused parameter. + * @param {boolean} [isLegacyObject=false] - Unused parameter. * @returns {Promise} True if the user is an Admin, false otherwise. */ - async isAdmin (username, orgShortName, options, isRegistryObject = true) { + async isAdmin (username, orgShortName, options, isLegacyObject = false) { const baseOrgRepository = new BaseOrgRepository() const existingOrg = await baseOrgRepository.findOneByShortName(orgShortName) @@ -357,13 +357,13 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username to check. * @param {string} requesterOrg - The organization of the requester. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - Unused parameter. + * @param {boolean} [isLegacyObject=false] - Unused parameter. * @returns {Promise} True if the user is an Admin or Secretariat, false otherwise. */ - async isAdminOrSecretariat (orgShortName, username, requesterOrg, options = {}, isRegistryObject = true) { + async isAdminOrSecretariat (orgShortName, username, requesterOrg, options = {}, isLegacyObject = false) { const baseOrgRepository = new BaseOrgRepository() const org = await baseOrgRepository.findOneByShortName(requesterOrg) - if (await baseOrgRepository.isSecretariat(org) || await this.isAdmin(username, orgShortName, options, isRegistryObject)) { + if (await baseOrgRepository.isSecretariat(org) || await this.isAdmin(username, orgShortName, options, isLegacyObject)) { return true } return false @@ -374,14 +374,14 @@ class BaseUserRepository extends BaseRepository { * @function getAllUsers * @description Retrieves all users with pagination. * @param {object} [options={}] - Pagination and query options. - * @param {boolean} [isRegistryObject=true] - If true, returns registry formatted users. + * @param {boolean} [isLegacyObject=false] - If true, returns legacy formatted users. * @returns {Promise} Paginated result containing users and metadata. */ - async getAllUsers (options = {}, isRegistryObject = true) { + async getAllUsers (options = {}, isLegacyObject = false) { const UserRepository = require('./userRepository') const userRepo = new UserRepository() let pg - if (!isRegistryObject) { + if (isLegacyObject) { const agt = setAggregateUserObj({}) pg = await userRepo.aggregatePaginate(agt, options) } else { @@ -407,10 +407,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} orgShortName - The short name of the organization. * @param {object} incomingUser - The user object to create. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, accepts legacy user object. + * @param {boolean} [isLegacyObject=false] - If true, accepts legacy user object. * @returns {Promise} The created user object (registry or legacy format). */ - async createUser (orgShortName, incomingUser, options = {}, isRegistryObject = true, requestingUserUUID = null) { + async createUser (orgShortName, incomingUser, options = {}, isLegacyObject = false, requestingUserUUID = null) { const { deepRemoveEmpty } = require('../utils/utils') // TO-DO: org_UUID is not necessarily the shortname. Is this info lost during conversion? let legacyObjectRaw = null @@ -427,13 +427,13 @@ class BaseUserRepository extends BaseRepository { // Allow user to provide initial status, default to active let isConsideredInactive = false - if (isRegistryObject && incomingUser.status === 'inactive') isConsideredInactive = true - if (!isRegistryObject && (incomingUser.active === false || String(incomingUser.active).toLowerCase() === 'false')) isConsideredInactive = true + if (!isLegacyObject && incomingUser.status === 'inactive') isConsideredInactive = true + if (isLegacyObject && (incomingUser.active === false || String(incomingUser.active).toLowerCase() === 'false')) isConsideredInactive = true // Get UUID of org, that is having the user added to it. const existingOrg = await baseOrgRepository.findOneByShortName(orgShortName) - if (!isRegistryObject) { + if (isLegacyObject) { legacyObjectRaw = incomingUser legacyObjectRaw.secret = secret legacyObjectRaw.active = !isConsideredInactive @@ -455,7 +455,7 @@ class BaseUserRepository extends BaseRepository { registryObject = await registryUserToSave.save(options) const registryObjectPlain = toPlainObject(registryObject) - if (isRegistryObject) { + if (!isLegacyObject) { const legacyRole = userHasAdminRole(incomingUser) ? 'ADMIN' : incomingUser.role legacyObjectRaw = this.convertRegistryToLegacy({ ...registryObjectPlain, role: legacyRole }) legacyObjectRaw.secret = secret @@ -466,7 +466,7 @@ class BaseUserRepository extends BaseRepository { await baseOrgRepository.addUserToOrg(orgShortName, incomingUser.UUID, (userHasAdminRole(incomingUser) || userHasAdminRole(legacyObjectRaw)), options, false, requestingUserUUID) - if (!isRegistryObject) { + if (isLegacyObject) { legacyObjectRaw.secret = randomKey legacyObjectRaw.org_UUID = existingOrg.UUID delete legacyObjectRaw._id @@ -491,10 +491,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} orgShortname - The short name of the organization. * @param {object} incomingParameters - The parameters to update. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, returns a legacy user object. + * @param {boolean} [isLegacyObject=false] - If true, returns a legacy user object. * @returns {Promise} The updated user object. */ - async updateUser (username, orgShortname, incomingParameters, options = {}, isRegistryObject = true, requestingUserUUID = null) { + async updateUser (username, orgShortname, incomingParameters, options = {}, isLegacyObject = false, requestingUserUUID = null) { const { deepRemoveEmpty } = require('../utils/utils') const baseOrgRepository = new BaseOrgRepository() const legacyUserRepo = new UserRepository() @@ -503,7 +503,7 @@ class BaseUserRepository extends BaseRepository { const originalRegistryOrg = registryOrg.toObject() const legacyUser = await legacyUserRepo.findOneByUserNameAndOrgUUID(username, registryOrg.UUID, null, options) - const registryUser = await this.findOneByUsernameAndOrgShortname(username, orgShortname, options, true) + const registryUser = await this.findOneByUsernameAndOrgShortname(username, orgShortname, options, false) if (!registryUser && !legacyUser) { throw new Error('User not found') @@ -607,7 +607,7 @@ class BaseUserRepository extends BaseRepository { if (legacyUser) await legacyUser.save(options) if (registryUser) await registryUser.save(options) - if (!isRegistryObject) { + if (isLegacyObject) { if (!legacyUser) throw new Error('Legacy record missing; cannot return legacy format.') const plainJavascriptLegacyUser = legacyUser.toObject() plainJavascriptLegacyUser.role = finalRoles[0] ?? '' @@ -633,10 +633,10 @@ class BaseUserRepository extends BaseRepository { * @param {string} identifier - The identifier (UUID) of the user. * @param {object} incomingUser - The full user object with updates. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - If false, accepts/returns legacy format. + * @param {boolean} [isLegacyObject=false] - If true, accepts/returns legacy format. * @returns {Promise} The updated user object. */ - async updateUserFull (identifier, incomingUser, options = {}, isRegistryObject = true, requestingUserUUID = null) { + async updateUserFull (identifier, incomingUser, options = {}, isLegacyObject = false, requestingUserUUID = null) { const legacyUserRepo = new UserRepository() const registryUser = await this.findUserByUUID(identifier, options) @@ -648,8 +648,8 @@ class BaseUserRepository extends BaseRepository { } const { ...incomingUserBody } = incomingUser - const legacyObjectRaw = isRegistryObject ? this.convertRegistryToLegacy(incomingUserBody) : incomingUserBody - const registryObjectRaw = isRegistryObject ? incomingUserBody : this.convertLegacyToRegistry(incomingUserBody) + const legacyObjectRaw = isLegacyObject ? incomingUserBody : this.convertRegistryToLegacy(incomingUserBody) + const registryObjectRaw = isLegacyObject ? this.convertLegacyToRegistry(incomingUserBody) : incomingUserBody const protectedFieldsRegistry = ['_id', 'UUID', '__v', 'secret', 'created', 'last_updated'] const protectedFieldsLegacy = ['_id', 'UUID', '__v', 'secret', 'time', 'org_UUID'] @@ -667,7 +667,7 @@ class BaseUserRepository extends BaseRepository { if (legacyUser) { updatedLegacyUser = legacyUser.overwrite(_.mergeWith(_.pick(legacyUser.toObject(), protectedFieldsLegacy), _.omit(legacyObjectRaw, protectedFieldsLegacy), skipNulls)) // Align status from incoming payload or resolved registry state - const targetStatus = registryUser ? updatedRegistryUser.status : (isRegistryObject ? registryObjectRaw.status : 'active') + const targetStatus = registryUser ? updatedRegistryUser.status : (isLegacyObject ? 'active' : registryObjectRaw.status) updatedLegacyUser.active = (targetStatus === 'active') } @@ -728,7 +728,7 @@ class BaseUserRepository extends BaseRepository { throw new Error('Failed to update user: ' + error.message) } - if (!isRegistryObject) { + if (isLegacyObject) { if (!updatedLegacyUser) throw new Error('Legacy record missing; cannot output legacy format.') const plain = updatedLegacyUser.toObject() delete plain._id; delete plain.__v; delete plain.secret @@ -748,16 +748,16 @@ class BaseUserRepository extends BaseRepository { * @param {string} username - The username. * @param {string} orgShortName - The short name of the organization. * @param {object} [options={}] - Optional settings for the repository query. - * @param {boolean} [isRegistryObject=true] - Unused parameter. + * @param {boolean} [isLegacyObject=false] - Unused parameter. * @returns {Promise} The new random secret key. */ - async resetSecret (username, orgShortName, options = {}, isRegistryObject = true) { + async resetSecret (username, orgShortName, options = {}, isLegacyObject = false) { const legacyUserRepo = new UserRepository() const baseOrgRepository = new BaseOrgRepository() const legOrgUUID = await baseOrgRepository.getOrgUUID(orgShortName, options, true) const legUser = await legacyUserRepo.findOneByUserNameAndOrgUUID(username, legOrgUUID, null, options) - const regUser = await this.findOneByUsernameAndOrgShortname(username, orgShortName, options, true) + const regUser = await this.findOneByUsernameAndOrgShortname(username, orgShortName, options, false) // Fail ONLY if the user is completely missing from both collections if (!legUser && !regUser) { @@ -845,10 +845,10 @@ class BaseUserRepository extends BaseRepository { * * @param {string} orgShortname - The short name of the organization. * @param {object} options - Pagination options (e.g., limit, page). - * @param {boolean} isRegistryObject - Whether to return users in the registry format. + * @param {boolean} isLegacyObject - Whether to return users in the legacy format. * @returns {Promise} An object containing the list of users and pagination details. */ - async getAllUsersByOrgShortname (orgShortname, options = {}, isRegistryObject = true) { + async getAllUsersByOrgShortname (orgShortname, options = {}, isLegacyObject = false) { const CONSTANTS = getConstants() const baseOrgRepository = new BaseOrgRepository() const userRepository = new UserRepository() @@ -857,7 +857,7 @@ class BaseUserRepository extends BaseRepository { let agt = {} let pg - if (!isRegistryObject) { + if (isLegacyObject) { agt = setAggregateUserObj({ org_UUID: org.UUID }) pg = await userRepository.aggregatePaginate(agt, options) } else { diff --git a/src/utils/authContext.js b/src/utils/authContext.js index 036c12a3d..b67a0ee3a 100644 --- a/src/utils/authContext.js +++ b/src/utils/authContext.js @@ -76,13 +76,13 @@ async function findOrgByShortName (orgRepo, orgShortName, options = {}, returnLe return orgRepo.findOneByShortName(orgShortName, options) } -async function findUserByUUID (userRepo, userUUID, options = {}, isRegistryObject = true) { +async function findUserByUUID (userRepo, userUUID, options = {}, isLegacyObject = false) { if (!userUUID) { return null } if (typeof userRepo?.findUserByUUID === 'function') { - return userRepo.findUserByUUID(userUUID, options, isRegistryObject) + return userRepo.findUserByUUID(userUUID, options, isLegacyObject) } if (typeof userRepo?.findOneByUUID === 'function') { @@ -92,18 +92,18 @@ async function findUserByUUID (userRepo, userUUID, options = {}, isRegistryObjec return null } -async function findUserByUsernameAndOrgUUID (userRepo, username, orgUUID, options = {}, isRegistryObject = true) { +async function findUserByUsernameAndOrgUUID (userRepo, username, orgUUID, options = {}, isLegacyObject = false) { if (!username || !orgUUID) { return null } if (typeof userRepo?.findUserByUsernameAndOrgUUID === 'function') { - return userRepo.findUserByUsernameAndOrgUUID(username, orgUUID, options, isRegistryObject) + return userRepo.findUserByUsernameAndOrgUUID(username, orgUUID, options, isLegacyObject) } if (typeof userRepo?.findOneByUserNameAndOrgUUID === 'function') { if (isBaseUserRepository(userRepo)) { - return userRepo.findOneByUserNameAndOrgUUID(username, orgUUID, options, isRegistryObject) + return userRepo.findOneByUserNameAndOrgUUID(username, orgUUID, options, isLegacyObject) } return userRepo.findOneByUserNameAndOrgUUID(username, orgUUID, null, options) @@ -125,16 +125,16 @@ async function orgHasRoleByUUID (orgRepo, orgUUID, role, options = {}, returnLeg return orgHasRole(org, role) } -async function isUserAdminOfOrgUUID (userRepo, orgRepo, userUUID, orgUUID, options = {}, isRegistryObject = true) { +async function isUserAdminOfOrgUUID (userRepo, orgRepo, userUUID, orgUUID, options = {}, isLegacyObject = false) { if (!userUUID || !orgUUID) { return false } if (typeof userRepo?.isUserAdminOfOrgUUID === 'function') { - return userRepo.isUserAdminOfOrgUUID(userUUID, orgUUID, options, isRegistryObject) + return userRepo.isUserAdminOfOrgUUID(userUUID, orgUUID, options, isLegacyObject) } - const org = await findOrgByUUID(orgRepo, orgUUID, options, !isRegistryObject) + const org = await findOrgByUUID(orgRepo, orgUUID, options, isLegacyObject) if (!org) { return false } @@ -147,7 +147,7 @@ async function isUserAdminOfOrgUUID (userRepo, orgRepo, userUUID, orgUUID, optio return false } - const user = await findUserByUUID(userRepo, userUUID, options, isRegistryObject) + const user = await findUserByUUID(userRepo, userUUID, options, isLegacyObject) return userHasAdminRole(user) } @@ -188,33 +188,33 @@ async function getRequesterOrg (req, orgRepo, options = {}, returnLegacyFormat = return null } -async function getRequesterUser (req, userRepo, orgRepo, options = {}, isRegistryObject = true) { +async function getRequesterUser (req, userRepo, orgRepo, options = {}, isLegacyObject = false) { if (req.ctx.userUUID) { - return findUserByUUID(userRepo, req.ctx.userUUID, options, isRegistryObject) + return findUserByUUID(userRepo, req.ctx.userUUID, options, isLegacyObject) } if (isAuthenticatedRequest(req) || isUnauthenticatedAfterAuthenticationCheck(req)) { return null } - const orgUUID = await getRequesterOrgUUID(req, orgRepo, options, !isRegistryObject) + const orgUUID = await getRequesterOrgUUID(req, orgRepo, options, isLegacyObject) if (!req.ctx.user || !orgUUID) { return null } - const user = await findUserByUsernameAndOrgUUID(userRepo, req.ctx.user, orgUUID, options, isRegistryObject) + const user = await findUserByUsernameAndOrgUUID(userRepo, req.ctx.user, orgUUID, options, isLegacyObject) if (user) { return user } if (typeof userRepo?.findOneByUsernameAndOrgShortname === 'function') { - return userRepo.findOneByUsernameAndOrgShortname(req.ctx.user, req.ctx.org, options, isRegistryObject) + return userRepo.findOneByUsernameAndOrgShortname(req.ctx.user, req.ctx.org, options, isLegacyObject) } return null } -async function getRequesterUserUUID (req, userRepo, orgRepo, options = {}, isRegistryObject = true) { +async function getRequesterUserUUID (req, userRepo, orgRepo, options = {}, isLegacyObject = false) { if (req.ctx.userUUID) { return req.ctx.userUUID } @@ -225,24 +225,24 @@ async function getRequesterUserUUID (req, userRepo, orgRepo, options = {}, isReg if (!req.ctx.orgUUID && typeof userRepo?.getUserUUID === 'function') { if (isBaseUserRepository(userRepo)) { - return userRepo.getUserUUID(req.ctx.user, req.ctx.org, options, isRegistryObject) + return userRepo.getUserUUID(req.ctx.user, req.ctx.org, options, isLegacyObject) } - const orgUUID = await getRequesterOrgUUID(req, orgRepo, options, !isRegistryObject) + const orgUUID = await getRequesterOrgUUID(req, orgRepo, options, isLegacyObject) return userRepo.getUserUUID(req.ctx.user, orgUUID, options) } - const user = await getRequesterUser(req, userRepo, orgRepo, options, isRegistryObject) + const user = await getRequesterUser(req, userRepo, orgRepo, options, isLegacyObject) if (user?.UUID) { return user.UUID } if (typeof userRepo?.getUserUUID === 'function') { if (isBaseUserRepository(userRepo)) { - return userRepo.getUserUUID(req.ctx.user, req.ctx.org, options, isRegistryObject) + return userRepo.getUserUUID(req.ctx.user, req.ctx.org, options, isLegacyObject) } - const orgUUID = await getRequesterOrgUUID(req, orgRepo, options, !isRegistryObject) + const orgUUID = await getRequesterOrgUUID(req, orgRepo, options, isLegacyObject) return userRepo.getUserUUID(req.ctx.user, orgUUID, options) } @@ -335,13 +335,13 @@ async function isRequesterBulkDownload (req, orgRepo, options = {}, returnLegacy return false } -async function isRequesterAdmin (req, userRepo, orgRepo, options = {}, isRegistryObject = true) { +async function isRequesterAdmin (req, userRepo, orgRepo, options = {}, isLegacyObject = false) { if (isAuthenticatedRequest(req) || (req.ctx.orgUUID && req.ctx.userUUID)) { if (!req.ctx.orgUUID || !req.ctx.userUUID) { return false } - return isUserAdminOfOrgUUID(userRepo, orgRepo, req.ctx.userUUID, req.ctx.orgUUID, options, isRegistryObject) + return isUserAdminOfOrgUUID(userRepo, orgRepo, req.ctx.userUUID, req.ctx.orgUUID, options, isLegacyObject) } if (isUnauthenticatedAfterAuthenticationCheck(req)) { @@ -349,13 +349,13 @@ async function isRequesterAdmin (req, userRepo, orgRepo, options = {}, isRegistr } if (typeof userRepo?.isAdmin === 'function') { - return userRepo.isAdmin(req.ctx.user, req.ctx.org, options, isRegistryObject) + return userRepo.isAdmin(req.ctx.user, req.ctx.org, options, isLegacyObject) } return false } -async function isRequesterAdminOfOrg (req, userRepo, orgRepo, targetOrgOrShortName, options = {}, isRegistryObject = true) { +async function isRequesterAdminOfOrg (req, userRepo, orgRepo, targetOrgOrShortName, options = {}, isLegacyObject = false) { const fallbackTargetShortName = typeof targetOrgOrShortName === 'string' ? targetOrgOrShortName : targetOrgOrShortName?.short_name @@ -369,26 +369,26 @@ async function isRequesterAdminOfOrg (req, userRepo, orgRepo, targetOrgOrShortNa let targetOrgUUID = targetOrg?.UUID || null if (targetOrgUUID && !Array.isArray(targetOrg.admins)) { - const fullTargetOrg = await findOrgByUUID(orgRepo, targetOrgUUID, options, !isRegistryObject) + const fullTargetOrg = await findOrgByUUID(orgRepo, targetOrgUUID, options, isLegacyObject) targetOrg = fullTargetOrg || targetOrg } if (!targetOrg && fallbackTargetShortName) { - targetOrg = await findOrgByShortName(orgRepo, fallbackTargetShortName, options, !isRegistryObject) + targetOrg = await findOrgByShortName(orgRepo, fallbackTargetShortName, options, isLegacyObject) } targetOrgUUID = targetOrg?.UUID || targetOrgUUID if (!targetOrgUUID && fallbackTargetShortName) { - targetOrgUUID = await getTargetOrgUUID(orgRepo, fallbackTargetShortName, options, !isRegistryObject) + targetOrgUUID = await getTargetOrgUUID(orgRepo, fallbackTargetShortName, options, isLegacyObject) } - if (await isUserAdminOfOrgUUID(userRepo, orgRepo, req.ctx.userUUID, targetOrgUUID, options, isRegistryObject)) { + if (await isUserAdminOfOrgUUID(userRepo, orgRepo, req.ctx.userUUID, targetOrgUUID, options, isLegacyObject)) { return true } const sameOrg = Boolean(req.ctx.orgUUID && targetOrgUUID && req.ctx.orgUUID === targetOrgUUID) if (sameOrg) { - const user = await getRequesterUser(req, userRepo, orgRepo, options, isRegistryObject) + const user = await getRequesterUser(req, userRepo, orgRepo, options, isLegacyObject) return userHasAdminRole(user) } @@ -401,29 +401,29 @@ async function isRequesterAdminOfOrg (req, userRepo, orgRepo, targetOrgOrShortNa if (!req.ctx.orgUUID && !req.ctx.userUUID) { if (hasMethod(userRepo, 'isAdminOrSecretariat')) { - return userRepo.isAdminOrSecretariat(fallbackTargetShortName, req.ctx.user, req.ctx.org, options, isRegistryObject) + return userRepo.isAdminOrSecretariat(fallbackTargetShortName, req.ctx.user, req.ctx.org, options, isLegacyObject) } if (hasMethod(userRepo, 'isAdmin')) { - return userRepo.isAdmin(req.ctx.user, fallbackTargetShortName, options, isRegistryObject) + return userRepo.isAdmin(req.ctx.user, fallbackTargetShortName, options, isLegacyObject) } } let targetOrg = typeof targetOrgOrShortName === 'string' ? null : targetOrgOrShortName if (!targetOrg && fallbackTargetShortName) { - targetOrg = await findOrgByShortName(orgRepo, fallbackTargetShortName, options, !isRegistryObject) + targetOrg = await findOrgByShortName(orgRepo, fallbackTargetShortName, options, isLegacyObject) } if (req.ctx.userUUID) { - const targetOrgUUID = targetOrg?.UUID || (fallbackTargetShortName ? await getTargetOrgUUID(orgRepo, fallbackTargetShortName, options, !isRegistryObject) : null) - if (await isUserAdminOfOrgUUID(userRepo, orgRepo, req.ctx.userUUID, targetOrgUUID, options, isRegistryObject)) { + const targetOrgUUID = targetOrg?.UUID || (fallbackTargetShortName ? await getTargetOrgUUID(orgRepo, fallbackTargetShortName, options, isLegacyObject) : null) + if (await isUserAdminOfOrgUUID(userRepo, orgRepo, req.ctx.userUUID, targetOrgUUID, options, isLegacyObject)) { return true } - const sameOrg = await isRequesterSameOrg(req, orgRepo, targetOrg || targetOrgOrShortName, options, !isRegistryObject) + const sameOrg = await isRequesterSameOrg(req, orgRepo, targetOrg || targetOrgOrShortName, options, isLegacyObject) if (sameOrg) { - const user = await getRequesterUser(req, userRepo, orgRepo, options, isRegistryObject) + const user = await getRequesterUser(req, userRepo, orgRepo, options, isLegacyObject) return userHasAdminRole(user) } @@ -431,13 +431,13 @@ async function isRequesterAdminOfOrg (req, userRepo, orgRepo, targetOrgOrShortNa } if (typeof userRepo?.isAdmin === 'function') { - return userRepo.isAdmin(req.ctx.user, fallbackTargetShortName, options, isRegistryObject) + return userRepo.isAdmin(req.ctx.user, fallbackTargetShortName, options, isLegacyObject) } return false } -async function getRequesterContext (req, repositories = {}, options = {}, isRegistryObject = true) { +async function getRequesterContext (req, repositories = {}, options = {}, isLegacyObject = false) { const orgRepo = repositories.orgRepo const userRepo = repositories.userRepo const context = { @@ -451,16 +451,16 @@ async function getRequesterContext (req, repositories = {}, options = {}, isRegi } if (orgRepo) { - context.orgUUID = await getRequesterOrgUUID(req, orgRepo, options, !isRegistryObject) - context.org = await getRequesterOrg(req, orgRepo, options, !isRegistryObject) - context.isSecretariat = await isRequesterSecretariat(req, orgRepo, options, !isRegistryObject) - context.isBulkDownload = await isRequesterBulkDownload(req, orgRepo, options, !isRegistryObject) + context.orgUUID = await getRequesterOrgUUID(req, orgRepo, options, isLegacyObject) + context.org = await getRequesterOrg(req, orgRepo, options, isLegacyObject) + context.isSecretariat = await isRequesterSecretariat(req, orgRepo, options, isLegacyObject) + context.isBulkDownload = await isRequesterBulkDownload(req, orgRepo, options, isLegacyObject) } if (userRepo && orgRepo) { - context.userUUID = await getRequesterUserUUID(req, userRepo, orgRepo, options, isRegistryObject) - context.user = await getRequesterUser(req, userRepo, orgRepo, options, isRegistryObject) - context.isAdmin = await isRequesterAdmin(req, userRepo, orgRepo, options, isRegistryObject) + context.userUUID = await getRequesterUserUUID(req, userRepo, orgRepo, options, isLegacyObject) + context.user = await getRequesterUser(req, userRepo, orgRepo, options, isLegacyObject) + context.isAdmin = await isRequesterAdmin(req, userRepo, orgRepo, options, isLegacyObject) } return context