Skip to content

Commit 22d6f33

Browse files
committed
customize error message for copilots
1 parent 4f5c91d commit 22d6f33

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/permissions/project.view.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import _ from 'lodash';
33
import util from '../util';
44
import models from '../models';
5-
import { USER_ROLE } from '../constants';
5+
import { USER_ROLE, PROJECT_STATUS } from '../constants';
66

77
/**
88
* Super admin, Topcoder Managers are allowed to view any projects
@@ -37,8 +37,30 @@ module.exports = freq => new Promise((resolve, reject) => {
3737
})
3838
.then((hasAccess) => {
3939
if (!hasAccess) {
40+
let errorMessage = 'You do not have permissions to perform this action';
41+
// customize error message for copilots
42+
if (util.hasRole(freq, USER_ROLE.COPILOT)) {
43+
if (_.findIndex(freq.context.currentProjectMembers, m => m.role === USER_ROLE.COPILOT) >= 0) {
44+
errorMessage = 'Project is already claimed by another copilot';
45+
} else {
46+
models.Project
47+
.find({
48+
where: { id: projectId },
49+
attributes: ['status'],
50+
raw: true,
51+
})
52+
.then((project) => {
53+
if (!project || [PROJECT_STATUS.DRAFT, PROJECT_STATUS.IN_REVIEW].indexOf(project.status) >= 0) {
54+
errorMessage = 'Project is not yet available to copilots';
55+
} else {
56+
// project status is 'active' or higher so it's not available to copilots
57+
errorMessage = 'Project has already started';
58+
}
59+
});
60+
}
61+
}
4062
// user is not an admin nor is a registered project member
41-
return reject(new Error('You do not have permissions to perform this action'));
63+
return reject(new Error(errorMessage));
4264
}
4365
return resolve(true);
4466
});

0 commit comments

Comments
 (0)