Skip to content

Commit c22c3b3

Browse files
author
vikasrohit
authored
Merge pull request #39 from topcoder-platform/develop
Prod release 1.1.0
2 parents b0174d2 + 665ae6a commit c22c3b3

14 files changed

+848
-842
lines changed

config/default.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ module.exports = {
2929
esConfig: {
3030
HOST: process.env.ES_HOST || 'localhost:9200',
3131
AWS_REGION: process.env.AWS_REGION || 'us-east-1', // AWS Region to be used if we use AWS ES
32-
API_VERSION: process.env.ES_API_VERSION || '6.7',
32+
API_VERSION: process.env.ES_API_VERSION || '6.8',
3333
ES_PROJECT_INDEX: process.env.ES_PROJECT_INDEX || 'projects',
3434
ES_TIMELINE_INDEX: process.env.ES_TIMELINE_INDEX || 'timelines',
3535
ES_METADATA_INDEX: process.env.ES_METADATA_INDEX || 'metadata',

migrations/elasticsearch_sync.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,13 @@ function getRequestBody (indexName) {
5656
description: {
5757
type: 'string'
5858
},
59-
filePath: {
59+
path: {
60+
type: 'string'
61+
},
62+
type: {
63+
type: 'string'
64+
},
65+
tags: {
6066
type: 'string'
6167
},
6268
id: {
@@ -227,8 +233,7 @@ function getRequestBody (indexName) {
227233
type: 'string'
228234
},
229235
handle: {
230-
type: 'string',
231-
index: 'not_analyzed'
236+
type: 'string'
232237
},
233238
id: {
234239
type: 'long'

package-lock.json

Lines changed: 792 additions & 811 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/common/helper.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,29 @@ async function getMemberDetailsByUserIds (userIds) {
167167
}
168168
}
169169

170+
/**
171+
* Populate member with user details
172+
*
173+
* @param {Object} member the member object
174+
* @returns {Object} the member object with details
175+
*/
176+
async function populateMemberWithUserDetails (member) {
177+
try {
178+
const membersDetails = await getMemberDetailsByUserIds([member.userId])
179+
const memberDetails = membersDetails[0]
180+
if (memberDetails) {
181+
logger.debug(`Successfully got user details for member (userId:${member.userId})`)
182+
return _.merge(member, _.pick(memberDetails, 'handle', 'firstName', 'lastName', 'email'))
183+
} else {
184+
throw new Error(`Didn't fine user details for member (userId:${member.userId})`)
185+
}
186+
} catch (err) {
187+
logger.error(`Cannot populate member (userId:${member.userId}) with user details.`)
188+
logger.debug(`Error during populating member (userId:${member.userId}) with user details`, err)
189+
return member
190+
}
191+
}
192+
170193
/**
171194
* Reusable method to generate a function which would remove invite from the project ES document.
172195
*
@@ -188,5 +211,6 @@ module.exports = {
188211
updateTimelineESPromise,
189212
updateMetadadaESPromise,
190213
getMemberDetailsByUserIds,
214+
populateMemberWithUserDetails,
191215
removeInvitePromise
192216
}

src/constants.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,18 @@ const MILESTONE_TEMPLATE_REFERENCES = {
6767
PRODUCT_TEMPLATE: 'productTemplate'
6868
}
6969

70+
const ATTACHMENT_TYPES = {
71+
'FILE': 'file',
72+
'LINK': 'link'
73+
}
74+
7075
module.exports = {
7176
RESOURCES,
7277
REGEX,
7378
PROJECT_STATUS,
7479
TIMELINE_REFERENCES,
7580
INVITE_STATUS,
7681
PROJECT_MEMBER_ROLE,
77-
MILESTONE_TEMPLATE_REFERENCES
82+
MILESTONE_TEMPLATE_REFERENCES,
83+
ATTACHMENT_TYPES
7884
}

src/services/ProcessorServiceAttachment.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const _ = require('lodash')
77

88
const logger = require('../common/logger')
99
const helper = require('../common/helper')
10+
const constants = require('../constants')
1011

1112
/**
1213
* create id schema
@@ -27,7 +28,8 @@ function updateSchema () {
2728
return createIdSchema().keys({
2829
title: Joi.string().required(),
2930
description: Joi.string().optional().allow(null).allow(''),
30-
allowedUsers: Joi.array().items(Joi.number().integer().positive()).allow(null).default(null)
31+
allowedUsers: Joi.array().items(Joi.number().integer().positive()).allow(null).default(null),
32+
tags: Joi.array().items(Joi.string()).optional().allow(null)
3133
})
3234
}
3335

@@ -39,8 +41,10 @@ function createSchema () {
3941
return updateSchema().keys({
4042
category: Joi.string().optional().allow(null).allow(''),
4143
size: Joi.number().optional().allow(null),
42-
contentType: Joi.string().required(),
43-
filePath: Joi.string().required()
44+
contentType: Joi.string().optional().allow(null).when('type', { is: constants.ATTACHMENT_TYPES.FILE, then: Joi.string().required() }),
45+
path: Joi.string().required(),
46+
type: Joi.string().valid(_.values(constants.ATTACHMENT_TYPES)),
47+
tags: Joi.array().items(Joi.string()).optional().allow(null)
4448
})
4549
}
4650

src/services/ProcessorServiceProject.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ function createSchema () {
9393
* @return {Promise} promise result
9494
*/
9595
async function create (message) {
96+
const member = await helper.populateMemberWithUserDetails(message.members[0])
97+
message.members = [member]
98+
9699
await client.create({
97100
index: config.get('esConfig.ES_PROJECT_INDEX'),
98101
type: config.get('esConfig.ES_TYPE'),

src/services/ProcessorServiceProjectMember.js

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,7 @@ async function create (message) {
5353
async function updateDocPromise (doc) {
5454
const members = _.isArray(doc._source.members) ? doc._source.members : []
5555
const existingMemberIndex = _.findIndex(members, p => p.id === message.id)// if member does not exists already
56-
let member = message
57-
58-
// try to populate member with user details
59-
// the code should move on, as it's not critical and is only used for searching at the moment
60-
try {
61-
const membersDetails = await helper.getMemberDetailsByUserIds([message.userId])
62-
const memberDetails = membersDetails[0]
63-
if (memberDetails) {
64-
member = _.merge(message, _.pick(memberDetails, 'handle', 'firstName', 'lastName', 'email'))
65-
logger.debug(`Successfully got user details for member (userId:${message.userId})`)
66-
} else {
67-
throw new Error(`Didn't find user details for member (userId:${message.userId})`)
68-
}
69-
} catch (err) {
70-
logger.error(`Cannot populate member (userId:${message.userId}) with user details.`)
71-
logger.debug(`Error during populating member (userId:${message.userId}) with user details`, err)
72-
}
56+
const member = await helper.populateMemberWithUserDetails(message)
7357

7458
if (existingMemberIndex === -1) {
7559
members.push(member)

src/services/ProcessorServiceProjectMemberInvite.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ function createSchema () {
2222
.email()
2323
.optional()
2424
.allow(null),
25-
hashEmail: Joi.string().optional().allow(null),
2625
status: Joi.any()
2726
.valid(_.values(INVITE_STATUS))
2827
.required()
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"topic":"project.action.create","originator":"project-api","timestamp":"2019-06-21T04:41:17.702Z","mime-type":"application/json","payload":{"resource":"attachment","createdAt":"2019-06-21T04:41:17.637Z","updatedAt":"2019-06-21T04:41:17.637Z","id":1,"projectId":1,"allowedUsers":null,"createdBy":40051333,"updatedBy":40051333,"title":"first attachment submission","size":null,"category":null,"description":null,"contentType":"application/png","deletedBy":null,"filePath":"projects/1/projects/asdasd.png"}}
1+
{"topic":"project.action.create","originator":"project-api","timestamp":"2019-06-21T04:41:17.702Z","mime-type":"application/json","payload":{"resource":"attachment","createdAt":"2019-06-21T04:41:17.637Z","updatedAt":"2019-06-21T04:41:17.637Z","id":1,"projectId":1,"allowedUsers":null,"createdBy":40051333,"updatedBy":40051333,"title":"first attachment submission","size":null,"category":null,"description":null,"contentType":"application/png","deletedBy":null,"path":"projects/1/projects/asdasd.png","type":"file","tags":["specification","design preview"]}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"topic":"project.action.update","originator":"project-api","timestamp":"2019-06-21T04:41:46.501Z","mime-type":"application/json","payload":{"resource":"attachment","title":"first attachment submission updated","description":"updated project attachment","allowedUsers":null,"updatedBy":40051333,"id":1,"projectId":1}}
1+
{"topic":"project.action.update","originator":"project-api","timestamp":"2019-06-21T04:41:46.501Z","mime-type":"application/json","payload":{"resource":"attachment","title":"first attachment submission updated","description":"updated project attachment","allowedUsers":null,"updatedBy":40051333,"id":1,"projectId":1,"tags":["specification","design preview","billing information"]}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"topic":"project.action.create","originator":"project-api","timestamp":"2019-06-21T04:58:12.671Z","mime-type":"application/json","payload":{"resource":"project.member.invite","createdAt":"2019-06-21T04:58:12.594Z","updatedAt":"2019-06-21T04:58:12.594Z","id":1,"projectId":1,"role":"customer","status":"pending","createdBy":40051334,"updatedBy":40051334,"userId":40051331,"email":"test@topcoder.com","hashEmail":"dummy_value","deletedAt":null,"deletedBy":null}}
1+
{"topic":"project.action.create","originator":"project-api","timestamp":"2019-06-21T04:58:12.671Z","mime-type":"application/json","payload":{"resource":"project.member.invite","createdAt":"2019-06-21T04:58:12.594Z","updatedAt":"2019-06-21T04:58:12.594Z","id":1,"projectId":1,"role":"customer","status":"pending","createdBy":40051334,"updatedBy":40051334,"userId":40051331,"email":"test@topcoder.com","deletedAt":null,"deletedBy":null}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"topic":"project.action.update","originator":"project-api","timestamp":"2019-06-21T04:59:38.562Z","mime-type":"application/json","payload":{"resource":"project.member.invite","status":"canceled","userId":40051331,"email":"test@topcoder.com","hashEmail":"dummy_value","id":1,"projectId":1}}
1+
{"topic":"project.action.update","originator":"project-api","timestamp":"2019-06-21T04:59:38.562Z","mime-type":"application/json","payload":{"resource":"project.member.invite","status":"canceled","userId":40051331,"email":"test@topcoder.com","id":1,"projectId":1}}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"topic":"project.action.update","originator":"project-api","timestamp":"2019-06-21T04:59:38.562Z","mime-type":"application/json","payload":{"resource":"project.member.invite","status":"pending","userId":40051331,"email":"test@topcoder.com","hashEmail":"dummy_value","id":1,"projectId":1}}
1+
{"topic":"project.action.update","originator":"project-api","timestamp":"2019-06-21T04:59:38.562Z","mime-type":"application/json","payload":{"resource":"project.member.invite","status":"pending","userId":40051331,"email":"test@topcoder.com","id":1,"projectId":1}}

0 commit comments

Comments
 (0)