Skip to content

Commit 8ad7019

Browse files
author
vikasrohit
authored
Merge pull request #433 from xxcxy/feature/only-list-project-with-pending-invites
[HOTFIX] [PROD] Copilots with "requested" invite shouldn't see projects in the list
2 parents 4b1bf7c + 1f25df1 commit 8ad7019

File tree

2 files changed

+86
-7
lines changed

2 files changed

+86
-7
lines changed

src/routes/projects/list.js

Lines changed: 29 additions & 7 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 } from '../../constants';
8+
import { MANAGER_ROLES, INVITE_STATUS } from '../../constants';
99
import util from '../../util';
1010

1111
const ES_PROJECT_INDEX = config.get('elasticsearchConfig.indexName');
@@ -127,9 +127,20 @@ const buildEsShouldQuery = (userId, email) => {
127127
nested: {
128128
path: 'invites',
129129
query: {
130-
query_string: {
131-
query: userId,
132-
fields: ['invites.userId'],
130+
bool: {
131+
must: [
132+
{
133+
query_string: {
134+
query: userId,
135+
fields: ['invites.userId'],
136+
},
137+
}, {
138+
query_string: {
139+
query: INVITE_STATUS.PENDING,
140+
fields: ['invites.status'],
141+
},
142+
},
143+
],
133144
},
134145
},
135146
},
@@ -141,9 +152,20 @@ const buildEsShouldQuery = (userId, email) => {
141152
nested: {
142153
path: 'invites',
143154
query: {
144-
query_string: {
145-
query: email,
146-
fields: ['invites.email'],
155+
bool: {
156+
must: [
157+
{
158+
query_string: {
159+
query: email,
160+
fields: ['invites.email'],
161+
},
162+
}, {
163+
query_string: {
164+
query: INVITE_STATUS.PENDING,
165+
fields: ['invites.status'],
166+
},
167+
},
168+
],
147169
},
148170
},
149171
},

src/routes/projects/list.spec.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,14 @@ const data = [
5454
updatedBy: 1,
5555
},
5656
],
57+
invites: [
58+
{
59+
id: 1,
60+
userId: 40051335,
61+
email: 'test@topcoder.com',
62+
status: 'pending',
63+
},
64+
],
5765
attachments: [
5866
{
5967
id: 1,
@@ -90,6 +98,14 @@ const data = [
9098
updatedBy: 1,
9199
},
92100
],
101+
invites: [
102+
{
103+
id: 1,
104+
userId: 40051335,
105+
email: 'test@topcoder.com',
106+
status: 'requested',
107+
},
108+
],
93109
},
94110
{
95111
id: 3,
@@ -836,5 +852,46 @@ describe('LIST Project', () => {
836852
});
837853
});
838854
});
855+
describe('GET All /projects/ for non-admins users who are invited', () => {
856+
it('should return projects where a non-admin user has an invitation in pending status', (done) => {
857+
request(server)
858+
.get(`/v5/projects/?id=${project1.id}`)
859+
.set({
860+
Authorization: `Bearer ${testUtil.jwts.member2}`,
861+
})
862+
.expect('Content-Type', /json/)
863+
.expect(200)
864+
.end((err, res) => {
865+
if (err) {
866+
done(err);
867+
} else {
868+
const resJson = res.body;
869+
should.exist(resJson);
870+
resJson.should.have.lengthOf(1);
871+
resJson[0].name.should.equal('test1');
872+
done();
873+
}
874+
});
875+
});
876+
it('should not return projects where a non-admin user has an invitation in requested status', (done) => {
877+
request(server)
878+
.get(`/v5/projects/?id=${project2.id}`)
879+
.set({
880+
Authorization: `Bearer ${testUtil.jwts.member2}`,
881+
})
882+
.expect('Content-Type', /json/)
883+
.expect(200)
884+
.end((err, res) => {
885+
if (err) {
886+
done(err);
887+
} else {
888+
const resJson = res.body;
889+
should.exist(resJson);
890+
resJson.should.have.lengthOf(0);
891+
done();
892+
}
893+
});
894+
});
895+
});
839896
});
840897
});

0 commit comments

Comments
 (0)