Skip to content
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

CRDCDH-1632 Data Curator Data Commons assignment #472

Merged
merged 3 commits into from
Sep 23, 2024
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
3 changes: 1 addition & 2 deletions src/config/AuthRoles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<UserRole, "Admin" | "Data Curator" | "Federal Lead" | "Federal Monitor">;
type RoleSubset = Extends<UserRole, "Admin" | "Federal Lead" | "Federal Monitor">;
export const OrgAssignmentMap: Record<RoleSubset, string> = {
Admin: "FNL",
"Data Curator": "FNL",
"Federal Lead": "NCI",
"Federal Monitor": "NCI",
};
Expand Down
2 changes: 1 addition & 1 deletion src/content/users/ProfileView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -443,7 +443,7 @@ const ProfileView: FC<Props> = ({ _id, viewType }: Props) => {
user.userStatus
)}
</StyledField>
<StyledField>
<StyledField visible={fieldset.organization !== "HIDDEN"}>
<StyledLabel id="userOrganizationLabel">Organization</StyledLabel>
{visibleFieldState.includes(fieldset.organization) ? (
<Controller
Expand Down
39 changes: 33 additions & 6 deletions src/hooks/useProfileFields.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Users View", () => {
);

// NOTE: This list is derived from the OrgAssignmentMap in src/config/AuthRoles.ts
it.each<UserRole>(["Admin", "Data Curator", "Federal Lead", "Federal Monitor"])(
it.each<UserRole>(["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;
Expand Down Expand Up @@ -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<User, "_id" | "role"> = { _id: "I-Am-User-B", role };
Expand All @@ -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<User, "_id" | "role"> = { _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<User, "_id" | "role"> = { _id: "I-Am-User-B", role: "Submitter" };
Expand Down Expand Up @@ -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<User, "_id" | "role"> = { _id: "User-A", role };
Expand Down Expand Up @@ -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, "_id" | "role"> = { ...user };

jest.spyOn(Auth, "useAuthContext").mockReturnValue({ user } as Auth.ContextState);

const { result } = renderHook(() => useProfileFields(profileOf, "profile"));

expect(result.current.organization).toBe("HIDDEN");
});
});
7 changes: 6 additions & 1 deletion src/hooks/useProfileFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down
Loading