Skip to content

Commit 2fd32ce

Browse files
authored
Merge pull request #479 from topcoder-platform/revert-478-revert-470-3496_search_by_manager
#3496 Includes non-customer roles when searching projects by manager.
2 parents cefa5a9 + 9021ce0 commit 2fd32ce

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

src/constants.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,16 @@ export const PROJECT_MEMBER_MANAGER_ROLES = [
4242
PROJECT_MEMBER_ROLE.SOLUTION_ARCHITECT,
4343
];
4444

45+
export const PROJECT_MEMBER_NON_CUSTOMER_ROLES = [
46+
PROJECT_MEMBER_ROLE.MANAGER,
47+
PROJECT_MEMBER_ROLE.COPILOT,
48+
PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER,
49+
PROJECT_MEMBER_ROLE.ACCOUNT_EXECUTIVE,
50+
PROJECT_MEMBER_ROLE.PROJECT_MANAGER,
51+
PROJECT_MEMBER_ROLE.PROGRAM_MANAGER,
52+
PROJECT_MEMBER_ROLE.SOLUTION_ARCHITECT,
53+
];
54+
4555
export const USER_ROLE = {
4656
TOPCODER_ADMIN: 'administrator',
4757
MANAGER: 'Connect Manager',

src/routes/projects/list.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import _ from 'lodash';
55
import config from 'config';
66

77
import models from '../../models';
8-
import { MANAGER_ROLES, INVITE_STATUS } from '../../constants';
8+
import { MANAGER_ROLES, INVITE_STATUS, PROJECT_MEMBER_NON_CUSTOMER_ROLES } from '../../constants';
99
import util from '../../util';
1010

1111
const ES_PROJECT_INDEX = config.get('elasticsearchConfig.indexName');
@@ -228,13 +228,14 @@ const buildEsQueryWithFilter = (value, keyword, matchType, fieldName) => {
228228
}
229229

230230
if (value === 'customer' || value === 'manager') {
231+
const roles = value === 'customer' ? [value] : PROJECT_MEMBER_NON_CUSTOMER_ROLES;
231232
should = _.concat(should, {
232233
nested: {
233234
path: 'members',
234235
query: {
235236
bool: {
236237
must: [
237-
{ match: { 'members.role': value } },
238+
{ terms: { 'members.role': roles } },
238239
{
239240
query_string: {
240241
query: keyword,

src/routes/projects/list.spec.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ const data = [
9393
userId: 40051332,
9494
projectId: 2,
9595
role: 'copilot',
96+
firstName: 'copi',
97+
lastName: 'lott',
98+
handle: 'tolipoc',
9699
isPrimary: true,
97100
createdBy: 1,
98101
updatedBy: 1,
@@ -207,6 +210,9 @@ describe('LIST Project', () => {
207210
userId: 40051332,
208211
projectId: project2.id,
209212
role: 'copilot',
213+
firstName: 'copi',
214+
lastName: 'lott',
215+
handle: 'tolipoc',
210216
isPrimary: true,
211217
createdBy: 1,
212218
updatedBy: 1,
@@ -729,6 +735,29 @@ describe('LIST Project', () => {
729735
});
730736
});
731737

738+
it('should return all projects that match when filtering by manager, searching on any non-customer role', (done) => {
739+
request(server)
740+
.get('/v5/projects/?manager=copi*')
741+
.set({
742+
Authorization: `Bearer ${testUtil.jwts.admin}`,
743+
})
744+
.expect('Content-Type', /json/)
745+
.expect(200)
746+
.end((err, res) => {
747+
if (err) {
748+
done(err);
749+
} else {
750+
const resJson = res.body;
751+
should.exist(resJson);
752+
resJson.should.have.lengthOf(1);
753+
resJson[0].name.should.equal('test2');
754+
resJson[0].members.should.have.deep.property('[0].role', 'copilot');
755+
resJson[0].members[0].userId.should.equal(40051332);
756+
done();
757+
}
758+
});
759+
});
760+
732761
it('should return list of projects ordered ascending by lastActivityAt when sort column is "lastActivityAt"', (done) => {
733762
request(server)
734763
.get('/v5/projects/?sort=lastActivityAt')

0 commit comments

Comments
 (0)