Skip to content

Commit b417186

Browse files
committed
hide project defaults page for customer role
1 parent 6139dff commit b417186

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/helpers/protectComponent.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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

src/projects/detail/components/EditProjectDefaultsForm/EditProjectDefaultsForm.jsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { updateProject } from '../../../actions/project'
77
import NDAField from '../NDAField'
88
import GroupsField from '../GroupsField'
99
import BillingAccountField from '../BillingAccountField'
10+
import {PERMISSIONS} from '../../../../config/permissions'
11+
import protectComponent from '../../../../helpers/protectComponent'
1012

1113
import './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+
)

0 commit comments

Comments
 (0)