Skip to content

Fix for issue-381 #382

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 3 commits into from
Oct 3, 2019
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
10 changes: 9 additions & 1 deletion src/routes/milestones/update.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Sequelize from 'sequelize';
import { middleware as tcMiddleware } from 'tc-core-library-js';
import util from '../../util';
import validateTimeline from '../../middlewares/validateTimeline';
import { EVENT, MILESTONE_STATUS } from '../../constants';
import { EVENT, MILESTONE_STATUS, ADMIN_ROLES } from '../../constants';
import models from '../../models';

const permissions = tcMiddleware.permissions;
Expand Down Expand Up @@ -185,6 +185,14 @@ module.exports = [
}
}

if (entityToUpdate.completionDate || entityToUpdate.actualStartDate) {
if (!util.hasPermission({ topcoderRoles: ADMIN_ROLES }, req.authUser)) {
const apiErr = new Error('You are not authorised to perform this action');
apiErr.status = 403;
return Promise.reject(apiErr);
}
}

if (entityToUpdate.completionDate && entityToUpdate.completionDate < milestone.startDate) {
const apiErr = new Error('The milestone completionDate should be greater or equal than the startDate.');
apiErr.status = 422;
Expand Down
55 changes: 52 additions & 3 deletions src/routes/milestones/update.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ describe('UPDATE Milestone', () => {
param: {
name: 'Milestone 1-updated',
duration: 3,
completionDate: '2018-05-16T00:00:00.000Z',
description: 'description-updated',
status: 'draft',
type: 'type1-updated',
Expand Down Expand Up @@ -302,6 +301,30 @@ describe('UPDATE Milestone', () => {
.expect(403, done);
});

it('should return 403 for non-admin member updating the completionDate', (done) => {
const newBody = _.cloneDeep(body);
newBody.param.completionDate = '2019-01-16T00:00:00.000Z';
request(server)
.patch('/v4/timelines/1/milestones/1')
.set({
Authorization: `Bearer ${testUtil.jwts.manager}`,
})
.send(newBody)
.expect(403, done);
});

it('should return 403 for non-admin member updating the actualStartDate', (done) => {
const newBody = _.cloneDeep(body);
newBody.param.actualStartDate = '2018-05-15T00:00:00.000Z';
request(server)
.patch('/v4/timelines/1/milestones/1')
.set({
Authorization: `Bearer ${testUtil.jwts.manager}`,
})
.send(newBody)
.expect(403, done);
});

it('should return 404 for non-existed timeline', (done) => {
request(server)
.patch('/v4/timelines/1234/milestones/1')
Expand Down Expand Up @@ -490,20 +513,22 @@ describe('UPDATE Milestone', () => {
});

it('should return 200 for admin', (done) => {
const newBody = _.cloneDeep(body);
newBody.param.completionDate = '2018-05-15T00:00:00.000Z';
request(server)
.patch('/v4/timelines/1/milestones/1')
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.send(body)
.send(newBody)
.expect(200)
.end((err, res) => {
const resJson = res.body.result.content;
should.exist(resJson.id);
resJson.name.should.be.eql(body.param.name);
resJson.description.should.be.eql(body.param.description);
resJson.duration.should.be.eql(body.param.duration);
resJson.completionDate.should.be.eql(body.param.completionDate);
resJson.completionDate.should.be.eql(newBody.param.completionDate);
resJson.status.should.be.eql(body.param.status);
resJson.type.should.be.eql(body.param.type);
resJson.details.should.be.eql({
Expand Down Expand Up @@ -1061,6 +1086,30 @@ describe('UPDATE Milestone', () => {
.end(done);
});

it('should return 200 for admin updating the completionDate', (done) => {
const newBody = _.cloneDeep(body);
newBody.param.completionDate = '2018-05-16T00:00:00.000Z';
request(server)
.patch('/v4/timelines/1/milestones/1')
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.send(newBody)
.expect(200, done);
});

it('should return 200 for admin updating the actualStartDate', (done) => {
const newBody = _.cloneDeep(body);
newBody.param.actualStartDate = '2018-05-15T00:00:00.000Z';
request(server)
.patch('/v4/timelines/1/milestones/1')
.set({
Authorization: `Bearer ${testUtil.jwts.admin}`,
})
.send(newBody)
.expect(200, done);
});

it('should return 200 for connect manager', (done) => {
request(server)
.patch('/v4/timelines/1/milestones/1')
Expand Down