Skip to content

Commit

Permalink
Merge pull request #1530 from topcoder-platform/PROD-4262
Browse files Browse the repository at this point in the history
Redirect fix
  • Loading branch information
jmgasper authored May 22, 2023
2 parents 274e4c1 + b79cfc4 commit afa9d19
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { getFreshToken, decodeToken } from 'tc-auth-lib'
import { saveToken } from './actions/auth'
import { loadChallengeDetails } from './actions/challenges'
import { connect } from 'react-redux'
import { checkAllowedRoles, checkReadOnlyRoles } from './util/tc'
import { checkAllowedRoles, checkOnlyReadOnlyRoles, checkReadOnlyRoles } from './util/tc'
import { setCookie, removeCookie, isBetaMode } from './util/cookie'
import IdleTimer from 'react-idle-timer'
import modalStyles from './styles/modal.module.scss'
Expand All @@ -38,7 +38,7 @@ class RedirectToChallenge extends React.Component {

componentWillReceiveProps (nextProps) {
const { token } = nextProps
const isReadOnly = checkReadOnlyRoles(token)
const isReadOnly = checkOnlyReadOnlyRoles(token)
const projectId = _.get(nextProps.challengeDetails, 'projectId')
const challengeId = _.get(nextProps.challengeDetails, 'id')
if (projectId && challengeId && isReadOnly) {
Expand All @@ -52,8 +52,9 @@ class RedirectToChallenge extends React.Component {
}
}

let mapStateToProps = ({ challenges: { challengeDetails } }) => ({
challengeDetails
let mapStateToProps = ({ challenges: { challengeDetails }, auth }) => ({
challengeDetails,
...auth
})

let mapDispatchToProps = {
Expand Down
9 changes: 9 additions & 0 deletions src/util/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,15 @@ export const checkReadOnlyRoles = token => {
return roles.some(val => READ_ONLY_ROLES.indexOf(val.toLowerCase()) > -1)
}

/**
* Checks if read only role is present in roles
* @param token
*/
export const checkOnlyReadOnlyRoles = token => {
const roles = _.get(decodeToken(token), 'roles')
return roles.some(val => READ_ONLY_ROLES.indexOf(val.toLowerCase()) > -1)
}

/**
* Checks if token has any of the admin roles
* @param token
Expand Down

0 comments on commit afa9d19

Please sign in to comment.