-
Notifications
You must be signed in to change notification settings - Fork 51
[PROD RELEASE] - Restrict Engagements Tab only to Admin Role #1731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,13 @@ class TabContainer extends Component { | |
| return !!resolvedToken && checkAdminOrTalentManager(resolvedToken) | ||
| } | ||
|
|
||
| getIsAdmin (props = this.props) { | ||
| const { token: currentToken } = this.props | ||
| const { token } = props | ||
| const resolvedToken = token || currentToken | ||
| return !!resolvedToken && checkAdmin(resolvedToken) | ||
| } | ||
|
|
||
| componentDidMount () { | ||
| const { | ||
| projectId, | ||
|
|
@@ -63,8 +70,9 @@ class TabContainer extends Component { | |
|
|
||
| const canViewAssets = this.getCanViewAssets() | ||
| const canViewEngagements = this.getCanViewEngagements() | ||
| const isAdmin = this.getIsAdmin() | ||
| this.setState({ | ||
| currentTab: this.getTabFromPath(history.location.pathname, projectId, canViewAssets, canViewEngagements) | ||
| currentTab: this.getTabFromPath(history.location.pathname, projectId, canViewAssets, canViewEngagements, isAdmin) | ||
| }) | ||
| } | ||
|
|
||
|
|
@@ -77,8 +85,9 @@ class TabContainer extends Component { | |
|
|
||
| const canViewAssets = this.getCanViewAssets(nextProps) | ||
| const canViewEngagements = this.getCanViewEngagements(nextProps) | ||
| const isAdmin = this.getIsAdmin(nextProps) | ||
| this.setState({ | ||
| currentTab: this.getTabFromPath(nextProps.history.location.pathname, projectId, canViewAssets, canViewEngagements) | ||
| currentTab: this.getTabFromPath(nextProps.history.location.pathname, projectId, canViewAssets, canViewEngagements, isAdmin) | ||
| }) | ||
| if ( | ||
| isLoading || | ||
|
|
@@ -130,7 +139,7 @@ class TabContainer extends Component { | |
| return 0 | ||
| } | ||
|
|
||
| getTabFromPath (pathname, projectId, canViewAssets = true, canViewEngagements = false) { | ||
| getTabFromPath (pathname, projectId, canViewAssets = true, canViewEngagements = false, isAdmin = false) { | ||
| if (projectId) { | ||
| return this.getProjectTabFromPath(pathname, projectId, canViewAssets, canViewEngagements) | ||
| } | ||
|
|
@@ -141,7 +150,7 @@ class TabContainer extends Component { | |
| return 2 | ||
| } | ||
| if (pathname === '/engagements') { | ||
| return canViewEngagements ? 3 : 0 | ||
| return isAdmin ? 3 : 0 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| } | ||
| if (pathname === '/users') { | ||
| return 4 | ||
|
|
@@ -178,7 +187,8 @@ class TabContainer extends Component { | |
| onTabChange (tab) { | ||
| const { history, resetSidebarActiveParams, projectId } = this.props | ||
| const canViewAssets = this.getCanViewAssets() | ||
| const canViewEngagements = this.getCanViewEngagements() | ||
| const canViewEngagements = this.getCanViewEngagements() // admin OR TM | ||
| const isAdmin = this.getIsAdmin() // admin | ||
| if (projectId) { | ||
| if ((tab === 2 && !canViewEngagements) || (tab === 3 && !canViewAssets)) { | ||
| return | ||
|
|
@@ -200,7 +210,7 @@ class TabContainer extends Component { | |
| history.push('/projects') | ||
| this.props.unloadProjects() | ||
| this.setState({ currentTab: 2 }) | ||
| } else if (tab === 3 && canViewEngagements) { | ||
| } else if (tab === 3 && isAdmin) { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| history.push('/engagements') | ||
| this.setState({ currentTab: 3 }) | ||
| } else if (tab === 4) { | ||
|
|
@@ -225,6 +235,7 @@ class TabContainer extends Component { | |
| const { currentTab } = this.state | ||
| const canViewAssets = this.getCanViewAssets() | ||
| const canViewEngagements = this.getCanViewEngagements() | ||
| const isAdmin = this.getIsAdmin() | ||
|
|
||
| return ( | ||
| <Tab | ||
|
|
@@ -233,6 +244,7 @@ class TabContainer extends Component { | |
| projectId={this.props.projectId} | ||
| canViewAssets={canViewAssets} | ||
| canViewEngagements={canViewEngagements} | ||
| isAdmin={isAdmin} | ||
| onBack={this.onBackToHome} | ||
| /> | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -156,7 +156,7 @@ class Routes extends React.Component { | |
| <FooterContainer /> | ||
| )()} | ||
| /> | ||
| {canAccessEngagements && ( | ||
| {isAdmin && ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| <Route exact path='/engagements' | ||
| render={() => renderApp( | ||
| <EngagementsList allEngagements />, | ||
|
|
@@ -166,12 +166,12 @@ class Routes extends React.Component { | |
| )()} | ||
| /> | ||
| )} | ||
| {!canAccessEngagements && ( | ||
| {!isAdmin && ( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [❗❗ |
||
| <Route exact path='/engagements' | ||
| render={() => renderApp( | ||
| <Challenges | ||
| menu='NULL' | ||
| warnMessage={'You need Admin or Talent Manager role to view all engagements'} | ||
| warnMessage={'You need Admin role to view all engagements'} | ||
| />, | ||
| <TopBarContainer />, | ||
| <Tab />, | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[❗❗
correctness]The change from
canViewEngagementstoisAdminrestricts the visibility of the 'Engagements' tab to only admin users. Ensure that this change aligns with the intended business logic, as it removes access for any other roles that might have previously been able to view this tab.