Skip to content

Commit faf5e6d

Browse files
committed
Fixed a typing issue for authority
1 parent 120e6d7 commit faf5e6d

File tree

11 files changed

+31
-16
lines changed

11 files changed

+31
-16
lines changed

src/controller/org.controller/index.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1008,7 +1008,9 @@ router.post(
10081008
.isString().withMessage(errorMsgs.MUST_BE_STRING).trim()
10091009
.notEmpty().withMessage(errorMsgs.NOT_EMPTY)
10101010
.isLength({ min: CONSTANTS.MIN_SHORTNAME_LENGTH, max: CONSTANTS.MAX_SHORTNAME_LENGTH }).withMessage(errorMsgs.SHORTNAME_LENGTH),
1011-
body(['name']).isString().trim().notEmpty(),
1011+
body(['name'])
1012+
.isString().withMessage(errorMsgs.MUST_BE_STRING).trim()
1013+
.notEmpty().withMessage(errorMsgs.NOT_EMPTY),
10121014
body(['authority.active_roles']).optional()
10131015
.custom(isFlatStringArray)
10141016
.customSanitizer(toUpperCaseArray)

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require('dotenv').config()
22
const mongoose = require('mongoose')
3+
const _ = require('lodash')
34
const logger = require('../../middleware/logger')
45
const getConstants = require('../../constants').getConstants
56
const errors = require('./error')
@@ -238,9 +239,9 @@ async function registryCreateOrg (req, res, next) {
238239
logger.error(JSON.stringify({ uuid: req.ctx.uuid, message: 'CVE JSON schema validation FAILED.' }))
239240
await session.abortTransaction()
240241
if (!Array.isArray(body?.authority) || body?.authority.some(item => typeof item !== 'string')) {
241-
return res.status(400).json({ message: 'Parameters were invalid', details: [{ param: 'authority', msg: 'Parameter must be a one-dimensional array of strings' }] })
242+
return res.status(400).json({ error: 'BAD_INPUT', message: 'Parameters were invalid', details: [{ param: 'authority', msg: 'Parameter must be a one-dimensional array of strings' }] })
242243
}
243-
return res.status(400).json({ message: 'Parameters were invalid', errors: result.errors })
244+
return res.status(400).json({ error: 'BAD_INPUT', message: 'Parameters were invalid', errors: result.errors })
244245
}
245246

246247
// Check to see if the org already exists

src/middleware/schemas/ADPOrg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"properties": {
1111
"authority": {
12-
"const": "ADP"
12+
"const": ["ADP"]
1313
}
1414
}
1515
}

src/middleware/schemas/BaseOrg.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,11 @@
6262
}
6363
},
6464
"authority": {
65-
"$ref": "#/definitions/authority"
65+
"type": "array",
66+
"uniqueItems": true,
67+
"items": {
68+
"$ref": "#/definitions/authority"
69+
}
6670
},
6771
"root_or_tlr": {
6872
"type": "boolean"

src/middleware/schemas/BulkDownloadOrg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"properties": {
1111
"authority": {
12-
"const": "BULK_DOWNLOAD"
12+
"const": ["BULK_DOWNLOAD"]
1313
}
1414
}
1515
}

src/middleware/schemas/CNAOrg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"properties": {
1111
"authority": {
12-
"const": "CNA"
12+
"const": ["CNA"]
1313
},
1414
"oversees": {
1515
"type": "array",

src/middleware/schemas/SecretariatOrg.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
{
1010
"properties": {
1111
"authority": {
12-
"const": "SECRETARIAT"
12+
"const": ["SECRETARIAT"]
1313
},
1414
"oversees": {
1515
"type": "array",

src/repositories/baseOrgRepository.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,14 +642,22 @@ class BaseOrgRepository extends BaseRepository {
642642
if (Array.isArray(org.authority)) {
643643
// User passed in an array, we need to decide how we handle this.
644644
if (org.authority.includes('SECRETARIAT')) {
645-
org.authority = 'SECRETARIAT'
645+
org.authority = ['SECRETARIAT']
646646
validateObject = SecretariatOrgModel.validateOrg(org)
647647
} else {
648648
// We are not a secretariat, so we need to take most priv
649649
if (org.authority.includes('CNA') || org.authority.length === 0) {
650-
org.authority = 'CNA'
650+
org.authority = ['CNA']
651651
validateObject = CNAOrgModel.validateOrg(org)
652652
}
653+
if (org.authority.includes('ADP')) {
654+
org.authority = ['ADP']
655+
validateObject = ADPOrgModel.validateOrg(org)
656+
}
657+
if (org.authority.includes('BULK_DOWNLOAD')) {
658+
org.authority = ['BULK_DOWNLOAD']
659+
validateObject = BulkDownloadModel.validateOrg(org)
660+
}
653661
}
654662
} else {
655663
if (org.authority === 'ADP') {

test/integration-tests/constants.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ const testRegistryOrg = {
373373
org_email: '[email protected]',
374374
website: 'https://test.org'
375375
},
376-
authority: 'CNA',
376+
authority: ['CNA'],
377377
hard_quota: 100000
378378
}
379379

@@ -387,7 +387,7 @@ const testRegistryOrg2 = {
387387
org_email: '[email protected]',
388388
website: 'https://test.org'
389389
},
390-
authority: 'CNA',
390+
authority: ['CNA'],
391391
hard_quota: 100000
392392
}
393393

@@ -415,7 +415,7 @@ const existingRegistryOrg = {
415415
org_email: '[email protected]',
416416
website: 'https://test.org'
417417
},
418-
authority: 'CNA',
418+
authority: ['CNA'],
419419
hard_quota: 100000
420420
}
421421

test/integration-tests/registry-org/registryOrgCRUDTest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const secretariatHeaders = { ...constants.headers, 'content-type': 'application/
1111
const testRegistryOrg = {
1212
short_name: 'registry_org_test',
1313
long_name: 'Registry Org Test',
14-
authority: 'CNA',
14+
authority: ['CNA'],
1515
hard_quota: 1000
1616
}
1717
let createdOrg

0 commit comments

Comments
 (0)