Skip to content

Commit ddfedd4

Browse files
committed
conflicts
1 parent 1431899 commit ddfedd4

2 files changed

Lines changed: 36 additions & 5 deletions

File tree

src/controller/registry-user.controller/registry-user.controller.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,11 @@ async function updateUser (req, res, next) {
258258
return res.status(404).json(error.orgDnePathParam(userToEditParameters.org))
259259
}
260260

261+
if (body.org_short_name && !isSecretariat) {
262+
logger.info({ uuid: req.ctx.uuid, message: 'Only Secretariat can reassign user organization.' })
263+
return res.status(403).json(error.notAllowedToChangeOrganization())
264+
}
265+
261266
if (body.org_short_name) {
262267
const targetOrg = await orgRepo.findOneByShortName(body.org_short_name)
263268
if (!targetOrg) {
@@ -266,11 +271,6 @@ async function updateUser (req, res, next) {
266271
}
267272
}
268273

269-
if (body.org_short_name && !isSecretariat) {
270-
logger.info({ uuid: req.ctx.uuid, message: 'Only Secretariat can reassign user organization.' })
271-
return res.status(403).json(error.notAllowedToChangeOrganization())
272-
}
273-
274274
if (body.org_short_name && isSecretariat && userToEditParameters.org === org.short_name && body.org_short_name === org.short_name) {
275275
logger.info({ uuid: req.ctx.uuid, message: `User ${userToEditParameters.username} is already in organization ${userToEditParameters.org}.` })
276276
return res.status(403).json(error.alreadyInOrg(org.short_name, userToEditParameters.username))

test/integration-tests/user/updateUserTest.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,36 @@ describe('Testing Edit user endpoint', () => {
205205
expect(res.body.error).to.equal('SECRET_UPDATE_NOT_ALLOWED')
206206
})
207207
})
208+
it('Should return 404 when target organization in path does not exist', async () => {
209+
const user = constants.headers['CVE-API-USER']
210+
await chai.request(app)
211+
.put(`/api/registry/org/non_existent_org/user/${user}`)
212+
.set(constants.headers)
213+
.send({
214+
name: {
215+
first: 'NewFirst',
216+
last: 'NewLast'
217+
}
218+
})
219+
.then((res) => {
220+
expect(res).to.have.status(404)
221+
expect(res.body.error).to.contain('ORG_DNE_PARAM')
222+
})
223+
})
224+
225+
it('Should return 404 when target organization in body does not exist', async () => {
226+
const user = constants.headers['CVE-API-USER']
227+
const org = constants.headers['CVE-API-ORG']
228+
await chai.request(app)
229+
.put(`/api/registry/org/${org}/user/${user}`)
230+
.set(constants.headers)
231+
.send({
232+
org_short_name: 'non_existent_org'
233+
})
234+
.then((res) => {
235+
expect(res).to.have.status(404)
236+
expect(res.body.error).to.contain('ORG_DNE_PARAM')
237+
})
238+
})
208239
})
209240
})

0 commit comments

Comments
 (0)