Skip to content

Commit

Permalink
Merge pull request #603 from CBIIT/CRDCDH-2271
Browse files Browse the repository at this point in the history
CRDCDH-2271 Limit Collaborator editing for specific Submission statuses
  • Loading branch information
amattu2 authored Jan 23, 2025
2 parents 47f7691 + c4fed02 commit bc7a903
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/components/Collaborators/CollaboratorsDialog.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -400,4 +400,64 @@ describe("CollaboratorsDialog Component", () => {
expect(getByTestId("collaborators-dialog-cancel-button")).toBeInTheDocument();
expect(queryByTestId("collaborators-dialog-close-button")).not.toBeInTheDocument();
});

it.each<SubmissionStatus>(["Completed", "Canceled", "Deleted"])(
"should not allow changes when submission status is '%s'",
async (status) => {
mockUseAuthContext.mockReturnValue({
user: {
...mockUser,
permissions: ["data_submission:view", "data_submission:create"],
} as User,
status: AuthStatus.LOADED,
});
mockUseSubmissionContext.mockReturnValue({
data: { getSubmission: { ...mockSubmission, status } as Submission },
updateQuery: mockUpdateQuery,
});

const mockOnClose = jest.fn();
const { getByTestId, queryByTestId } = render(
<TestParent>
<CollaboratorsDialog open onClose={mockOnClose} onSave={jest.fn()} />
</TestParent>
);

expect(queryByTestId("collaborators-dialog-save-button")).not.toBeInTheDocument();
expect(queryByTestId("collaborators-dialog-cancel-button")).not.toBeInTheDocument();
expect(getByTestId("collaborators-dialog-close-button")).toBeInTheDocument();
}
);

it.each<SubmissionStatus>([
"New",
"In Progress",
"Rejected",
"Released",
"Submitted",
"Withdrawn",
])("should allow changes when submission status is '%s'", async (status) => {
mockUseAuthContext.mockReturnValue({
user: {
...mockUser,
permissions: ["data_submission:view", "data_submission:create"],
} as User,
status: AuthStatus.LOADED,
});
mockUseSubmissionContext.mockReturnValue({
data: { getSubmission: { ...mockSubmission, status } as Submission },
updateQuery: mockUpdateQuery,
});

const mockOnClose = jest.fn();
const { getByTestId, queryByTestId } = render(
<TestParent>
<CollaboratorsDialog open onClose={mockOnClose} onSave={jest.fn()} />
</TestParent>
);

expect(getByTestId("collaborators-dialog-save-button")).toBeInTheDocument();
expect(getByTestId("collaborators-dialog-cancel-button")).toBeInTheDocument();
expect(queryByTestId("collaborators-dialog-close-button")).not.toBeInTheDocument();
});
});
13 changes: 12 additions & 1 deletion src/components/Collaborators/CollaboratorsDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ const StyledDescription = styled(Typography)({
marginBottom: "44px",
});

/**
* A set of Submission statuses where the collaborator dialog actions
* should be disabled
*/
export const DISABLE_COLLABORATOR_DIALOG_STATUSES: SubmissionStatus[] = [
"Completed",
"Canceled",
"Deleted",
];

type Props = {
onClose: () => void;
onSave: (collaborators: Collaborator[]) => void;
Expand All @@ -112,7 +122,8 @@ const CollaboratorsDialog = ({ onClose, onSave, open, ...rest }: Props) => {
const canModifyCollaborators = useMemo(
() =>
hasPermission(user, "data_submission", "create", null, true) &&
submission?.getSubmission?.submitterID === user?._id,
submission?.getSubmission?.submitterID === user?._id &&
!DISABLE_COLLABORATOR_DIALOG_STATUSES.includes(submission?.getSubmission?.status),
[user, submission?.getSubmission]
);

Expand Down
2 changes: 1 addition & 1 deletion src/components/DataSubmissions/DataSubmissionSummary.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ const DataSubmissionSummary: FC<Props> = ({ dataSubmission }) => {
<StyledTooltip
placement="top"
title="Click to add new collaborators or view existing ones."
disableHoverListener={false}
disableHoverListener={!dataSubmission}
slotProps={{
tooltip: { "data-testid": "collaborators-button-tooltip" } as unknown,
}}
Expand Down

0 comments on commit bc7a903

Please sign in to comment.