Skip to content

Commit 3e97ee4

Browse files
committed
integration changes
1 parent 13f5dfd commit 3e97ee4

File tree

4 files changed

+24
-6
lines changed

4 files changed

+24
-6
lines changed

local/mock-services/server.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ server.get('/v3/members/_search', (req, res) => {
4444
return ret;
4545
});
4646
const userIds = _.map(criteria, 'userId');
47+
const handles = _.map(criteria, 'handle');
4748
const cloned = _.cloneDeep(members);
4849
const response = {
4950
id: 'res1',
@@ -59,6 +60,12 @@ server.get('/v3/members/_search', (req, res) => {
5960
found = _.pick(found, fields);
6061
}
6162
return found;
63+
} else if (_.indexOf(handles, single.result.content.handle) > -1) {
64+
let found = single.result.content;
65+
if (fields.length > 0) {
66+
found = _.pick(found, fields);
67+
}
68+
return found;
6269
}
6370
return null;
6471
}).filter(_.identity);

src/models/projectMemberInvite.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ module.exports = function defineProjectMemberInvite(sequelize, DataTypes) {
5656
});
5757
},
5858
getPendingInviteByEmailOrUserId(projectId, email, userId) {
59-
const where = { status: INVITE_STATUS.PENDING };
59+
const where = { projectId, status: INVITE_STATUS.PENDING };
6060

6161
if (email && userId) {
6262
_.assign(where, { $or: [{ email: { $eq: email } }, { userId: { $eq: userId } }] });

src/routes/projectMembers/update.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const updateProjectMemberValdiations = {
1717
param: Joi.object().keys({
1818
isPrimary: Joi.boolean(),
1919
role: Joi.any().valid(PROJECT_MEMBER_ROLE.CUSTOMER, PROJECT_MEMBER_ROLE.MANAGER,
20-
PROJECT_MEMBER_ROLE.COPILOT).required(),
20+
PROJECT_MEMBER_ROLE.COPILOT, PROJECT_MEMBER_ROLE.OBSERVER).required(),
2121
}),
2222
},
2323
};

src/routes/projects/list.js

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ const PROJECT_MEMBER_ATTRIBUTES = _.without(
3030
_.keys(models.ProjectMember.rawAttributes),
3131
'deletedAt',
3232
);
33+
const PROJECT_MEMBER_INVITE_ATTRIBUTES = _.without(
34+
_.keys(models.ProjectMemberInvite.rawAttributes),
35+
'deletedAt'
36+
);
3337
const PROJECT_ATTACHMENT_ATTRIBUTES = _.without(
3438
_.keys(models.ProjectAttachment.rawAttributes),
3539
'deletedAt',
@@ -126,6 +130,10 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
126130
const memberFields = _.get(fields, 'project_members');
127131
sourceInclude = sourceInclude.concat(_.map(memberFields, single => `members.${single}`));
128132
}
133+
if (_.get(fields, 'project_member_invites', null)) {
134+
const memberFields = _.get(fields, 'project_member_invites');
135+
sourceInclude = sourceInclude.concat(_.map(memberFields, single => `invites.${single}`));
136+
}
129137
if (_.get(fields, 'project_phases', null)) {
130138
const phaseFields = _.get(fields, 'project_phases');
131139
sourceInclude = sourceInclude.concat(_.map(phaseFields, single => `phases.${single}`));
@@ -249,6 +257,7 @@ const retrieveProjects = (req, criteria, sort, ffields) => {
249257
fields = util.parseFields(fields, {
250258
projects: PROJECT_ATTRIBUTES,
251259
project_members: PROJECT_MEMBER_ATTRIBUTES,
260+
project_member_invites: PROJECT_MEMBER_INVITE_ATTRIBUTES,
252261
project_phases: PROJECT_PHASE_ATTRIBUTES,
253262
project_phases_products: PROJECT_PHASE_PRODUCTS_ATTRIBUTES,
254263
attachments: PROJECT_ATTACHMENT_ATTRIBUTES,
@@ -321,16 +330,18 @@ module.exports = [
321330
const getProjectIds = !memberOnly && util.hasRole(req, USER_ROLE.COPILOT) ?
322331
models.Project.getProjectIdsForCopilot(req.authUser.userId) :
323332
models.ProjectMember.getProjectIdsForUser(req.authUser.userId);
333+
324334
return getProjectIds
325335
.then((accessibleProjectIds) => {
326-
let allowedProjectIds = accessibleProjectIds;
336+
const allowedProjectIds = accessibleProjectIds;
327337
// get projects with pending invite for current user
328338
const invites = models.ProjectMemberInvite.getProjectInvitesForUser(
329339
req.authUser.email,
330340
req.authUser.userId);
331-
if (invites) {
332-
allowedProjectIds = _.union(allowedProjectIds, invites);
333-
}
341+
342+
return invites.then((ids => _.union(allowedProjectIds, ids)));
343+
})
344+
.then((allowedProjectIds) => {
334345
// filter based on accessible
335346
if (_.get(criteria.filters, 'id', null)) {
336347
criteria.filters.id.$in = _.intersection(

0 commit comments

Comments
 (0)