Skip to content

Commit 77ff5fc

Browse files
authored
COMP-798 link/unlink case file visibility (#723)
1 parent 045400e commit 77ff5fc

File tree

3 files changed

+43
-14
lines changed

3 files changed

+43
-14
lines changed

compliance-web/cypress/components/_components/_App/_CaseFiles/_Profile/CaseFileActions.cy.tsx

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { mount } from "cypress/react";
22
import CaseFileActions from "@/components/App/CaseFiles/Profile/CaseFileActions";
33
import { QueryClient, QueryClientProvider } from "@tanstack/react-query";
44
import ModalProvider from "@/components/Shared/Modals/ModalProvider";
5+
import { CaseFileStatusEnum } from "@/utils/constants";
6+
import { OidcConfig } from "@/utils/config";
7+
import { AuthProvider } from "react-oidc-context";
58

69
describe("CaseFileActions", () => {
710
let queryClient: QueryClient;
@@ -13,19 +16,21 @@ describe("CaseFileActions", () => {
1316
const mountComponent = (status: string) => {
1417
mount(
1518
<QueryClientProvider client={queryClient}>
16-
<ModalProvider />
17-
<CaseFileActions status={status} fileNumber="CF-123" />
19+
<AuthProvider {...OidcConfig}>
20+
<ModalProvider />
21+
<CaseFileActions status={status} fileNumber="CF-123" />
22+
</AuthProvider>
1823
</QueryClientProvider>
1924
);
2025
};
2126

2227
it("renders menu action dropdown", () => {
23-
mountComponent("open");
28+
mountComponent(CaseFileStatusEnum.OPEN);
2429
cy.contains("button", "Actions").should("exist");
2530
});
2631

2732
it("shows all actions for open case file", () => {
28-
mountComponent("open");
33+
mountComponent(CaseFileStatusEnum.OPEN);
2934
cy.contains("button", "Actions").click();
3035

3136
cy.contains("Link to Case File").should("exist");
@@ -36,7 +41,7 @@ describe("CaseFileActions", () => {
3641
});
3742

3843
it("shows appropriate actions for closed case file", () => {
39-
mountComponent("closed");
44+
mountComponent(CaseFileStatusEnum.CLOSED);
4045
cy.contains("button", "Actions").click();
4146

4247
cy.contains("Link to Case File").should("not.exist");
@@ -47,7 +52,7 @@ describe("CaseFileActions", () => {
4752
});
4853

4954
it("handles Link to Case File click", () => {
50-
mountComponent("open");
55+
mountComponent(CaseFileStatusEnum.OPEN);
5156
cy.contains("button", "Actions").click();
5257
cy.contains("Link to Case File").click();
5358

@@ -59,7 +64,7 @@ describe("CaseFileActions", () => {
5964
});
6065

6166
it("handles Unlink from Case File click", () => {
62-
mountComponent("open");
67+
mountComponent(CaseFileStatusEnum.OPEN);
6368
cy.contains("button", "Actions").click();
6469
cy.contains("Unlink from Case File").click();
6570

@@ -71,7 +76,7 @@ describe("CaseFileActions", () => {
7176
});
7277

7378
it("handles Close Case File click", () => {
74-
mountComponent("open");
79+
mountComponent(CaseFileStatusEnum.OPEN);
7580
cy.contains("button", "Actions").click();
7681
cy.contains("Close Case File").click();
7782

@@ -85,7 +90,7 @@ describe("CaseFileActions", () => {
8590
});
8691

8792
it("handles Delete Case File click", () => {
88-
mountComponent("open");
93+
mountComponent(CaseFileStatusEnum.OPEN);
8994
cy.contains("button", "Actions").click();
9095
cy.contains("Delete Case File").click();
9196

@@ -99,7 +104,7 @@ describe("CaseFileActions", () => {
99104
});
100105

101106
it("handles Reopen Case File click", () => {
102-
mountComponent("closed");
107+
mountComponent(CaseFileStatusEnum.CLOSED);
103108
cy.contains("button", "Actions").click();
104109
cy.contains("Reopen Case File").click();
105110

compliance-web/src/components/App/CaseFiles/Profile/CaseFileActions.tsx

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ import { notify } from "@/store/snackbarStore";
1515
import { useQueryClient } from "@tanstack/react-query";
1616
import { useRouter } from "@tanstack/react-router";
1717
import React, { useCallback } from "react";
18+
import { useAuth } from "react-oidc-context";
19+
import { KC_USER_GROUPS, useIsRolesAllowed } from "@/hooks/useAuthorization";
20+
import { CaseFileStatusEnum } from "@/utils/constants";
1821

1922
interface CaseFileActionsProps {
2023
status: string;
@@ -28,6 +31,8 @@ const CaseFileActions: React.FC<CaseFileActionsProps> = ({
2831
const router = useRouter();
2932
const queryClient = useQueryClient();
3033
const { setOpen, setClose } = useModal();
34+
const { user } = useAuth();
35+
const isSuperUser = useIsRolesAllowed([KC_USER_GROUPS.SUPERUSER]);
3136

3237
const caseFileData = queryClient.getQueryData<CaseFile>([
3338
"case-file",
@@ -38,6 +43,18 @@ const CaseFileActions: React.FC<CaseFileActionsProps> = ({
3843
caseFileData?.id ?? 0
3944
);
4045

46+
const isPrimaryOfficer =
47+
caseFileData?.primary_officer?.auth_user_guid ===
48+
user?.profile?.preferred_username;
49+
50+
const otherAssignedOfficers =
51+
caseFileData?.officers?.map((o) => o?.auth_user_guid) ?? [];
52+
53+
const canLinkOrUnlinkCaseFile =
54+
isSuperUser ||
55+
isPrimaryOfficer ||
56+
otherAssignedOfficers.includes(user?.profile?.preferred_username ?? "");
57+
4158
const closeAndRefresh = useCallback(() => {
4259
queryClient.invalidateQueries({
4360
queryKey: ["case-file", fileNumber],
@@ -147,7 +164,8 @@ const CaseFileActions: React.FC<CaseFileActionsProps> = ({
147164
),
148165
});
149166
},
150-
hidden: status?.toLowerCase() === "closed",
167+
hidden:
168+
status === CaseFileStatusEnum.CLOSED || !canLinkOrUnlinkCaseFile,
151169
},
152170
{
153171
text: "Unlink from Case File",
@@ -169,12 +187,13 @@ const CaseFileActions: React.FC<CaseFileActionsProps> = ({
169187
),
170188
});
171189
},
172-
hidden: status?.toLowerCase() === "closed",
190+
hidden:
191+
status === CaseFileStatusEnum.CLOSED || !canLinkOrUnlinkCaseFile,
173192
},
174193
{
175194
text: "Close Case File",
176195
onClick: closeCaseFile,
177-
hidden: status?.toLowerCase() === "closed",
196+
hidden: status === CaseFileStatusEnum.CLOSED,
178197
},
179198
{
180199
text: "Reopen Case File",
@@ -196,7 +215,7 @@ const CaseFileActions: React.FC<CaseFileActionsProps> = ({
196215
),
197216
});
198217
},
199-
hidden: status?.toLowerCase() === "open",
218+
hidden: status === CaseFileStatusEnum.OPEN,
200219
},
201220
{
202221
text: "Delete Case File",

compliance-web/src/utils/constants.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,11 @@ export enum ComplaintStatusEnum {
201201
CLOSED = "Closed",
202202
}
203203

204+
export enum CaseFileStatusEnum {
205+
OPEN = "Open",
206+
CLOSED = "Closed",
207+
}
208+
204209
export const APReferralStatus = {
205210
DRAFTING: { id: "DRAFTING", name: "Drafting" },
206211
DEPUTY_REVIEW: { id: "DEPUTY_REVIEW", name: "Deputy Review" },

0 commit comments

Comments
 (0)