@@ -15,7 +15,7 @@ import { getFreshToken, decodeToken } from 'tc-auth-lib'
1515import { saveToken } from './actions/auth'
1616import { loadChallengeDetails } from './actions/challenges'
1717import { connect } from 'react-redux'
18- import { checkAllowedRoles } from './util/tc'
18+ import { checkAllowedRoles , checkReadOnlyRoles } from './util/tc'
1919import { setCookie , removeCookie , isBetaMode } from './util/cookie'
2020import IdleTimer from 'react-idle-timer'
2121import modalStyles from './styles/modal.module.scss'
@@ -36,9 +36,11 @@ class RedirectToChallenge extends React.Component {
3636 }
3737
3838 componentWillReceiveProps ( nextProps ) {
39+ const { token } = nextProps
40+ const isReadOnly = checkReadOnlyRoles ( token )
3941 const projectId = _ . get ( nextProps . challengeDetails , 'projectId' )
4042 const challengeId = _ . get ( nextProps . challengeDetails , 'id' )
41- if ( projectId && challengeId ) {
43+ if ( projectId && challengeId && isReadOnly ) {
4244 console . log ( 'Redircting to full URL' )
4345 this . props . history . replace ( `/projects/${ projectId } /challenges/${ challengeId } /view` )
4446 }
@@ -61,7 +63,8 @@ RedirectToChallenge.propTypes = {
6163 loadChallengeDetails : PropTypes . func ,
6264 challengeDetails : PropTypes . object ,
6365 match : PropTypes . object ,
64- history : PropTypes . object
66+ history : PropTypes . object ,
67+ token : PropTypes . string
6568}
6669
6770const ConnectRedirectToChallenge = connect ( mapStateToProps , mapDispatchToProps ) ( RedirectToChallenge )
@@ -128,6 +131,7 @@ class Routes extends React.Component {
128131 }
129132
130133 const isAllowed = checkAllowedRoles ( _ . get ( decodeToken ( this . props . token ) , 'roles' ) )
134+ const isReadOnly = checkReadOnlyRoles ( this . props . token )
131135 const modal = ( < ConfirmationModal
132136 theme = { theme }
133137 title = 'Session Timeout'
@@ -176,26 +180,34 @@ class Routes extends React.Component {
176180 < Tab />
177181 ) ( ) }
178182 />
179- < Route exact path = '/users'
180- render = { ( ) => renderApp (
181- < Users /> ,
182- < TopBarContainer /> ,
183- < Tab />
184- ) ( ) }
185- />
183+ {
184+ ! isReadOnly && (
185+ < Route exact path = '/users'
186+ render = { ( ) => renderApp (
187+ < Users /> ,
188+ < TopBarContainer /> ,
189+ < Tab />
190+ ) ( ) }
191+ />
192+ )
193+ }
186194 < Route exact path = '/self-service'
187195 render = { ( ) => renderApp (
188196 < Challenges selfService /> ,
189197 < TopBarContainer /> ,
190198 < Tab selfService />
191199 ) ( ) }
192200 />
193- < Route exact path = '/projects/:projectId/challenges/new'
194- render = { ( { match } ) => renderApp (
195- < ChallengeEditor /> ,
196- < TopBarContainer /> ,
197- < Tab projectId = { match . params . projectId } menu = { 'New Challenge' } />
198- ) ( ) } />
201+ {
202+ ! isReadOnly && (
203+ < Route exact path = '/projects/:projectId/challenges/new'
204+ render = { ( { match } ) => renderApp (
205+ < ChallengeEditor /> ,
206+ < TopBarContainer /> ,
207+ < Tab projectId = { match . params . projectId } menu = { 'New Challenge' } />
208+ ) ( ) } />
209+ )
210+ }
199211 < Route exact path = '/challenges/:challengeId' component = { ConnectRedirectToChallenge } />
200212 < Route
201213 path = '/projects/:projectId/challenges/:challengeId'
0 commit comments