@@ -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,23 @@ 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 } )
12731287
1288+ const requesterUUID = await userRegistryRepo . getUserUUID ( requesterUsername , requesterOrgUUID , { session } )
1289+ const targetUserUUID = await userRegistryRepo . getUserUUID ( username , orgRegUUID , { session } )
12741290 // check if orgUUID and orgRegUUID are the same
12751291 if ( orgUUID . toString ( ) !== orgRegUUID . toString ( ) ) {
12761292 logger . info ( { uuid : req . ctx . uuid , message : 'The organization UUID and the organization registry UUID are not the same.' } )
12771293 return res . status ( 500 ) . json ( error . internalServerError ( ) )
12781294 }
12791295
12801296 if ( ! orgUUID && ! orgRegUUID ) {
1281- logger . info ( { uuid : req . ctx . uuid , messsage : orgShortName + ' organization does not exist.' } )
1297+ logger . info ( { uuid : req . ctx . uuid , message : orgShortName + ' organization does not exist.' } )
12821298 return res . status ( 404 ) . json ( error . orgDnePathParam ( orgShortName ) )
12831299 }
12841300
@@ -1291,14 +1307,24 @@ async function resetSecret (req, res, next) {
12911307 const oldUserRegistry = await userRegistryRepo . findOneByUserNameAndOrgUUID ( username , orgRegUUID , null , { session } )
12921308
12931309 if ( ! oldUser && ! oldUserRegistry ) {
1294- logger . info ( { uuid : req . ctx . uuid , messsage : username + ' user does not exist.' } )
1310+ logger . info ( { uuid : req . ctx . uuid , message : username + ' user does not exist.' } )
12951311 return res . status ( 404 ) . json ( error . userDne ( username ) )
12961312 }
12971313
12981314 const isLegAdmin = await userRepo . isAdmin ( requesterUsername , requesterShortName , false , { session } )
12991315 const isRegAdmin = await userRegistryRepo . isAdmin ( requesterUsername , requesterShortName , true , { session } )
13001316 const isAdmin = isLegAdmin && isRegAdmin
13011317
1318+ if ( ! isSecretariat && ! isAdmin ) {
1319+ if ( targetUserUUID !== requesterUUID ) {
1320+ if ( ! targetUserUUID ) {
1321+ logger . info ( { uuid : req . ctx . uuid , message : 'User DNE' } )
1322+ await session . abortTransaction ( ) ; await session . endSession ( )
1323+ return res . status ( 404 ) . json ( error . userDne ( username ) )
1324+ }
1325+ }
1326+ }
1327+
13021328 // check if the user is not the requester or if the requester is not a secretariat
13031329 if ( ( orgShortName !== requesterShortName || username !== requesterUsername ) && ! isSecretariat ) {
13041330 // check if the requester is not and admin; if admin, the requester must be from the same org as the user
0 commit comments