Skip to content

Commit afa9d19

Browse files
authored
Merge pull request #1530 from topcoder-platform/PROD-4262
Redirect fix
2 parents 274e4c1 + b79cfc4 commit afa9d19

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/routes.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { getFreshToken, decodeToken } from 'tc-auth-lib'
1616
import { saveToken } from './actions/auth'
1717
import { loadChallengeDetails } from './actions/challenges'
1818
import { connect } from 'react-redux'
19-
import { checkAllowedRoles, checkReadOnlyRoles } from './util/tc'
19+
import { checkAllowedRoles, checkOnlyReadOnlyRoles, checkReadOnlyRoles } from './util/tc'
2020
import { setCookie, removeCookie, isBetaMode } from './util/cookie'
2121
import IdleTimer from 'react-idle-timer'
2222
import modalStyles from './styles/modal.module.scss'
@@ -38,7 +38,7 @@ class RedirectToChallenge extends React.Component {
3838

3939
componentWillReceiveProps (nextProps) {
4040
const { token } = nextProps
41-
const isReadOnly = checkReadOnlyRoles(token)
41+
const isReadOnly = checkOnlyReadOnlyRoles(token)
4242
const projectId = _.get(nextProps.challengeDetails, 'projectId')
4343
const challengeId = _.get(nextProps.challengeDetails, 'id')
4444
if (projectId && challengeId && isReadOnly) {
@@ -52,8 +52,9 @@ class RedirectToChallenge extends React.Component {
5252
}
5353
}
5454

55-
let mapStateToProps = ({ challenges: { challengeDetails } }) => ({
56-
challengeDetails
55+
let mapStateToProps = ({ challenges: { challengeDetails }, auth }) => ({
56+
challengeDetails,
57+
...auth
5758
})
5859

5960
let mapDispatchToProps = {

src/util/tc.js

+9
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,15 @@ export const checkReadOnlyRoles = token => {
162162
return roles.some(val => READ_ONLY_ROLES.indexOf(val.toLowerCase()) > -1)
163163
}
164164

165+
/**
166+
* Checks if read only role is present in roles
167+
* @param token
168+
*/
169+
export const checkOnlyReadOnlyRoles = token => {
170+
const roles = _.get(decodeToken(token), 'roles')
171+
return roles.some(val => READ_ONLY_ROLES.indexOf(val.toLowerCase()) > -1)
172+
}
173+
165174
/**
166175
* Checks if token has any of the admin roles
167176
* @param token

0 commit comments

Comments
 (0)