Skip to content

CF20 #451

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 7 commits into from
Jan 27, 2020
Merged

CF20 #451

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
248 changes: 247 additions & 1 deletion docs/Project API.postman_collection.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"info": {
"_postman_id": "2e0a1b99-3cb9-4c77-a562-7e6fe4956358",
"_postman_id": "49981b6e-f611-4016-999e-737ef4103435",
"name": "Project API",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
Expand Down Expand Up @@ -5837,6 +5837,252 @@
],
"protocolProfileBehavior": {}
},
{
"name": "Org Config",
"item": [
{
"name": "Create org config",
"event": [
{
"listen": "test",
"script": {
"id": "fbc45946-a3f2-433a-8ec5-0af82b69d2bd",
"exec": [
"pm.test(\"Status code is 201\", function () {",
" pm.response.to.have.status(201);",
" console.log(pm.response.json())",
" pm.environment.set(\"orgStrId\", pm.response.json().orgId);",
" pm.environment.set(\"orgConfigName\", pm.response.json().configName);",
" pm.environment.set(\"orgId\", pm.response.json().id);",
"});"
],
"type": "text/javascript"
}
}
],
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{ \n\t\"orgId\": \"testStr Id\",\n \"configName\": \"project_catefory_url\",\n \"configValue\": \"http://localhost/url\"\n}"
},
"url": {
"raw": "{{api-url}}/projects/metadata/orgConfig",
"host": [
"{{api-url}}"
],
"path": [
"projects",
"metadata",
"orgConfig"
]
}
},
"response": []
},
{
"name": "List org configs without orgId",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"url": {
"raw": "{{api-url}}/projects/metadata/orgConfig",
"host": [
"{{api-url}}"
],
"path": [
"projects",
"metadata",
"orgConfig"
]
}
},
"response": []
},
{
"name": "List org configs with only orgId",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"url": {
"raw": "{{api-url}}/projects/metadata/orgConfig?orgId={{orgStrId}}",
"host": [
"{{api-url}}"
],
"path": [
"projects",
"metadata",
"orgConfig"
],
"query": [
{
"key": "orgId",
"value": "{{orgStrId}}",
"description": "orgId can be array with ',', 'id1,id2'"
}
]
}
},
"response": []
},
{
"name": "List org configs with orgId and configName",
"request": {
"method": "GET",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"url": {
"raw": "{{api-url}}/projects/metadata/orgConfig?orgId={{orgStrId}}&configName={{orgConfigName}}",
"host": [
"{{api-url}}"
],
"path": [
"projects",
"metadata",
"orgConfig"
],
"query": [
{
"key": "orgId",
"value": "{{orgStrId}}",
"description": "orgId can be array with ',', 'id1,id2'"
},
{
"key": "configName",
"value": "{{orgConfigName}}"
}
]
}
},
"response": []
},
{
"name": "Delete org config",
"request": {
"method": "DELETE",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": ""
},
"url": {
"raw": "{{api-url}}/projects/metadata/orgConfig/{{orgId}}",
"host": [
"{{api-url}}"
],
"path": [
"projects",
"metadata",
"orgConfig",
"{{orgId}}"
]
}
},
"response": []
},
{
"name": "Update org config",
"request": {
"method": "PATCH",
"header": [
{
"key": "Content-Type",
"value": "application/json"
},
{
"key": "Authorization",
"value": "Bearer {{jwt-token}}"
}
],
"body": {
"mode": "raw",
"raw": "{ \n\t\"orgId\": \"another orgId\",\n \"configName\": \"project_catefory_url\",\n \"configValue\": \"http://localhost/url\"\n}"
},
"url": {
"raw": "{{api-url}}/projects/metadata/orgConfig/{{orgId}}",
"host": [
"{{api-url}}"
],
"path": [
"projects",
"metadata",
"orgConfig",
"{{orgId}}"
]
}
},
"response": []
}
],
"event": [
{
"listen": "prerequest",
"script": {
"id": "2e274cc9-22e6-4dd2-9eee-c4f1fd98253d",
"type": "text/javascript",
"exec": [
""
]
}
},
{
"listen": "test",
"script": {
"id": "9d171dbf-2a50-4483-b172-ce240ac09413",
"type": "text/javascript",
"exec": [
""
]
}
}
],
"protocolProfileBehavior": {}
},
{
"name": "Product Category",
"item": [
Expand Down
6 changes: 3 additions & 3 deletions src/routes/projectMembers/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ module.exports = [
targetRole = _.get(req, 'body.role');

if (PROJECT_MEMBER_ROLE.MANAGER === targetRole &&
!util.hasRoles(req, [USER_ROLE.MANAGER])) {
const err = new Error(`Only manager is able to join as ${targetRole}`);
!util.hasRoles(req, [USER_ROLE.TOPCODER_ADMIN, USER_ROLE.CONNECT_ADMIN, USER_ROLE.MANAGER])) {
const err = new Error(`Only admin or manager is able to join as ${targetRole}`);
err.status = 401;
return next(err);
}
Expand Down Expand Up @@ -96,7 +96,7 @@ module.exports = [
err.status = 401;
return next(err);
}
} else if (util.hasRoles(req, [USER_ROLE.MANAGER, USER_ROLE.CONNECT_ADMIN])) {
} else if (util.hasRoles(req, [USER_ROLE.MANAGER, USER_ROLE.CONNECT_ADMIN, USER_ROLE.TOPCODER_ADMIN])) {
targetRole = PROJECT_MEMBER_ROLE.MANAGER;
} else if (util.hasRoles(req, [
USER_ROLE.TOPCODER_ACCOUNT_MANAGER,
Expand Down
72 changes: 71 additions & 1 deletion src/routes/projectMembers/create.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,14 @@ import util from '../../util';
import server from '../../app';
import testUtil from '../../tests/util';
import busApi from '../../services/busApi';
import { USER_ROLE, BUS_API_EVENT, RESOURCES, CONNECT_NOTIFICATION_EVENT, INVITE_STATUS } from '../../constants';
import {
USER_ROLE,
BUS_API_EVENT,
RESOURCES,
CONNECT_NOTIFICATION_EVENT,
INVITE_STATUS,
PROJECT_MEMBER_ROLE,
} from '../../constants';

const should = chai.should();

Expand Down Expand Up @@ -201,6 +208,69 @@ describe('Project Members create', () => {
});
});

it('should return 201 and register admin as manager', (done) => {
const mockHttpClient = _.merge(testUtil.mockHttpClient, {
get: () => Promise.resolve({
status: 200,
data: {
id: 'requesterId',
version: 'v3',
result: {
success: true,
status: 200,
content: [{
roleName: USER_ROLE.TOPCODER_ADMIN,
}],
},
},
}),
});
sandbox.stub(util, 'getHttpClient', () => mockHttpClient);
request(server)
.post(`/v5/projects/${project1.id}/members/`)
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.expect('Content-Type', /json/)
.expect(201)
.end((err, res) => {
if (err) {
done(err);
} else {
const resJson = res.body;
should.exist(resJson);
resJson.role.should.equal('manager');
resJson.isPrimary.should.be.truthy;
resJson.projectId.should.equal(project1.id);
resJson.userId.should.equal(40051333);
server.services.pubsub.publish.calledWith('project.member.added').should.be.true;
done();
}
});
});

it('should return 401 if register admin as role other than manager (copilot) ', (done) => {
request(server)
.post(`/v5/projects/${project1.id}/members/`)
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.send({ role: PROJECT_MEMBER_ROLE.COPILOT })
.expect('Content-Type', /json/)
.expect(401, done);
});

it('should return 401 if register admin as role other than manager (project manager) ', (done) => {
request(server)
.post(`/v5/projects/${project1.id}/members/`)
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.send({ role: PROJECT_MEMBER_ROLE.PROJECT_MANAGER })
.expect('Content-Type', /json/)
.expect(401, done);
});

describe('Bus api', () => {
let createEventSpy;

Expand Down
4 changes: 2 additions & 2 deletions src/routes/projects/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -333,13 +333,13 @@ const parseElasticSearchCriteria = (criteria, fields, order) => {
if (_.has(criteria, 'filters.customer')) {
mustQuery = _.concat(mustQuery, setFilter('customer',
criteria.filters.customer,
['members.firstName', 'members.lastName']));
['members.firstName', 'members.lastName', 'members.handle']));
}

if (_.has(criteria, 'filters.manager')) {
mustQuery = _.concat(mustQuery, setFilter('manager',
criteria.filters.manager,
['members.firstName', 'members.lastName']));
['members.firstName', 'members.lastName', 'members.handle']));
}

if (_.has(criteria, 'filters.userId') || _.has(criteria, 'filters.email')) {
Expand Down
Loading