File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed
projects/detail/components/EditProjectDefaultsForm Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change 1+ import React from 'react'
2+ import CoderBroken from '../assets/icons/coder-broken.svg'
3+ import { hasPermission } from './permissions'
4+
5+ function protectComponent ( Component , permission , pageName ) {
6+ class ProtectedComponent extends React . Component {
7+ render ( ) {
8+ if ( ! hasPermission ( permission ) ) {
9+ return (
10+ < section className = "content content-error" >
11+ < div className = "container" >
12+ < div className = "page-error" >
13+ < CoderBroken className = "icon-coder-broken" />
14+ < span > You don't have permission to access { pageName || 'this page' } </ span >
15+ </ div >
16+ </ div >
17+ </ section >
18+ )
19+ }
20+ return < Component { ...this . props } />
21+ }
22+ }
23+
24+ return ProtectedComponent
25+ }
26+
27+ export default protectComponent
Original file line number Diff line number Diff line change @@ -7,6 +7,8 @@ import { updateProject } from '../../../actions/project'
77import NDAField from '../NDAField'
88import GroupsField from '../GroupsField'
99import BillingAccountField from '../BillingAccountField'
10+ import { PERMISSIONS } from '../../../../config/permissions'
11+ import protectComponent from '../../../../helpers/protectComponent'
1012
1113import './EditProjectDefaultsForm.scss'
1214
@@ -106,4 +108,8 @@ const mapDispatchToProps = {
106108 updateProject
107109}
108110
109- export default connect ( null , mapDispatchToProps ) ( EditProjectDefaultsForm )
111+ export default protectComponent (
112+ connect ( null , mapDispatchToProps ) ( EditProjectDefaultsForm ) ,
113+ PERMISSIONS . VIEW_PROJECT_DEFAULTS ,
114+ 'Project Defaults'
115+ )
You can’t perform that action at this time.
0 commit comments