From 6ea645f3581c35db6925d91538c24e4a18acd7b5 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Wed, 30 Aug 2023 15:28:30 -0700 Subject: [PATCH] Hide delete workspace button on non-admin users if setting is disabled (#227) * hide delete workspace button on non-admin users if setting is disabled --------- Co-authored-by: Timothy Carambat --- .../Modals/MangeWorkspace/Documents/index.jsx | 18 ++++++------ frontend/src/models/system.js | 16 +++++++++++ server/endpoints/system.js | 28 +++++++++++++++++++ server/models/systemSettings.js | 6 ++++ 4 files changed, 60 insertions(+), 8 deletions(-) diff --git a/frontend/src/components/Modals/MangeWorkspace/Documents/index.jsx b/frontend/src/components/Modals/MangeWorkspace/Documents/index.jsx index 167a8cbf..3dcfd337 100644 --- a/frontend/src/components/Modals/MangeWorkspace/Documents/index.jsx +++ b/frontend/src/components/Modals/MangeWorkspace/Documents/index.jsx @@ -16,6 +16,7 @@ export default function DocumentSettings({ workspace }) { const [originalDocuments, setOriginalDocuments] = useState([]); const [selectedFiles, setSelectFiles] = useState([]); const [hasFiles, setHasFiles] = useState(true); + const [canDelete, setCanDelete] = useState(false); useEffect(() => { async function fetchKeys() { @@ -24,6 +25,9 @@ export default function DocumentSettings({ workspace }) { const hasAnyFiles = localFiles.items.some( (folder) => folder?.items?.length > 0 ); + + const canDelete = await System.getCanDeleteWorkspaces(); + setCanDelete(canDelete); setDirectories(localFiles); setOriginalDocuments([...originalDocs]); setSelectFiles([...originalDocs]); @@ -92,13 +96,6 @@ export default function DocumentSettings({ workspace }) { : selectedFiles.some((doc) => doc.includes(filepath)); }; - const isOriginalDoc = (filepath) => { - const isFolder = !filepath.includes("/"); - return isFolder - ? originalDocuments.some((doc) => doc.includes(filepath.split("/")[0])) - : originalDocuments.some((doc) => doc.includes(filepath)); - }; - const toggleSelection = (filepath) => { const isFolder = !filepath.includes("/"); const parent = isFolder ? filepath : filepath.split("/")[0]; @@ -179,14 +176,19 @@ export default function DocumentSettings({ workspace }) { -
+
+