diff --git a/src/controller/org.controller/org.controller.js b/src/controller/org.controller/org.controller.js index 9f7bb8845..1c982c260 100644 --- a/src/controller/org.controller/org.controller.js +++ b/src/controller/org.controller/org.controller.js @@ -485,6 +485,11 @@ async function updateUser (req, res, next) { return res.status(404).json(error.orgDneParam(shortName)) } + if (shortName !== requesterShortName && !isSecretariat) { + logger.info({ uuid: req.ctx.uuid, message: shortName + ' organization can only be viewed by the users of the same organization or the Secretariat.' }) + return res.status(403).json(error.notSameOrgOrSecretariat()) + } + const user = await userRepo.findOneByUserNameAndOrgUUID(username, orgUUID) if (!user) { logger.info({ uuid: req.ctx.uuid, message: 'The user could not be updated because ' + username + ' does not exist for ' + shortName + ' organization.' }) diff --git a/test-http/src/test/org_user_tests/org_as_org_admin.py b/test-http/src/test/org_user_tests/org_as_org_admin.py index a40058fd0..ac2d43a08 100644 --- a/test-http/src/test/org_user_tests/org_as_org_admin.py +++ b/test-http/src/test/org_user_tests/org_as_org_admin.py @@ -266,7 +266,7 @@ def test_org_admin_cannot_update_user_for_another_org(org_admin_headers): headers=org_admin_headers ) assert res.status_code == 403 - response_contains_json(res, 'error', 'NOT_SAME_USER_OR_SECRETARIAT') + response_contains_json(res, 'error', 'NOT_SAME_ORG_OR_SECRETARIAT') def test_org_admin_cannot_update_user_new_shortname_dne(org_admin_headers): diff --git a/test/unit-tests/user/userUpdateTest.js b/test/unit-tests/user/userUpdateTest.js index 38bdf1ec5..8718b1629 100644 --- a/test/unit-tests/user/userUpdateTest.js +++ b/test/unit-tests/user/userUpdateTest.js @@ -270,7 +270,7 @@ describe('Testing the PUT /org/:shortname/user/:username endpoint in Org Control expect(res).to.have.status(403) expect(res).to.have.property('body').and.to.be.a('object') - const errObj = error.notSameUserOrSecretariat() + const errObj = error.notSameOrgOrSecretariat() expect(res.body.error).to.equal(errObj.error) expect(res.body.message).to.equal(errObj.message) done() @@ -320,7 +320,7 @@ describe('Testing the PUT /org/:shortname/user/:username endpoint in Org Control expect(res).to.have.status(403) expect(res).to.have.property('body').and.to.be.a('object') - const errObj = error.notSameUserOrSecretariat() + const errObj = error.notSameOrgOrSecretariat() expect(res.body.error).to.equal(errObj.error) expect(res.body.message).to.equal(errObj.message) done()