Skip to content

Commit

Permalink
Merge pull request #1133 from nickgros/SWC-7010
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgros authored Aug 15, 2024
2 parents fa492a2 + f206c15 commit 05048ab
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ import {
getEndpoint,
} from '../../utils/functions/getEndpoint'
import {
AccessControlList,
ACCESS_TYPE,
SubmissionState,
AccessControlList,
FileHandleAssociation,
SubmissionState,
} from '@sage-bionetworks/synapse-types'
import {
mockApprovedSubmission,
Expand All @@ -35,8 +35,10 @@ import { mockManagedACTAccessRequirement } from '../../mocks/accessRequirement/m
import { rest, server } from '../../mocks/msw/server'
import {
MOCK_USER_ID,
MOCK_USER_ID_3,
MOCK_USER_NAME,
MOCK_USER_NAME_2,
MOCK_USER_NAME_3,
} from '../../mocks/user/mock_user_profile'
import * as RejectDataAccessRequestModalModule from './RejectDataAccessRequestModal'
import failOnConsoleError from 'jest-fail-on-console'
Expand Down Expand Up @@ -290,8 +292,7 @@ describe('Submission Page tests', () => {
).not.toBeInTheDocument()
})

// Flaky in TravisCI
it.skip('Renders a user card if the AR has an ACL', async () => {
it('Renders a user card if the AR has an ACL', async () => {
// Fetching the AR's ACL will yield a designated reviewer
server.use(
rest.get(
Expand All @@ -307,6 +308,11 @@ describe('Submission Page tests', () => {
principalId: MOCK_USER_ID,
accessType: [ACCESS_TYPE.REVIEW_SUBMISSIONS],
},
{
// User 3 should not be shown
principalId: MOCK_USER_ID_3,
accessType: [ACCESS_TYPE.EXEMPTION_ELIGIBLE],
},
],
}
return res(ctx.status(200), ctx.json(responseBody))
Expand All @@ -318,12 +324,15 @@ describe('Submission Page tests', () => {
submissionId: SUBMITTED_SUBMISSION_ID,
})

// When an ACL exists, don't show the ACT as the reviewer
expect(screen.queryByText(mockActTeam.name)).not.toBeInTheDocument()

// User 1 now appears as the submitter, modifier, an accessor, and the Reviewer
await waitFor(() =>
expect(screen.getAllByText('@' + MOCK_USER_NAME)).toHaveLength(4),
)

// User 3 should not appear - they are not a reviewer
expect(screen.queryByText('@' + MOCK_USER_NAME_3)).not.toBeInTheDocument()

// When an ACL exists, don't show the ACT as the reviewer
expect(screen.queryByText(mockActTeam.name)).not.toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Button, Skeleton, Typography } from '@mui/material'
import { toLower, upperFirst } from 'lodash-es'
import { isEmpty, toLower, upperFirst } from 'lodash-es'
import dayjs from 'dayjs'
import React, { useState } from 'react'
import { useErrorHandler } from 'react-error-boundary'
Expand All @@ -14,6 +14,7 @@ import {
} from '../../synapse-queries/dataaccess/useAccessRequirements'
import { ACT_TEAM_ID } from '../../utils/SynapseConstants'
import {
ACCESS_TYPE,
FileHandleAssociateType,
ManagedACTAccessRequirement,
SubmissionState,
Expand Down Expand Up @@ -133,7 +134,7 @@ export default function SubmissionPage(props: SubmissionPageProps) {
{ enabled: !!submission },
)

const { data: acl } = useGetAccessRequirementACL(
const { data: acl, isLoading: isLoadingACL } = useGetAccessRequirementACL(
submission?.accessRequirementId!,
{ enabled: !!submission, throwOnError: true },
)
Expand All @@ -148,6 +149,10 @@ export default function SubmissionPage(props: SubmissionPageProps) {
})
}

const reviewerIds = acl?.resourceAccess
.filter(ra => ra.accessType.includes(ACCESS_TYPE.REVIEW_SUBMISSIONS))
.map(ra => ra.principalId)

return (
<div className="SubmissionPage">
<ApproveConfirmationModal
Expand Down Expand Up @@ -213,21 +218,14 @@ export default function SubmissionPage(props: SubmissionPageProps) {
<br />
<Typography variant="dataFieldKey">Assigned Reviewer</Typography>
<Typography variant="smallText1">
{acl !== undefined ? (
acl !== null ? (
acl.resourceAccess.map(ra => {
return (
<UserOrTeamBadge
key={ra.principalId}
principalId={ra.principalId}
/>
)
})
) : (
<UserOrTeamBadge principalId={ACT_TEAM_ID} />
)
) : (
<Skeleton width={100} />
{isLoadingACL && <Skeleton width={100} />}
{!isLoadingACL &&
!isEmpty(reviewerIds) &&
reviewerIds!.map(id => {
return <UserOrTeamBadge key={id} principalId={id} />
})}
{!isLoadingACL && isEmpty(reviewerIds) && (
<UserOrTeamBadge principalId={ACT_TEAM_ID} />
)}
</Typography>
<br />
Expand Down

0 comments on commit 05048ab

Please sign in to comment.