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 22import _ from 'lodash' ;
33import util from '../util' ;
44import 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 } ) ;
You can’t perform that action at this time.
0 commit comments