@@ -724,15 +724,36 @@ async function resetSecret (req, res, next) {
724724
725725 const isRequesterSecretariat = await orgRepo . isSecretariatByShortName ( requesterOrgShortName , { session } )
726726 // const isAdmin = await userRepo.isAdmin(requesterUsername, targetOrgShortName, { session })
727- if ( ! isRequesterSecretariat && ( requesterOrgShortName !== targetOrgShortName ) ) {
727+
728+ // if (!isRequesterSecretariat && (requesterOrgShortName !== targetOrgShortName)) {
729+ // if (requesterOrgShortName !== targetOrgShortName) {
730+ // 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.' })
731+ // await session.abortTransaction()
732+ // return res.status(403).json(error.notSameOrgOrSecretariat())
733+ // } else if (requesterUserUUID !== targetUserUUID) {
734+ // 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.' })
735+ // await session.abortTransaction()
736+ // return res.status(403).json(error.notSameUserOrSecretariat())
737+ // }
738+ // 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.' })
739+ // await session.abortTransaction()
740+ // return res.status(403).json(error.notSameOrgOrSecretariat())
741+ // }
742+
743+ if ( ! isRequesterSecretariat ) {
744+ // If not Secretariat, they must be in the same organization.
745+ if ( requesterOrgShortName !== targetOrgShortName ) {
746+ 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.' } )
747+ await session . abortTransaction ( )
748+ return res . status ( 403 ) . json ( error . notSameOrgOrSecretariat ( ) )
749+ }
750+
751+ // If they are in the same organization, they must be the target user themselves.
728752 if ( requesterUserUUID !== targetUserUUID ) {
729753 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.' } )
730754 await session . abortTransaction ( )
731755 return res . status ( 403 ) . json ( error . notSameUserOrSecretariat ( ) )
732756 }
733- 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.' } )
734- await session . abortTransaction ( )
735- return res . status ( 403 ) . json ( error . notSameOrgOrSecretariat ( ) )
736757 }
737758 // Check if requester is either admin of target org or secretariat, or is same as target user
738759 const isAdminOrSecretariat = await userRepo . isAdminOrSecretariat ( targetOrgShortName , requesterUsername , requesterOrgShortName , { session } , ! req . useRegistry )
0 commit comments