Skip to content

Commit 57b7ea9

Browse files
committed
Revert "Merge pull request #1262 from CVEProject/jf-1258"
This reverts commit 3300b06, reversing changes made to 8fc52ad.
1 parent 821815a commit 57b7ea9

File tree

10 files changed

+32
-637
lines changed

10 files changed

+32
-637
lines changed

api-docs/openapi.json

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2099,7 +2099,7 @@
20992099
"Organization"
21002100
],
21012101
"summary": "Updates information about the organization specified by short name (accessible to Secretariat)",
2102-
"description": " <h2>Access Control</h2> <p>User must belong to an organization with the <b>Secretariat</b> role, or user must belong to the organization specified by short name</p> <h2>Expected Behavior</h2> <p><b>Secretariat:</b> Updates any organization's information</p> <p><b>Non-secretariat:</b> Updates 'last_active' timestamp to show that an org is still active</p>",
2102+
"description": " <h2>Access Control</h2> <p>User must belong to an organization with the <b>Secretariat</b> role</p> <h2>Expected Behavior</h2> <p><b>Secretariat:</b> Updates any organization's information</p>",
21032103
"operationId": "orgUpdateSingle",
21042104
"parameters": [
21052105
{
@@ -2142,14 +2142,7 @@
21422142
"content": {
21432143
"application/json": {
21442144
"schema": {
2145-
"oneOf": [
2146-
{
2147-
"$ref": "../schemas/org/update-org-response.json"
2148-
},
2149-
{
2150-
"$ref": "../schemas/org/am-i-alive-response.json"
2151-
}
2152-
]
2145+
"$ref": "../schemas/org/update-org-response.json"
21532146
}
21542147
}
21552148
}

schemas/org/am-i-alive-response.json

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/controller/org.controller/index.js

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,9 @@ router.put('/org/:shortname',
245245
#swagger.summary = "Updates information about the organization specified by short name (accessible to Secretariat)"
246246
#swagger.description = "
247247
<h2>Access Control</h2>
248-
<p>User must belong to an organization with the <b>Secretariat</b> role, or user must belong to the organization specified by short name</p>
248+
<p>User must belong to an organization with the <b>Secretariat</b> role</p>
249249
<h2>Expected Behavior</h2>
250-
<p><b>Secretariat:</b> Updates any organization's information</p>
251-
<p><b>Non-secretariat:</b> Updates 'last_active' timestamp to show that an org is still active</p>"
250+
<p><b>Secretariat:</b> Updates any organization's information</p>"
252251
#swagger.parameters['shortname'] = { description: 'The shortname of the organization' }
253252
#swagger.parameters['$ref'] = [
254253
'#/components/parameters/id_quota',
@@ -264,12 +263,7 @@ router.put('/org/:shortname',
264263
description: 'Returns information about the organization updated',
265264
content: {
266265
"application/json": {
267-
schema: {
268-
oneOf: [
269-
{ $ref: '../schemas/org/update-org-response.json' },
270-
{ $ref: '../schemas/org/am-i-alive-response.json' }
271-
]
272-
}
266+
schema: { $ref: '../schemas/org/update-org-response.json' }
273267
}
274268
}
275269
}
@@ -315,10 +309,10 @@ router.put('/org/:shortname',
315309
}
316310
*/
317311
mw.validateUser,
318-
param(['shortname']).isString().trim().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
319-
mw.validateOrg,
312+
mw.onlySecretariat,
320313
query().custom((query) => { return mw.validateQueryParameterNames(query, ['new_short_name', 'id_quota', 'name', 'active_roles.add', 'active_roles.remove']) }),
321314
query(['new_short_name', 'id_quota', 'name', 'active_roles.add', 'active_roles.remove']).custom((val) => { return mw.containsNoInvalidCharacters(val) }),
315+
param(['shortname']).isString().trim().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
322316
query(['new_short_name']).optional().isString().trim().notEmpty().isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }),
323317
query(['id_quota']).optional().not().isArray().isInt({ min: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_min, max: CONSTANTS.MONGOOSE_VALIDATION.Org_policies_id_quota_max }).withMessage(errorMsgs.ID_QUOTA),
324318
query(['name']).optional().isString().trim().notEmpty(),

src/controller/org.controller/org.controller.js

Lines changed: 24 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ async function updateOrg (req, res, next) {
329329
const addRoles = []
330330
const orgRepo = req.ctx.repositories.getOrgRepository()
331331
const org = await orgRepo.findOneByShortName(shortName)
332-
const orgMakingChanges = req.ctx.org
333332
let agt = setAggregateOrgObj({ short_name: shortName })
334333

335334
// org doesn't exist
@@ -338,38 +337,30 @@ async function updateOrg (req, res, next) {
338337
return res.status(404).json(error.orgDnePathParam(shortName))
339338
}
340339

341-
const isSec = await orgRepo.isSecretariat(orgMakingChanges)
342-
343-
if (isSec) {
344-
Object.keys(req.ctx.query).forEach(k => {
345-
const key = k.toLowerCase()
346-
347-
if (key === 'new_short_name') {
348-
newOrg.short_name = req.ctx.query.new_short_name
349-
agt = setAggregateOrgObj({ short_name: newOrg.short_name })
350-
} else if (key === 'name') {
351-
newOrg.name = req.ctx.query.name
352-
} else if (key === 'id_quota') {
353-
newOrg.policies.id_quota = req.ctx.query.id_quota
354-
} else if (key === 'active_roles.add') {
355-
if (Array.isArray(req.ctx.query['active_roles.add'])) {
356-
req.ctx.query['active_roles.add'].forEach(r => {
357-
addRoles.push(r)
358-
})
359-
}
360-
} else if (key === 'active_roles.remove') {
361-
if (Array.isArray(req.ctx.query['active_roles.remove'])) {
362-
req.ctx.query['active_roles.remove'].forEach(r => {
363-
removeRoles.push(r)
364-
})
365-
}
366-
}
367-
})
368-
}
340+
Object.keys(req.ctx.query).forEach(k => {
341+
const key = k.toLowerCase()
369342

370-
if (shortName === orgMakingChanges) {
371-
newOrg.last_active = Date.now()
372-
}
343+
if (key === 'new_short_name') {
344+
newOrg.short_name = req.ctx.query.new_short_name
345+
agt = setAggregateOrgObj({ short_name: newOrg.short_name })
346+
} else if (key === 'name') {
347+
newOrg.name = req.ctx.query.name
348+
} else if (key === 'id_quota') {
349+
newOrg.policies.id_quota = req.ctx.query.id_quota
350+
} else if (key === 'active_roles.add') {
351+
if (Array.isArray(req.ctx.query['active_roles.add'])) {
352+
req.ctx.query['active_roles.add'].forEach(r => {
353+
addRoles.push(r)
354+
})
355+
}
356+
} else if (key === 'active_roles.remove') {
357+
if (Array.isArray(req.ctx.query['active_roles.remove'])) {
358+
req.ctx.query['active_roles.remove'].forEach(r => {
359+
removeRoles.push(r)
360+
})
361+
}
362+
}
363+
})
373364

374365
// updating the org's roles
375366
if (org) {
@@ -412,13 +403,6 @@ async function updateOrg (req, res, next) {
412403
result = await orgRepo.aggregate(agt)
413404
result = result.length > 0 ? result[0] : null
414405

415-
if (!isSec) {
416-
if (!result || !result.last_active) {
417-
return res.status(500).json(error.serverError())
418-
}
419-
result = { last_active: result.last_active }
420-
}
421-
422406
const responseMessage = {
423407
message: shortName + ' organization was successfully updated.',
424408
updated: result
@@ -835,8 +819,7 @@ function setAggregateOrgObj (query) {
835819
name: true,
836820
'authority.active_roles': true,
837821
'policies.id_quota': true,
838-
time: true,
839-
last_active: true
822+
time: true
840823
}
841824
}
842825
]

src/middleware/middleware.js

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,32 +135,6 @@ async function validateUser (req, res, next) {
135135
}
136136
}
137137

138-
async function validateOrg (req, res, next) {
139-
const org = req.ctx.org
140-
const reqOrg = req.params.shortname
141-
const orgRepo = req.ctx.repositories.getOrgRepository()
142-
const CONSTANTS = getConstants()
143-
144-
try {
145-
logger.info({ uuid: req.ctx.uuid, message: 'Authenticating org: ' + org })
146-
147-
const isSec = await orgRepo.isSecretariat(org)
148-
if (!isSec) {
149-
if (org !== reqOrg) {
150-
logger.info({ uuid: req.ctx.uuid, message: org + ' is not a ' + CONSTANTS.AUTH_ROLE_ENUM.SECRETARIAT + ' or the same as ' + reqOrg + ' and is not allowed to make these changes.' })
151-
return res.status(403).json(error.secretariatOnly())
152-
} else if (Object.keys(req.query).length > 0) {
153-
return res.status(403).json(error.secretariatOnly())
154-
}
155-
}
156-
157-
logger.info({ uuid: req.ctx.uuid, message: 'Confirmed ' + org + ' has the authority to make changes to ' + reqOrg })
158-
next()
159-
} catch (err) {
160-
next(err)
161-
}
162-
}
163-
164138
// Checks that the requester belongs to an org that has the 'BULK_DOWNLOAD' role
165139
async function onlySecretariatOrBulkDownload (req, res, next) {
166140
const org = req.ctx.org
@@ -509,7 +483,6 @@ module.exports = {
509483
setCacheControl,
510484
optionallyValidateUser,
511485
validateUser,
512-
validateOrg,
513486
onlySecretariat,
514487
onlySecretariatOrBulkDownload,
515488
onlySecretariatOrAdmin,

src/model/org.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ const schema = {
2424
created: Date,
2525
modified: Date
2626
},
27-
inUse: Boolean,
28-
last_active: Date
27+
inUse: Boolean
2928
}
3029

3130
const OrgSchema = new mongoose.Schema(schema, { collection: 'Org', timestamps: { createdAt: 'time.created', updatedAt: 'time.modified' } })

0 commit comments

Comments
 (0)