Skip to content

PM-973 - fix checkIsUserInvitedToProject #1636

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

Merged
merged 1 commit into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/containers/Challenges/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import {
setActiveProject,
resetSidebarActiveParams
} from '../../actions/sidebar'
import { checkAdmin, checkIsUserInvited } from '../../util/tc'
import { checkAdmin, checkIsUserInvitedToProject } from '../../util/tc'
import { withRouter } from 'react-router-dom'

class Challenges extends Component {
Expand Down Expand Up @@ -59,7 +59,7 @@ class Challenges extends Component {
componentDidUpdate () {
const { auth } = this.props

if (checkIsUserInvited(auth.token, this.props.projectDetail)) {
if (checkIsUserInvitedToProject(auth.token, this.props.projectDetail)) {
this.props.history.push(`/projects/${this.props.projectId}/invitation`)
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/containers/ProjectEditor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
updateProject
} from '../../actions/projects'
import { setActiveProject } from '../../actions/sidebar'
import { checkAdminOrCopilot, checkAdmin, checkIsUserInvited } from '../../util/tc'
import { checkAdminOrCopilot, checkAdmin, checkIsUserInvitedToProject } from '../../util/tc'
import { PROJECT_ROLES } from '../../config/constants'
import Loader from '../../components/Loader'

Expand All @@ -38,7 +38,7 @@ class ProjectEditor extends Component {
componentDidUpdate () {
const { auth } = this.props

if (checkIsUserInvited(auth.token, this.props.projectDetail)) {
if (checkIsUserInvitedToProject(auth.token, this.props.projectDetail)) {
this.props.history.push(`/projects/${this.props.projectDetail.id}/invitation`)
}

Expand Down
4 changes: 2 additions & 2 deletions src/containers/ProjectInvitations/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react'
import { connect } from 'react-redux'
import { withRouter } from 'react-router-dom'
import { toastr } from 'react-redux-toastr'
import { checkIsUserInvited } from '../../util/tc'
import { checkIsUserInvitedToProject } from '../../util/tc'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import statement has been updated to use checkIsUserInvitedToProject. Ensure that this function is correctly defined and exported in ../../util/tc and that all references to checkIsUserInvited in this file and others are updated accordingly.

import { isEmpty } from 'lodash'
import { loadProjectInvites } from '../../actions/projects'
import ConfirmationModal from '../../components/Modal/ConfirmationModal'
Expand All @@ -20,7 +20,7 @@ const theme = {
const ProjectInvitations = ({ match, auth, isProjectLoading, history, projectDetail, loadProjectInvites }) => {
const automaticAction = useMemo(() => [PROJECT_MEMBER_INVITE_STATUS_ACCEPTED, PROJECT_MEMBER_INVITE_STATUS_REFUSED].includes(match.params.action) ? match.params.action : undefined, [match.params])
const projectId = useMemo(() => parseInt(match.params.projectId), [match.params])
const invitation = useMemo(() => checkIsUserInvited(auth.token, projectDetail), [auth.token, projectDetail])
const invitation = useMemo(() => checkIsUserInvitedToProject(auth.token, projectDetail), [auth.token, projectDetail])
const [isUpdating, setIsUpdating] = useState(automaticAction || false)
const isAccepting = isUpdating === PROJECT_MEMBER_INVITE_STATUS_ACCEPTED
const isDeclining = isUpdating === PROJECT_MEMBER_INVITE_STATUS_REFUSED
Expand Down
4 changes: 2 additions & 2 deletions src/containers/Projects/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { withRouter, Link } from 'react-router-dom'
import { connect } from 'react-redux'
import PropTypes from 'prop-types'
import Loader from '../../components/Loader'
import { checkAdminOrCopilot, checkIsUserInvited, checkManager } from '../../util/tc'
import { checkAdminOrCopilot, checkIsUserInvitedToProject, checkManager } from '../../util/tc'
import { PrimaryButton } from '../../components/Buttons'
import Select from '../../components/Select'
import ProjectCard from '../../components/ProjectCard'
Expand Down Expand Up @@ -112,7 +112,7 @@ const Projects = ({ projects, auth, isLoading, projectsCount, loadProjects, load
{projects.map(p => (
<li key={p.id}>
<ProjectCard
isInvited={!!checkIsUserInvited(auth.token, p)}
isInvited={!!checkIsUserInvitedToProject(auth.token, p)}
projectStatus={p.status}
projectName={p.name}
projectId={p.id}
Expand Down
4 changes: 2 additions & 2 deletions src/util/tc.js
Original file line number Diff line number Diff line change
Expand Up @@ -233,13 +233,13 @@ export const checkAdminOrCopilot = (token, project) => {
return isAdmin || (isCopilot && canManageProject)
}

export const checkIsUserInvited = (token, project) => {
export const checkIsUserInvitedToProject = (token, project) => {
if (!token) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider returning a specific value (e.g., false) instead of undefined when the token is not provided, to maintain consistency in return types.

return
}

const tokenData = decodeToken(token)
return project && !_.isEmpty(project) && _.find(project.invites, { userId: tokenData.userId })
return project && !_.isEmpty(project) && (_.find(project.invites, d => d.userId === tokenData.userId || d.email === tokenData.email))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The condition now checks for both userId and email. Ensure that this change aligns with the intended logic and that it does not introduce any security or logic issues, such as allowing access based on email when it should be restricted to userId.

}

/**
Expand Down