File tree Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Expand file tree Collapse file tree 1 file changed +24
-2
lines changed Original file line number Diff line number Diff line change 2
2
import _ from 'lodash' ;
3
3
import util from '../util' ;
4
4
import models from '../models' ;
5
- import { USER_ROLE } from '../constants' ;
5
+ import { USER_ROLE , PROJECT_STATUS } from '../constants' ;
6
6
7
7
/**
8
8
* Super admin, Topcoder Managers are allowed to view any projects
@@ -37,8 +37,30 @@ module.exports = freq => new Promise((resolve, reject) => {
37
37
} )
38
38
. then ( ( hasAccess ) => {
39
39
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
+ }
40
62
// 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 ) ) ;
42
64
}
43
65
return resolve ( true ) ;
44
66
} ) ;
You can’t perform that action at this time.
0 commit comments