From 1e24d52050d1fd7c2b773413bf6074f29772425c Mon Sep 17 00:00:00 2001
From: 0tuedon <90271995+0tuedon@users.noreply.github.com>
Date: Wed, 3 Jul 2024 15:00:37 +0100
Subject: [PATCH] Evaluator role access (#296)
---
.eslintrc.json | 3 +-
.../editTranscript/EditTranscript.tsx | 21 +++++----
src/components/navbar/AdminMenu.tsx | 12 +++--
src/components/navbar/Menu.tsx | 44 +++++++++++--------
src/components/tables/AdminReviewsTable.tsx | 6 ++-
src/components/tables/TableItems.tsx | 8 ++--
src/config/default.ts | 5 ---
src/config/permissions.json | 27 ++++++++++++
src/hooks/useHasPermissions.ts | 20 +++++++++
src/pages/admin/reviews.tsx | 11 ++---
src/pages/admin/transactions.tsx | 13 +++---
src/pages/admin/users.tsx | 12 ++---
types.ts | 8 +++-
13 files changed, 122 insertions(+), 68 deletions(-)
create mode 100644 src/config/permissions.json
create mode 100644 src/hooks/useHasPermissions.ts
diff --git a/.eslintrc.json b/.eslintrc.json
index a8e3ffbb..979a6243 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -15,6 +15,7 @@
"no-console": ["warn", { "allow": ["warn", "error"] }],
"no-unused-vars": ["warn", { "vars": "all", "args": "none", "ignoreRestSiblings": false }],
"eol-last": ["error", "always"],
- "react/react-in-jsx-scope": "off"
+ "react/react-in-jsx-scope": "off",
+ "react/display-name": "off"
}
}
diff --git a/src/components/editTranscript/EditTranscript.tsx b/src/components/editTranscript/EditTranscript.tsx
index ad0743e6..1b22135e 100644
--- a/src/components/editTranscript/EditTranscript.tsx
+++ b/src/components/editTranscript/EditTranscript.tsx
@@ -29,9 +29,8 @@ import SubmitTranscriptMenu, {
TranscriptSubmitOptions,
} from "../menus/SubmitTranscriptMenu";
import { TranscriptContent, UserReviewData } from "../../../types";
-import { useSession } from "next-auth/react";
import { useUpdateTranscript } from "@/services/api/transcripts";
-
+import { useHasPermission } from "@/hooks/useHasPermissions";
// Interfaces for react-markdown-editior
export interface IHandleEditorChange {
text: string;
@@ -74,15 +73,15 @@ const EditTranscript = ({
onOpen: () => void;
}) => {
const [isPreviewOnly, setIsPreviewOnly] = useState(false);
- const [isModalOpen, setIsModalopen] = useState(false);
+ const [isModalOpen, setIsModalOpen] = useState(false);
const toast = useToast();
const mdParser = new MarkdownIt();
const reviewSubmissionDisabled =
!!reviewData.branchUrl && !!reviewData.pr_url;
- const { data: userSession } = useSession();
- const isAdmin = userSession?.user?.permissions === "admin";
+ const canSubmitToOwnRepo = useHasPermission("submitToOwnRepo");
+
const { isLoading: saveLoading } = useUpdateTranscript();
const handleSave = async () => {
@@ -149,7 +148,7 @@ const EditTranscript = ({
// restoreOriginal content function
const onClickRestore = () => {
restoreOriginal();
- setIsModalopen(false);
+ setIsModalOpen(false);
};
return (
@@ -180,7 +179,7 @@ const EditTranscript = ({
- {isAdmin && (
+ {canSubmitToOwnRepo && (
<>
>
@@ -237,7 +236,7 @@ const EditTranscript = ({
/>
- setIsModalopen(false)}>
+ setIsModalOpen(false)}>
@@ -253,7 +252,7 @@ const EditTranscript = ({