Skip to content

Commit 275d8da

Browse files
authored
Merge pull request #490 from yoution/issue-488
#488 Project List endpoint returns member email for some projects
2 parents 053ce48 + 8080019 commit 275d8da

File tree

5 files changed

+668
-19
lines changed

5 files changed

+668
-19
lines changed

src/routes/projects/get.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,18 @@ const ES_PROJECT_TYPE = config.get('elasticsearchConfig.docType');
2222
// var permissions = require('tc-core-library-js').middleware.permissions
2323
const permissions = tcMiddleware.permissions;
2424
const PROJECT_ATTRIBUTES = _.without(_.keys(models.Project.rawAttributes), 'utm', 'deletedAt');
25-
const PROJECT_MEMBER_ATTRIBUTES = _.without(_.keys(models.ProjectMember.rawAttributes), 'deletedAt');
25+
const PROJECT_MEMBER_ATTRIBUTES = _.concat(_.without(_.keys(models.ProjectMember.rawAttributes), 'deletedAt'),
26+
['firstName', 'lastName', 'handle', 'email']);
2627
const PROJECT_MEMBER_INVITE_ATTRIBUTES = _.without(_.keys(models.ProjectMemberInvite.rawAttributes), 'deletedAt');
2728
const PROJECT_ATTACHMENT_ATTRIBUTES = _.without(_.keys(models.ProjectAttachment.rawAttributes), 'deletedAt');
29+
const PROJECT_PHASE_ATTRIBUTES = _.without(
30+
_.keys(models.ProjectPhase.rawAttributes),
31+
'deletedAt',
32+
);
33+
const PROJECT_PHASE_PRODUCTS_ATTRIBUTES = _.without(
34+
_.keys(models.PhaseProduct.rawAttributes),
35+
'deletedAt',
36+
);
2837

2938
/**
3039
* Parse the ES search criteria and prepare search request body
@@ -52,13 +61,21 @@ const parseElasticSearchCriteria = (projectId, fields) => {
5261
sourceInclude = sourceInclude.concat(_.map(memberFields, single => `invites.${single}`));
5362
}
5463

64+
if (_.get(fields, 'project_phases', null)) {
65+
const phaseFields = _.get(fields, 'project_phases');
66+
sourceInclude = sourceInclude.concat(_.map(phaseFields, single => `phases.${single}`));
67+
}
68+
if (_.get(fields, 'project_phases_products', null)) {
69+
const phaseFields = _.get(fields, 'project_phases_products');
70+
sourceInclude = sourceInclude.concat(_.map(phaseFields, single => `phases.products.${single}`));
71+
}
5572
if (_.get(fields, 'attachments', null)) {
5673
const attachmentFields = _.get(fields, 'attachments');
5774
sourceInclude = sourceInclude.concat(_.map(attachmentFields, single => `attachments.${single}`));
5875
}
5976

6077
if (sourceInclude) {
61-
searchCriteria._sourceInclude = sourceInclude; // eslint-disable-line no-underscore-dangle
78+
searchCriteria._sourceIncludes = sourceInclude; // eslint-disable-line no-underscore-dangle
6279
}
6380

6481

@@ -87,9 +104,14 @@ const retrieveProjectFromES = (projectId, req) => {
87104
projects: PROJECT_ATTRIBUTES,
88105
project_members: PROJECT_MEMBER_ATTRIBUTES,
89106
project_member_invites: PROJECT_MEMBER_INVITE_ATTRIBUTES,
107+
project_phases: PROJECT_PHASE_ATTRIBUTES,
108+
project_phases_products: PROJECT_PHASE_PRODUCTS_ATTRIBUTES,
90109
attachments: PROJECT_ATTACHMENT_ATTRIBUTES,
91110
});
92111

112+
// if user is not admin, ignore email field for project_members
113+
fields = util.ignoreEmailField(req, fields);
114+
93115
const searchCriteria = parseElasticSearchCriteria(projectId, fields) || {};
94116
return new Promise((accept, reject) => {
95117
const es = util.getElasticSearchClient();
@@ -108,6 +130,7 @@ const retrieveProjectFromDB = (projectId, req) => {
108130
projects: PROJECT_ATTRIBUTES,
109131
project_members: PROJECT_MEMBER_ATTRIBUTES,
110132
});
133+
111134
return models.Project
112135
.findOne({
113136
where: { id: projectId },

0 commit comments

Comments
 (0)