Skip to content

Commit 17d5c45

Browse files
authored
Merge pull request #1731 from topcoder-platform/develop
[PROD RELEASE] - Restrict Engagements Tab only to Admin Role
2 parents 38c5eab + 1d687ff commit 17d5c45

3 files changed

Lines changed: 26 additions & 11 deletions

File tree

src/components/Tab/index.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@ const Tab = ({
88
selectTab,
99
projectId,
1010
canViewAssets,
11-
canViewEngagements,
11+
canViewEngagements, // Admin or TM
12+
isAdmin, // Only admin
1213
onBack
1314
}) => {
1415
const projectTabs = [
@@ -21,7 +22,7 @@ const Tab = ({
2122
: [
2223
{ id: 1, label: 'All Work' },
2324
{ id: 2, label: 'Projects' },
24-
...(canViewEngagements ? [{ id: 3, label: 'Engagements' }] : []),
25+
...(isAdmin ? [{ id: 3, label: 'Engagements' }] : []),
2526
{ id: 4, label: 'Users' },
2627
{ id: 5, label: 'Self-Service' },
2728
{ id: 6, label: 'TaaS' },
@@ -88,6 +89,7 @@ Tab.defaultProps = {
8889
projectId: null,
8990
canViewAssets: true,
9091
canViewEngagements: false,
92+
isAdmin: false,
9193
onBack: () => {}
9294
}
9395

@@ -97,6 +99,7 @@ Tab.propTypes = {
9799
projectId: PT.oneOfType([PT.string, PT.number]),
98100
canViewAssets: PT.bool,
99101
canViewEngagements: PT.bool,
102+
isAdmin: PT.bool,
100103
onBack: PT.func
101104
}
102105

src/containers/Tab/index.js

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ class TabContainer extends Component {
3838
return !!resolvedToken && checkAdminOrTalentManager(resolvedToken)
3939
}
4040

41+
getIsAdmin (props = this.props) {
42+
const { token: currentToken } = this.props
43+
const { token } = props
44+
const resolvedToken = token || currentToken
45+
return !!resolvedToken && checkAdmin(resolvedToken)
46+
}
47+
4148
componentDidMount () {
4249
const {
4350
projectId,
@@ -63,8 +70,9 @@ class TabContainer extends Component {
6370

6471
const canViewAssets = this.getCanViewAssets()
6572
const canViewEngagements = this.getCanViewEngagements()
73+
const isAdmin = this.getIsAdmin()
6674
this.setState({
67-
currentTab: this.getTabFromPath(history.location.pathname, projectId, canViewAssets, canViewEngagements)
75+
currentTab: this.getTabFromPath(history.location.pathname, projectId, canViewAssets, canViewEngagements, isAdmin)
6876
})
6977
}
7078

@@ -77,8 +85,9 @@ class TabContainer extends Component {
7785

7886
const canViewAssets = this.getCanViewAssets(nextProps)
7987
const canViewEngagements = this.getCanViewEngagements(nextProps)
88+
const isAdmin = this.getIsAdmin(nextProps)
8089
this.setState({
81-
currentTab: this.getTabFromPath(nextProps.history.location.pathname, projectId, canViewAssets, canViewEngagements)
90+
currentTab: this.getTabFromPath(nextProps.history.location.pathname, projectId, canViewAssets, canViewEngagements, isAdmin)
8291
})
8392
if (
8493
isLoading ||
@@ -130,7 +139,7 @@ class TabContainer extends Component {
130139
return 0
131140
}
132141

133-
getTabFromPath (pathname, projectId, canViewAssets = true, canViewEngagements = false) {
142+
getTabFromPath (pathname, projectId, canViewAssets = true, canViewEngagements = false, isAdmin = false) {
134143
if (projectId) {
135144
return this.getProjectTabFromPath(pathname, projectId, canViewAssets, canViewEngagements)
136145
}
@@ -141,7 +150,7 @@ class TabContainer extends Component {
141150
return 2
142151
}
143152
if (pathname === '/engagements') {
144-
return canViewEngagements ? 3 : 0
153+
return isAdmin ? 3 : 0
145154
}
146155
if (pathname === '/users') {
147156
return 4
@@ -178,7 +187,8 @@ class TabContainer extends Component {
178187
onTabChange (tab) {
179188
const { history, resetSidebarActiveParams, projectId } = this.props
180189
const canViewAssets = this.getCanViewAssets()
181-
const canViewEngagements = this.getCanViewEngagements()
190+
const canViewEngagements = this.getCanViewEngagements() // admin OR TM
191+
const isAdmin = this.getIsAdmin() // admin
182192
if (projectId) {
183193
if ((tab === 2 && !canViewEngagements) || (tab === 3 && !canViewAssets)) {
184194
return
@@ -200,7 +210,7 @@ class TabContainer extends Component {
200210
history.push('/projects')
201211
this.props.unloadProjects()
202212
this.setState({ currentTab: 2 })
203-
} else if (tab === 3 && canViewEngagements) {
213+
} else if (tab === 3 && isAdmin) {
204214
history.push('/engagements')
205215
this.setState({ currentTab: 3 })
206216
} else if (tab === 4) {
@@ -225,6 +235,7 @@ class TabContainer extends Component {
225235
const { currentTab } = this.state
226236
const canViewAssets = this.getCanViewAssets()
227237
const canViewEngagements = this.getCanViewEngagements()
238+
const isAdmin = this.getIsAdmin()
228239

229240
return (
230241
<Tab
@@ -233,6 +244,7 @@ class TabContainer extends Component {
233244
projectId={this.props.projectId}
234245
canViewAssets={canViewAssets}
235246
canViewEngagements={canViewEngagements}
247+
isAdmin={isAdmin}
236248
onBack={this.onBackToHome}
237249
/>
238250
)

src/routes.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ class Routes extends React.Component {
156156
<FooterContainer />
157157
)()}
158158
/>
159-
{canAccessEngagements && (
159+
{isAdmin && (
160160
<Route exact path='/engagements'
161161
render={() => renderApp(
162162
<EngagementsList allEngagements />,
@@ -166,12 +166,12 @@ class Routes extends React.Component {
166166
)()}
167167
/>
168168
)}
169-
{!canAccessEngagements && (
169+
{!isAdmin && (
170170
<Route exact path='/engagements'
171171
render={() => renderApp(
172172
<Challenges
173173
menu='NULL'
174-
warnMessage={'You need Admin or Talent Manager role to view all engagements'}
174+
warnMessage={'You need Admin role to view all engagements'}
175175
/>,
176176
<TopBarContainer />,
177177
<Tab />,

0 commit comments

Comments
 (0)