@@ -15,7 +15,7 @@ import { getFreshToken, decodeToken } from 'tc-auth-lib'
15
15
import { saveToken } from './actions/auth'
16
16
import { loadChallengeDetails } from './actions/challenges'
17
17
import { connect } from 'react-redux'
18
- import { checkAllowedRoles } from './util/tc'
18
+ import { checkAllowedRoles , checkReadOnlyRoles } from './util/tc'
19
19
import { setCookie , removeCookie , isBetaMode } from './util/cookie'
20
20
import IdleTimer from 'react-idle-timer'
21
21
import modalStyles from './styles/modal.module.scss'
@@ -36,9 +36,11 @@ class RedirectToChallenge extends React.Component {
36
36
}
37
37
38
38
componentWillReceiveProps ( nextProps ) {
39
+ const { token } = nextProps
40
+ const isReadOnly = checkReadOnlyRoles ( token )
39
41
const projectId = _ . get ( nextProps . challengeDetails , 'projectId' )
40
42
const challengeId = _ . get ( nextProps . challengeDetails , 'id' )
41
- if ( projectId && challengeId ) {
43
+ if ( projectId && challengeId && isReadOnly ) {
42
44
console . log ( 'Redircting to full URL' )
43
45
this . props . history . replace ( `/projects/${ projectId } /challenges/${ challengeId } /view` )
44
46
}
@@ -61,7 +63,8 @@ RedirectToChallenge.propTypes = {
61
63
loadChallengeDetails : PropTypes . func ,
62
64
challengeDetails : PropTypes . object ,
63
65
match : PropTypes . object ,
64
- history : PropTypes . object
66
+ history : PropTypes . object ,
67
+ token : PropTypes . string
65
68
}
66
69
67
70
const ConnectRedirectToChallenge = connect ( mapStateToProps , mapDispatchToProps ) ( RedirectToChallenge )
@@ -128,6 +131,7 @@ class Routes extends React.Component {
128
131
}
129
132
130
133
const isAllowed = checkAllowedRoles ( _ . get ( decodeToken ( this . props . token ) , 'roles' ) )
134
+ const isReadOnly = checkReadOnlyRoles ( this . props . token )
131
135
const modal = ( < ConfirmationModal
132
136
theme = { theme }
133
137
title = 'Session Timeout'
@@ -176,26 +180,34 @@ class Routes extends React.Component {
176
180
< Tab />
177
181
) ( ) }
178
182
/>
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
+ }
186
194
< Route exact path = '/self-service'
187
195
render = { ( ) => renderApp (
188
196
< Challenges selfService /> ,
189
197
< TopBarContainer /> ,
190
198
< Tab selfService />
191
199
) ( ) }
192
200
/>
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
+ }
199
211
< Route exact path = '/challenges/:challengeId' component = { ConnectRedirectToChallenge } />
200
212
< Route
201
213
path = '/projects/:projectId/challenges/:challengeId'
0 commit comments