Skip to content

Cf21 in Connect App #504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Mar 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/permissions/projectMember.delete.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ module.exports = freq => new Promise((resolve, reject) => {
// check if auth user has acecss to this project
const hasAccess = util.hasAdminRole(req)
|| (authMember && memberToBeRemoved && ([
PROJECT_MEMBER_ROLE.ACCOUNT_MANAGER,
PROJECT_MEMBER_ROLE.MANAGER,
PROJECT_MEMBER_ROLE.PROGRAM_MANAGER,
PROJECT_MEMBER_ROLE.PROJECT_MANAGER,
Expand Down
11 changes: 9 additions & 2 deletions src/routes/projects/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,14 @@ const SUPPORTED_FILTERS = [
'directProjectId',
];

const escapeEsKeyword = keyword => keyword.replace(/[+-=><!|(){}[&\]^"~*?:\\/]/g, '\\\\$&');
/**
* ES need to skip special chars else it is considered as RegEx or other ES query string syntax,
* see https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
*
* @param {String} keyword keyword being searched for
* @return {String} result after parsing
*/
const escapeEsKeyword = keyword => keyword.replace(/[+-=><!|(){}[&\]^"~*?:\\/]/g, '\\$&');

const buildEsFullTextQuery = (keyword, matchType, singleFieldName) => {
let should = [
Expand Down Expand Up @@ -426,7 +433,7 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {

if (!keyword) {
// Not a specific field search nor an exact phrase search, do a wildcard match
keyword = criteria.filters.keyword;
keyword = escapeEsKeyword(keywordCriterion);
matchType = MATCH_TYPE_WILDCARD;
}

Expand Down
142 changes: 137 additions & 5 deletions src/routes/projects/list.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ const data = [
type: 'generic',
billingAccountId: 1,
name: 'test1',
description: 'test project1',
description: 'test project1 abc/d',
status: 'active',
details: {
utm: {
Expand Down Expand Up @@ -160,7 +160,7 @@ const data = [
role: 'manager',
firstName: 'first',
lastName: 'last',
handle: 'manager_handle',
handle: 'MANAGER_HANDLE',
isPrimary: true,
createdBy: 1,
updatedBy: 1,
Expand Down Expand Up @@ -723,7 +723,7 @@ describe('LIST Project', () => {
});
});

it('should return all projects that match when filtering by customer handle', (done) => {
it('should return all projects that match when filtering by customer handle (lowercase)', (done) => {
request(server)
.get('/v5/projects/?customer=*tourist*')
.set({
Expand All @@ -746,7 +746,53 @@ describe('LIST Project', () => {
});
});

it('should return all projects that match when filtering by manager handle', (done) => {
it('should return all projects that match when filtering by customer handle (uppercase)', (done) => {
request(server)
.get('/v5/projects/?customer=*TOUR*')
.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('test1');
resJson[0].members.should.have.deep.property('[0].role', 'customer');
resJson[0].members[0].userId.should.equal(40051331);
done();
}
});
});

it('should return all projects that match when filtering by customer handle (mixed case)', (done) => {
request(server)
.get('/v5/projects/?customer=*tOURiS*')
.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('test1');
resJson[0].members.should.have.deep.property('[0].role', 'customer');
resJson[0].members[0].userId.should.equal(40051331);
done();
}
});
});

it('should return all projects that match when filtering by manager handle (lowercase)', (done) => {
request(server)
.get('/v5/projects/?manager=*_handle')
.set({
Expand All @@ -769,6 +815,52 @@ describe('LIST Project', () => {
});
});

it('should return all projects that match when filtering by manager handle (uppercase)', (done) => {
request(server)
.get('/v5/projects/?manager=MANAG*')
.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('test3');
resJson[0].members.should.have.deep.property('[0].role', 'manager');
resJson[0].members[0].userId.should.equal(40051334);
done();
}
});
});

it('should return all projects that match when filtering by manager handle (mixed case)', (done) => {
request(server)
.get('/v5/projects/?manager=*_HAndLe')
.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('test3');
resJson[0].members.should.have.deep.property('[0].role', 'manager');
resJson[0].members[0].userId.should.equal(40051334);
done();
}
});
});

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*')
Expand Down Expand Up @@ -1065,7 +1157,7 @@ describe('LIST Project', () => {
resJson.should.have.lengthOf(1);
resJson[0].should.have.property('description');
resJson[0].should.not.have.property('cancelReason');
resJson[0].description.should.be.eq('test project1');
resJson[0].description.should.be.eq('test project1 abc/d');
done();
}
});
Expand Down Expand Up @@ -1244,6 +1336,46 @@ describe('LIST Project', () => {
}
});
});

it('should find a project by quoted keyword with a special symbol in the name', (done) => {
request(server)
.get('/v5/projects/?keyword="abc/d"')
.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);
done();
}
});
});

it('should find a project by keyword with a special symbol in the name', (done) => {
request(server)
.get('/v5/projects/?keyword=abc/d')
.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);
done();
}
});
});
});
});
});
1 change: 0 additions & 1 deletion src/utils/es-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ MAPPINGS[ES_PROJECT_INDEX] = {
},
handle: {
type: 'string',
index: 'not_analyzed',
},
id: {
type: 'long',
Expand Down