From f8c9ced3725b0fa4fe5e8cde79a98b5091edb7c4 Mon Sep 17 00:00:00 2001 From: Alec M Date: Thu, 19 Sep 2024 16:27:23 -0400 Subject: [PATCH] CRDCDH-1632 Support Data Curator Data Commons assignment --- src/config/AuthRoles.ts | 3 +-- src/content/users/ProfileView.tsx | 2 +- src/hooks/useProfileFields.test.ts | 39 +++++++++++++++++++++++++----- src/hooks/useProfileFields.ts | 7 +++++- 4 files changed, 41 insertions(+), 10 deletions(-) diff --git a/src/config/AuthRoles.ts b/src/config/AuthRoles.ts index d9b85caf..8f435fec 100644 --- a/src/config/AuthRoles.ts +++ b/src/config/AuthRoles.ts @@ -26,10 +26,9 @@ export const OrgRequiredRoles: UserRole[] = ["Submitter", "Organization Owner", * * @note This requires that an organization with the specified name exists in the database. */ -type RoleSubset = Extends; +type RoleSubset = Extends; export const OrgAssignmentMap: Record = { Admin: "FNL", - "Data Curator": "FNL", "Federal Lead": "NCI", "Federal Monitor": "NCI", }; diff --git a/src/content/users/ProfileView.tsx b/src/content/users/ProfileView.tsx index 590717aa..9955adb7 100644 --- a/src/content/users/ProfileView.tsx +++ b/src/content/users/ProfileView.tsx @@ -443,7 +443,7 @@ const ProfileView: FC = ({ _id, viewType }: Props) => { user.userStatus )} - + Organization {visibleFieldState.includes(fieldset.organization) ? ( { ); // NOTE: This list is derived from the OrgAssignmentMap in src/config/AuthRoles.ts - it.each(["Admin", "Data Curator", "Federal Lead", "Federal Monitor"])( + it.each(["Admin", "Federal Lead", "Federal Monitor"])( "should return DISABLED for organization when viewing the role %s", (role) => { const user = { _id: "User-A", role: "Admin" } as User; @@ -89,11 +89,11 @@ describe("Users View", () => { ["HIDDEN", "Submitter"], ["HIDDEN", "Organization Owner"], ["HIDDEN", "Federal Lead"], - ["HIDDEN", "Data Curator"], + ["UNLOCKED", "Data Curator"], // NOTE: accepts Data Commons ["HIDDEN", "Admin"], ["HIDDEN", "fake role" as UserRole], ["HIDDEN", "Federal Monitor"], - ["UNLOCKED", "Data Commons POC"], // NOTE: Only this role accepts studies + ["UNLOCKED", "Data Commons POC"], // NOTE: accepts Data Commons ])("should return %s for the dataCommons field on the users page for role %s", (state, role) => { const user = { _id: "User-A", role: "Admin" } as User; const profileOf: Pick = { _id: "I-Am-User-B", role }; @@ -105,6 +105,17 @@ describe("Users View", () => { expect(result.current.dataCommons).toBe(state); }); + it("should return HIDDEN organization field for an Admin viewing a Data Curator profile", () => { + const user = { _id: "User-A", role: "Admin" } as User; + const profileOf: Pick = { _id: "Not-User-a", role: "Data Curator" }; + + jest.spyOn(Auth, "useAuthContext").mockReturnValue({ user } as Auth.ContextState); + + const { result } = renderHook(() => useProfileFields(profileOf, "users")); + + expect(result.current.organization).toBe("HIDDEN"); + }); + it("should always return READ_ONLY for the firstName and lastName fields on the users page", () => { const user = { _id: "User-A", role: "Admin" } as User; const profileOf: Pick = { _id: "I-Am-User-B", role: "Submitter" }; @@ -166,10 +177,15 @@ describe("Profile View", () => { }); it.each<[state: FieldState, role: UserRole]>([ + ["HIDDEN", "User"], ["HIDDEN", "Submitter"], - ["HIDDEN", "Data Curator"], - ["HIDDEN", "fake user" as UserRole], - ["READ_ONLY", "Data Commons POC"], // NOTE: Only one with this field visible + ["HIDDEN", "Organization Owner"], + ["HIDDEN", "Federal Lead"], + ["READ_ONLY", "Data Curator"], // NOTE: Data Commons visible but read-only + ["HIDDEN", "Admin"], + ["HIDDEN", "fake role" as UserRole], + ["HIDDEN", "Federal Monitor"], + ["READ_ONLY", "Data Commons POC"], // NOTE: Data Commons visible but read-only ])("should return %s for the dataCommons field for the role %s", (state, role) => { const user = { _id: "User-A", role } as User; const profileOf: Pick = { _id: "User-A", role }; @@ -224,4 +240,15 @@ describe("Profile View", () => { expect(result.current.dataCommons).toBe("READ_ONLY"); }); + + it("should return HIDDEN organization field for a Data Curator viewing their own profile", () => { + const user = { _id: "User-A", role: "Data Curator" } as User; + const profileOf: Pick = { ...user }; + + jest.spyOn(Auth, "useAuthContext").mockReturnValue({ user } as Auth.ContextState); + + const { result } = renderHook(() => useProfileFields(profileOf, "profile")); + + expect(result.current.organization).toBe("HIDDEN"); + }); }); diff --git a/src/hooks/useProfileFields.ts b/src/hooks/useProfileFields.ts index 0d914c17..20c772f9 100644 --- a/src/hooks/useProfileFields.ts +++ b/src/hooks/useProfileFields.ts @@ -72,12 +72,17 @@ const useProfileFields = ( } // Only applies to Data Commons POC - if (profileOf?.role === "Data Commons POC") { + if (profileOf?.role === "Data Commons POC" || profileOf?.role === "Data Curator") { fields.dataCommons = user?.role === "Admin" && viewType === "users" ? "UNLOCKED" : "READ_ONLY"; } else { fields.dataCommons = "HIDDEN"; } + // Only applies to Data Curator + if (profileOf?.role === "Data Curator") { + fields.organization = "HIDDEN"; + } + return fields; };