Skip to content

Commit

Permalink
Merge pull request #579 from wizedkyle/issue-574
Browse files Browse the repository at this point in the history
Issue #574
  • Loading branch information
slubar authored Mar 21, 2022
2 parents 340bdfb + 0ccabab commit 718b712
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/controller/org.controller/org.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.' })
Expand Down
2 changes: 1 addition & 1 deletion test-http/src/test/org_user_tests/org_as_org_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/user/userUpdateTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit 718b712

Please sign in to comment.