Skip to content

Commit 00b883e

Browse files
author
James Cori
committed
Merge branch 'develop'
2 parents c0b72b4 + 13c745b commit 00b883e

File tree

7 files changed

+88
-48
lines changed

7 files changed

+88
-48
lines changed

config/default.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ module.exports = {
2323
// bus API config params
2424
BUSAPI_URL: process.env.BUSAPI_URL || 'https://api.topcoder-dev.com/v5',
2525
KAFKA_ERROR_TOPIC: process.env.KAFKA_ERROR_TOPIC || 'common.error.reporting',
26+
SCHEDULING_TOPIC: process.env.SCHEDULING_TOPIC || 'challenge.notification.schedule.update',
2627

2728
AMAZON: {
2829
// AWS_ACCESS_KEY_ID: process.env.AWS_FAKE_ID || 'FAKE_ACCESS_KEY',
@@ -75,5 +76,5 @@ module.exports = {
7576

7677
DEFAULT_CONFIDENTIALITY_TYPE: process.env.DEFAULT_CONFIDENTIALITY_TYPE || 'public',
7778

78-
M2M_AUDIT_HANDLE: process.env.M2M_AUDIT_HANDLE || 'TopcoderService'
79+
M2M_AUDIT_HANDLE: process.env.M2M_AUDIT_HANDLE || 'tcwebservice'
7980
}

docs/swagger.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,11 @@ paths:
400400
Will be ignored for regular users or not authenticated users
401401
required: false
402402
type: string
403+
- name: useSchedulingAPI
404+
in: query
405+
description: Search based on `legacy.useSchedulingAPI`
406+
type: boolean
407+
required: false
403408
- in: body
404409
name: body
405410
required: false
@@ -2095,7 +2100,7 @@ paths:
20952100
tags:
20962101
- Attachments
20972102
description: >
2098-
Create a new attachment in the system.
2103+
Create a new attachment in the system. If you want to create multiple attachment, you can pass an array of objects instead of a single object.
20992104
security:
21002105
- bearer: []
21012106
produces:

src/common/helper.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,13 +639,20 @@ function getESClient () {
639639
/**
640640
* Ensure project exist
641641
* @param {String} projectId the project id
642-
* @param {String} userToken the user token
642+
* @param {String} currentUser the user
643643
*/
644-
async function ensureProjectExist (projectId, userToken) {
644+
async function ensureProjectExist (projectId, currentUser) {
645645
let token = await getM2MToken()
646646
const url = `${config.PROJECTS_API_URL}/${projectId}`
647647
try {
648-
await axios.get(url, { headers: { Authorization: `Bearer ${token}` } })
648+
const res = await axios.get(url, { headers: { Authorization: `Bearer ${token}` } })
649+
if (currentUser.isMachine || hasAdminRole(currentUser)) {
650+
return res.data
651+
}
652+
if (!_.find(_.get(res, 'data.members', []), m => _.toString(m.userId) === _.toString(currentUser.userId))) {
653+
throw new errors.ForbiddenError(`You don't have access to project with ID: ${projectId}`)
654+
}
655+
return res.data
649656
} catch (err) {
650657
if (_.get(err, 'response.status') === HttpStatus.NOT_FOUND) {
651658
throw new errors.BadRequestError(`Project with id: ${projectId} doesn't exist`)

src/controllers/AttachmentController.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Controller for attachment endpoints
33
*/
44
const HttpStatus = require('http-status-codes')
5+
const _ = require('lodash')
56
const service = require('../services/AttachmentService')
67

78
/**
@@ -10,7 +11,8 @@ const service = require('../services/AttachmentService')
1011
* @param {Object} res the response
1112
*/
1213
async function createAttachment (req, res) {
13-
const result = await service.createAttachment(req.authUser, req.params.challengeId, req.body)
14+
const body = _.isArray(req.body) ? req.body : [req.body]
15+
const result = await service.createAttachment(req.authUser, req.params.challengeId, body)
1416
res.status(HttpStatus.CREATED).send(result)
1517
}
1618

src/controllers/ChallengeController.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async function searchChallenges (req, res) {
2424
*/
2525
async function createChallenge (req, res) {
2626
logger.debug(`createChallenge User: ${JSON.stringify(req.authUser)} - Body: ${JSON.stringify(req.body)}`)
27-
const result = await service.createChallenge(req.authUser, req.body, req.userToken)
27+
const result = await service.createChallenge(req.authUser, req.body)
2828
res.status(HttpStatus.CREATED).send(result)
2929
}
3030

@@ -45,7 +45,7 @@ async function getChallenge (req, res) {
4545
*/
4646
async function fullyUpdateChallenge (req, res) {
4747
logger.debug(`fullyUpdateChallenge User: ${JSON.stringify(req.authUser)} - ChallengeID: ${req.params.challengeId} - Body: ${JSON.stringify(req.body)}`)
48-
const result = await service.fullyUpdateChallenge(req.authUser, req.params.challengeId, req.body, req.userToken)
48+
const result = await service.fullyUpdateChallenge(req.authUser, req.params.challengeId, req.body)
4949
res.send(result)
5050
}
5151

@@ -56,7 +56,7 @@ async function fullyUpdateChallenge (req, res) {
5656
*/
5757
async function partiallyUpdateChallenge (req, res) {
5858
logger.debug(`partiallyUpdateChallenge User: ${JSON.stringify(req.authUser)} - ChallengeID: ${req.params.challengeId} - Body: ${JSON.stringify(req.body)}`)
59-
const result = await service.partiallyUpdateChallenge(req.authUser, req.params.challengeId, req.body, req.userToken)
59+
const result = await service.partiallyUpdateChallenge(req.authUser, req.params.challengeId, req.body)
6060
res.send(result)
6161
}
6262

src/services/AttachmentService.js

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,36 +52,40 @@ async function _getChallengeAttachment (challengeId, attachmentId) {
5252
/**
5353
* Create attachment.
5454
* @param {String} challengeId the challenge id
55-
* @param {Object} attachment the attachment to created
55+
* @param {Array} attachments the attachments to be created
5656
* @returns {Object} the created attachment
5757
*/
58-
async function createAttachment (currentUser, challengeId, attachment) {
58+
async function createAttachment (currentUser, challengeId, attachments) {
5959
const challenge = await helper.getById('Challenge', challengeId)
6060
await helper.ensureUserCanModifyChallenge(currentUser, challenge)
61-
validateUrl(attachment.url)
62-
const attachmentObject = { id: uuid(), challengeId, ...attachment }
63-
const ret = await helper.create('Attachment', attachmentObject)
61+
const newAttachments = []
62+
for (const attachment of attachments) {
63+
validateUrl(attachment.url)
64+
const attachmentObject = { id: uuid(), challengeId, ...attachment }
65+
const newAttachment = await helper.create('Attachment', attachmentObject)
66+
await helper.postBusEvent(constants.Topics.ChallengeAttachmentCreated, newAttachment)
67+
newAttachments.push(newAttachment)
68+
}
6469
// update challenge object
6570
await challengeService.partiallyUpdateChallenge(currentUser, challengeId, {
6671
attachments: [
6772
..._.get(challenge, 'attachments', []),
68-
ret
73+
...newAttachments
6974
]
7075
})
7176
// post bus event
72-
await helper.postBusEvent(constants.Topics.ChallengeAttachmentCreated, ret)
73-
return ret
77+
return newAttachments
7478
}
7579

7680
createAttachment.schema = {
7781
currentUser: Joi.any(),
7882
challengeId: Joi.id(),
79-
attachment: Joi.object().keys({
83+
attachments: Joi.array().items(Joi.object().keys({
8084
name: Joi.string().required(),
8185
url: Joi.string().uri().required(),
8286
fileSize: Joi.fileSize(),
8387
description: Joi.string()
84-
}).required()
88+
})).required().min(1)
8589
}
8690

8791
/**

0 commit comments

Comments
 (0)