@@ -15,8 +15,10 @@ import {
15
15
updateProject
16
16
} from '../../actions/projects'
17
17
import { setActiveProject } from '../../actions/sidebar'
18
- import { checkAdminOrCopilot } from '../../util/tc'
18
+ import { checkAdminOrCopilot , checkAdmin } from '../../util/tc'
19
+ import { PROJECT_ROLES } from '../../config/constants'
19
20
import Loader from '../../components/Loader'
21
+
20
22
class ProjectEditor extends Component {
21
23
constructor ( props ) {
22
24
super ( props )
@@ -53,6 +55,25 @@ class ProjectEditor extends Component {
53
55
}
54
56
}
55
57
58
+ getMemberRole ( members , handle ) {
59
+ if ( ! handle ) { return null }
60
+
61
+ const found = _ . find ( members , ( m ) => {
62
+ return m . handle === handle
63
+ } )
64
+
65
+ return _ . get ( found , 'role' )
66
+ }
67
+
68
+ checkIsCopilotOrManager ( projectMembers , handle ) {
69
+ if ( projectMembers && projectMembers . length > 0 ) {
70
+ const role = this . getMemberRole ( projectMembers , handle )
71
+ return role === PROJECT_ROLES . COPILOT || role === PROJECT_ROLES . MANAGER
72
+ } else {
73
+ return false
74
+ }
75
+ }
76
+
56
77
render ( ) {
57
78
const {
58
79
match,
@@ -66,8 +87,13 @@ class ProjectEditor extends Component {
66
87
isProjectLoading,
67
88
projectDetail
68
89
} = this . props
90
+
69
91
if ( isProjectTypesLoading || ( isEdit && isProjectLoading ) ) return < Loader />
70
92
93
+ const isAdmin = checkAdmin ( this . props . auth . token )
94
+ const isCopilotOrManager = this . checkIsCopilotOrManager ( _ . get ( this . state . project , 'members' , [ ] ) , _ . get ( this . props . auth , 'user.handle' , null ) )
95
+ const canManage = isAdmin || isCopilotOrManager
96
+
71
97
const projectId = this . getProjectId ( match )
72
98
return (
73
99
< div className = { styles . wrapper } >
@@ -97,6 +123,7 @@ class ProjectEditor extends Component {
97
123
setActiveProject = { setActiveProject }
98
124
history = { history }
99
125
isEdit = { isEdit }
126
+ canManage = { canManage }
100
127
projectDetail = { projectDetail }
101
128
/>
102
129
</ div >
0 commit comments