From a216c680a6eac2045ecb5e4267336d54a7f0b913 Mon Sep 17 00:00:00 2001 From: gets0ul Date: Tue, 11 Feb 2020 20:46:32 +0700 Subject: [PATCH] Includes non-customer roles when searching projects by manager. --- src/constants.js | 10 ++++++++++ src/routes/projects/list.js | 5 +++-- src/routes/projects/list.spec.js | 29 +++++++++++++++++++++++++++++ 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/src/constants.js b/src/constants.js index a31c965b..7385fe04 100644 --- a/src/constants.js +++ b/src/constants.js @@ -42,6 +42,16 @@ export const PROJECT_MEMBER_MANAGER_ROLES = [ PROJECT_MEMBER_ROLE.SOLUTION_ARCHITECT, ]; +export const PROJECT_MEMBER_NON_CUSTOMER_ROLES = [ + PROJECT_MEMBER_ROLE.MANAGER, + PROJECT_MEMBER_ROLE.COPILOT, + PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER, + PROJECT_MEMBER_ROLE.ACCOUNT_EXECUTIVE, + PROJECT_MEMBER_ROLE.PROJECT_MANAGER, + PROJECT_MEMBER_ROLE.PROGRAM_MANAGER, + PROJECT_MEMBER_ROLE.SOLUTION_ARCHITECT, +]; + export const USER_ROLE = { TOPCODER_ADMIN: 'administrator', MANAGER: 'Connect Manager', diff --git a/src/routes/projects/list.js b/src/routes/projects/list.js index 91119da3..fc58c03b 100755 --- a/src/routes/projects/list.js +++ b/src/routes/projects/list.js @@ -5,7 +5,7 @@ import _ from 'lodash'; import config from 'config'; import models from '../../models'; -import { MANAGER_ROLES, INVITE_STATUS } from '../../constants'; +import { MANAGER_ROLES, INVITE_STATUS, PROJECT_MEMBER_NON_CUSTOMER_ROLES } from '../../constants'; import util from '../../util'; const ES_PROJECT_INDEX = config.get('elasticsearchConfig.indexName'); @@ -228,13 +228,14 @@ const buildEsQueryWithFilter = (value, keyword, matchType, fieldName) => { } if (value === 'customer' || value === 'manager') { + const roles = value === 'customer' ? [value] : PROJECT_MEMBER_NON_CUSTOMER_ROLES; should = _.concat(should, { nested: { path: 'members', query: { bool: { must: [ - { match: { 'members.role': value } }, + { terms: { 'members.role': roles } }, { query_string: { query: keyword, diff --git a/src/routes/projects/list.spec.js b/src/routes/projects/list.spec.js index 0dbe713e..0cbb4fc6 100644 --- a/src/routes/projects/list.spec.js +++ b/src/routes/projects/list.spec.js @@ -93,6 +93,9 @@ const data = [ userId: 40051332, projectId: 2, role: 'copilot', + firstName: 'copi', + lastName: 'lott', + handle: 'tolipoc', isPrimary: true, createdBy: 1, updatedBy: 1, @@ -207,6 +210,9 @@ describe('LIST Project', () => { userId: 40051332, projectId: project2.id, role: 'copilot', + firstName: 'copi', + lastName: 'lott', + handle: 'tolipoc', isPrimary: true, createdBy: 1, updatedBy: 1, @@ -729,6 +735,29 @@ describe('LIST Project', () => { }); }); + it('should return all projects that match when filtering by manager, searching on any non-customer role', (done) => { + request(server) + .get('/v5/projects/?manager=copi*') + .set({ + Authorization: `Bearer ${testUtil.jwts.admin}`, + }) + .expect('Content-Type', /json/) + .expect(200) + .end((err, res) => { + if (err) { + done(err); + } else { + const resJson = res.body; + should.exist(resJson); + resJson.should.have.lengthOf(1); + resJson[0].name.should.equal('test2'); + resJson[0].members.should.have.deep.property('[0].role', 'copilot'); + resJson[0].members[0].userId.should.equal(40051332); + done(); + } + }); + }); + it('should return list of projects ordered ascending by lastActivityAt when sort column is "lastActivityAt"', (done) => { request(server) .get('/v5/projects/?sort=lastActivityAt')