@@ -905,9 +905,14 @@ async function updateUser (req, res, next) {
905905
906906 if ( ! isRequesterSecretariat && ! isAdmin ) {
907907 if ( targetUserUUID !== requesterUUID ) {
908- logger . info ( { uuid : req . ctx . uuid , message : 'Only Secretariat can reassign user organization.' } )
908+ if ( ! targetUserUUID ) {
909+ logger . info ( { uuid : req . ctx . uuid , message : 'User DNE' } )
910+ await session . abortTransaction ( ) ; await session . endSession ( )
911+ return res . status ( 404 ) . json ( error . userDne ( usernameParams ) )
912+ }
913+ logger . info ( { uuid : req . ctx . uuid , message : 'Not same user or secretariat' } )
909914 await session . abortTransaction ( ) ; await session . endSession ( )
910- return res . status ( 403 ) . json ( error . notSameUserOrSecretariatUpdate ( ) )
915+ return res . status ( 403 ) . json ( error . notSameUserOrSecretariat ( ) )
911916 }
912917 }
913918
@@ -1027,6 +1032,13 @@ async function updateUser (req, res, next) {
10271032 }
10281033 }
10291034
1035+ if ( queryParameters . active ) {
1036+ if ( requesterUUID === targetUserUUID ) {
1037+ await session . abortTransaction ; await session . endSession ( )
1038+ return res . status ( 403 ) . json ( error . notOrgAdminOrSecretariatUpdate ( ) )
1039+ }
1040+ }
1041+
10301042 // Check to make sure we are NOT self demoting
10311043 if ( removeRolesCollector . includes ( 'ADMIN' ) ) {
10321044 if ( requesterUUID === targetUserUUID ) {
@@ -1266,19 +1278,30 @@ async function resetSecret (req, res, next) {
12661278 try {
12671279 const isSecretariatLeg = await orgRepo . isSecretariat ( requesterShortName , { session } )
12681280 const isSecretariatReg = await orgRegistryRepo . isSecretariat ( requesterShortName , { session } )
1281+
12691282 const isSecretariat = isSecretariatLeg && isSecretariatReg
12701283
12711284 const orgUUID = await orgRepo . getOrgUUID ( orgShortName , { session } ) // userUUID may be null if user does not exist
12721285 const orgRegUUID = await orgRegistryRepo . getOrgUUID ( orgShortName , { session } )
1286+ const requesterOrgUUID = await orgRegistryRepo . getOrgUUID ( requesterShortName , { session } )
1287+ const targetOrgUUID = await orgRegistryRepo . getOrgUUID ( orgShortName , { session } )
12731288
1289+ if ( ! targetOrgUUID ) {
1290+ logger . info ( { uuid : req . ctx . uuid , message : 'User DNE' } )
1291+ await session . abortTransaction ( ) ; await session . endSession ( )
1292+ return res . status ( 404 ) . json ( error . orgDnePathParam ( orgShortName ) )
1293+ }
1294+
1295+ const requesterUUID = await userRegistryRepo . getUserUUID ( requesterUsername , requesterOrgUUID , { session } )
1296+ const targetUserUUID = await userRegistryRepo . getUserUUID ( username , orgRegUUID , { session } )
12741297 // check if orgUUID and orgRegUUID are the same
12751298 if ( orgUUID . toString ( ) !== orgRegUUID . toString ( ) ) {
12761299 logger . info ( { uuid : req . ctx . uuid , message : 'The organization UUID and the organization registry UUID are not the same.' } )
12771300 return res . status ( 500 ) . json ( error . internalServerError ( ) )
12781301 }
12791302
12801303 if ( ! orgUUID && ! orgRegUUID ) {
1281- logger . info ( { uuid : req . ctx . uuid , messsage : orgShortName + ' organization does not exist.' } )
1304+ logger . info ( { uuid : req . ctx . uuid , message : orgShortName + ' organization does not exist.' } )
12821305 return res . status ( 404 ) . json ( error . orgDnePathParam ( orgShortName ) )
12831306 }
12841307
@@ -1291,14 +1314,24 @@ async function resetSecret (req, res, next) {
12911314 const oldUserRegistry = await userRegistryRepo . findOneByUserNameAndOrgUUID ( username , orgRegUUID , null , { session } )
12921315
12931316 if ( ! oldUser && ! oldUserRegistry ) {
1294- logger . info ( { uuid : req . ctx . uuid , messsage : username + ' user does not exist.' } )
1317+ logger . info ( { uuid : req . ctx . uuid , message : username + ' user does not exist.' } )
12951318 return res . status ( 404 ) . json ( error . userDne ( username ) )
12961319 }
12971320
12981321 const isLegAdmin = await userRepo . isAdmin ( requesterUsername , requesterShortName , false , { session } )
12991322 const isRegAdmin = await userRegistryRepo . isAdmin ( requesterUsername , requesterShortName , true , { session } )
13001323 const isAdmin = isLegAdmin && isRegAdmin
13011324
1325+ if ( ! isSecretariat && ! isAdmin ) {
1326+ if ( targetUserUUID !== requesterUUID ) {
1327+ if ( ! targetUserUUID ) {
1328+ logger . info ( { uuid : req . ctx . uuid , message : 'User DNE' } )
1329+ await session . abortTransaction ( ) ; await session . endSession ( )
1330+ return res . status ( 404 ) . json ( error . userDne ( username ) )
1331+ }
1332+ }
1333+ }
1334+
13021335 // check if the user is not the requester or if the requester is not a secretariat
13031336 if ( ( orgShortName !== requesterShortName || username !== requesterUsername ) && ! isSecretariat ) {
13041337 // check if the requester is not and admin; if admin, the requester must be from the same org as the user
0 commit comments