From 77916d920b0562f41534630c9471ec21dcac9632 Mon Sep 17 00:00:00 2001 From: Sean Hatfield Date: Tue, 25 Jun 2024 16:46:06 -0700 Subject: [PATCH] [FEAT] Remove users_can_delete_workspaces feature (#1742) remove all references to users_can_delete_workspaces option --- frontend/src/locales/en/common.js | 3 ++ frontend/src/locales/es/common.js | 3 ++ frontend/src/locales/fr/common.js | 3 ++ frontend/src/locales/ru/common.js | 3 ++ frontend/src/locales/zh/common.js | 2 ++ frontend/src/models/system.js | 16 --------- frontend/src/pages/Admin/System/index.jsx | 26 -------------- .../DeleteWorkspace/index.jsx | 36 +++++++++---------- server/endpoints/admin.js | 3 -- server/endpoints/api/admin/index.js | 5 --- server/endpoints/system.js | 28 --------------- server/models/systemSettings.js | 11 ------ server/prisma/seed.js | 1 - server/swagger/openapi.json | 2 -- 14 files changed, 30 insertions(+), 112 deletions(-) diff --git a/frontend/src/locales/en/common.js b/frontend/src/locales/en/common.js index 5254e3bd..a851f4cf 100644 --- a/frontend/src/locales/en/common.js +++ b/frontend/src/locales/en/common.js @@ -85,6 +85,9 @@ const TRANSLATIONS = { remove: "Remove Workspace Image", }, delete: { + title: "Delete Workspace", + description: + "Delete this workspace and all of its data. This will delete the workspace for all users.", delete: "Delete Workspace", deleting: "Deleting Workspace...", "confirm-start": "You are about to delete your entire", diff --git a/frontend/src/locales/es/common.js b/frontend/src/locales/es/common.js index d0609e9a..5dc2daad 100644 --- a/frontend/src/locales/es/common.js +++ b/frontend/src/locales/es/common.js @@ -82,6 +82,9 @@ const TRANSLATIONS = { remove: "Eliminar imagen del espacio de trabajo", }, delete: { + title: "Eliminar Espacio de Trabajo", + description: + "Eliminar este espacio de trabajo y todos sus datos. Esto eliminará el espacio de trabajo para todos los usuarios.", delete: "Eliminar espacio de trabajo", deleting: "Eliminando espacio de trabajo...", "confirm-start": "Estás a punto de eliminar tu", diff --git a/frontend/src/locales/fr/common.js b/frontend/src/locales/fr/common.js index 9e7a82e8..71c37a7e 100644 --- a/frontend/src/locales/fr/common.js +++ b/frontend/src/locales/fr/common.js @@ -87,6 +87,9 @@ const TRANSLATIONS = { remove: "Supprimer l'image de l'espace de travail", }, delete: { + title: "Supprimer l'Espace de Travail", + description: + "Supprimer cet espace de travail et toutes ses données. Cela supprimera l'espace de travail pour tous les utilisateurs.", delete: "Supprimer l'espace de travail", deleting: "Suppression de l'espace de travail...", "confirm-start": "Vous êtes sur le point de supprimer votre", diff --git a/frontend/src/locales/ru/common.js b/frontend/src/locales/ru/common.js index 34f9591c..da3b49f1 100644 --- a/frontend/src/locales/ru/common.js +++ b/frontend/src/locales/ru/common.js @@ -78,6 +78,9 @@ const TRANSLATIONS = { remove: "Удалить изображение рабочего пространства", }, delete: { + title: "Удалить Рабочее Пространство", + description: + "Удалите это рабочее пространство и все его данные. Это удалит рабочее пространство для всех пользователей.", delete: "Удалить рабочее пространство", deleting: "Удаление рабочего пространства...", "confirm-start": "Вы собираетесь удалить весь ваш", diff --git a/frontend/src/locales/zh/common.js b/frontend/src/locales/zh/common.js index 0f30c4f7..476533d1 100644 --- a/frontend/src/locales/zh/common.js +++ b/frontend/src/locales/zh/common.js @@ -84,6 +84,8 @@ const TRANSLATIONS = { remove: "移除工作区图像", }, delete: { + title: "删除工作区", + description: "删除此工作区及其所有数据。这将删除所有用户的工作区。", delete: "删除工作区", deleting: "正在删除工作区...", "confirm-start": "您即将删除整个", diff --git a/frontend/src/models/system.js b/frontend/src/models/system.js index d6c724b7..095244a4 100644 --- a/frontend/src/models/system.js +++ b/frontend/src/models/system.js @@ -420,22 +420,6 @@ const System = { return { success: false, error: e.message }; }); }, - getCanDeleteWorkspaces: async function () { - return await fetch(`${API_BASE}/system/can-delete-workspaces`, { - method: "GET", - cache: "no-cache", - headers: baseHeaders(), - }) - .then((res) => { - if (!res.ok) throw new Error("Could not fetch can delete workspaces."); - return res.json(); - }) - .then((res) => res?.canDelete) - .catch((e) => { - console.error(e); - return false; - }); - }, getWelcomeMessages: async function () { return await fetch(`${API_BASE}/system/welcome-messages`, { method: "GET", diff --git a/frontend/src/pages/Admin/System/index.jsx b/frontend/src/pages/Admin/System/index.jsx index bdab765a..3924c6e8 100644 --- a/frontend/src/pages/Admin/System/index.jsx +++ b/frontend/src/pages/Admin/System/index.jsx @@ -8,7 +8,6 @@ import CTAButton from "@/components/lib/CTAButton"; export default function AdminSystem() { const [saving, setSaving] = useState(false); const [hasChanges, setHasChanges] = useState(false); - const [canDelete, setCanDelete] = useState(false); const [messageLimit, setMessageLimit] = useState({ enabled: false, limit: 10, @@ -18,7 +17,6 @@ export default function AdminSystem() { e.preventDefault(); setSaving(true); await Admin.updateSystemPreferences({ - users_can_delete_workspaces: canDelete, limit_user_messages: messageLimit.enabled, message_limit: messageLimit.limit, }); @@ -31,7 +29,6 @@ export default function AdminSystem() { async function fetchSettings() { const settings = (await Admin.systemPreferences())?.settings; if (!settings) return; - setCanDelete(settings?.users_can_delete_workspaces); setMessageLimit({ enabled: settings.limit_user_messages, limit: settings.message_limit, @@ -71,29 +68,6 @@ export default function AdminSystem() { )}
-
-

- Users can delete workspaces -

-

- Allow non-admin users to delete workspaces that they are a part - of. This would delete the workspace for everyone. -

- -
-
- -

Limit messages per user per day diff --git a/frontend/src/pages/WorkspaceSettings/GeneralAppearance/DeleteWorkspace/index.jsx b/frontend/src/pages/WorkspaceSettings/GeneralAppearance/DeleteWorkspace/index.jsx index 32a3eaa4..44c7127a 100644 --- a/frontend/src/pages/WorkspaceSettings/GeneralAppearance/DeleteWorkspace/index.jsx +++ b/frontend/src/pages/WorkspaceSettings/GeneralAppearance/DeleteWorkspace/index.jsx @@ -1,22 +1,14 @@ -import { useEffect, useState } from "react"; +import { useState } from "react"; import { useParams } from "react-router-dom"; import Workspace from "@/models/workspace"; import paths from "@/utils/paths"; -import System from "@/models/system"; import { useTranslation } from "react-i18next"; +import showToast from "@/utils/toast"; export default function DeleteWorkspace({ workspace }) { const { slug } = useParams(); const [deleting, setDeleting] = useState(false); - const [canDelete, setCanDelete] = useState(false); const { t } = useTranslation(); - useEffect(() => { - async function fetchKeys() { - const canDelete = await System.getCanDeleteWorkspaces(); - setCanDelete(canDelete); - } - fetchKeys(); - }, [workspace?.slug]); const deleteWorkspace = async () => { if ( @@ -40,16 +32,20 @@ export default function DeleteWorkspace({ workspace }) { ? (window.location = paths.home()) : window.location.reload(); }; - - if (!canDelete) return null; return ( - +
+ +

+ {t("general.delete.description")} +

+ +
); } diff --git a/server/endpoints/admin.js b/server/endpoints/admin.js index 67d7210f..d7cab1f5 100644 --- a/server/endpoints/admin.js +++ b/server/endpoints/admin.js @@ -319,9 +319,6 @@ function adminEndpoints(app) { try { const embedder = getEmbeddingEngineSelection(); const settings = { - users_can_delete_workspaces: - (await SystemSettings.get({ label: "users_can_delete_workspaces" })) - ?.value === "true", limit_user_messages: (await SystemSettings.get({ label: "limit_user_messages" })) ?.value === "true", diff --git a/server/endpoints/api/admin/index.js b/server/endpoints/api/admin/index.js index 600d3636..dd47f374 100644 --- a/server/endpoints/api/admin/index.js +++ b/server/endpoints/api/admin/index.js @@ -616,7 +616,6 @@ function apiAdminEndpoints(app) { type: 'object', example: { settings: { - users_can_delete_workspaces: true, limit_user_messages: false, message_limit: 10, } @@ -641,9 +640,6 @@ function apiAdminEndpoints(app) { } const settings = { - users_can_delete_workspaces: - (await SystemSettings.get({ label: "users_can_delete_workspaces" })) - ?.value === "true", limit_user_messages: (await SystemSettings.get({ label: "limit_user_messages" })) ?.value === "true", @@ -673,7 +669,6 @@ function apiAdminEndpoints(app) { content: { "application/json": { example: { - users_can_delete_workspaces: false, limit_user_messages: true, message_limit: 5, } diff --git a/server/endpoints/system.js b/server/endpoints/system.js index 1849a2fc..05a24e5c 100644 --- a/server/endpoints/system.js +++ b/server/endpoints/system.js @@ -479,7 +479,6 @@ function systemEndpoints(app) { }); await SystemSettings._updateSettings({ multi_user_mode: true, - users_can_delete_workspaces: false, limit_user_messages: false, message_limit: 25, }); @@ -776,33 +775,6 @@ function systemEndpoints(app) { } ); - app.get( - "/system/can-delete-workspaces", - [validatedRequest], - async function (request, response) { - try { - if (!response.locals.multiUserMode) { - return response.status(200).json({ canDelete: true }); - } - - const user = await userFromSession(request, response); - if ([ROLES.admin, ROLES.manager].includes(user?.role)) { - return response.status(200).json({ canDelete: true }); - } - - const canDelete = await SystemSettings.canDeleteWorkspaces(); - response.status(200).json({ canDelete }); - } catch (error) { - console.error("Error fetching can delete workspaces:", error); - response.status(500).json({ - success: false, - message: "Internal server error", - canDelete: false, - }); - } - } - ); - app.get( "/system/welcome-messages", [validatedRequest, flexUserRoleValid([ROLES.all])], diff --git a/server/models/systemSettings.js b/server/models/systemSettings.js index 3f44f722..ea1dd01e 100644 --- a/server/models/systemSettings.js +++ b/server/models/systemSettings.js @@ -15,7 +15,6 @@ function isNullOrNaN(value) { const SystemSettings = { protectedFields: ["multi_user_mode"], supportedFields: [ - "users_can_delete_workspaces", "limit_user_messages", "message_limit", "logo_filename", @@ -302,16 +301,6 @@ const SystemSettings = { } }, - canDeleteWorkspaces: async function () { - try { - const setting = await this.get({ label: "users_can_delete_workspaces" }); - return setting?.value === "true"; - } catch (error) { - console.error(error.message); - return false; - } - }, - hasEmbeddings: async function () { try { const { Document } = require("./documents"); diff --git a/server/prisma/seed.js b/server/prisma/seed.js index 829b812a..c58e4556 100644 --- a/server/prisma/seed.js +++ b/server/prisma/seed.js @@ -4,7 +4,6 @@ const prisma = new PrismaClient(); async function main() { const settings = [ { label: "multi_user_mode", value: "false" }, - { label: "users_can_delete_workspaces", value: "false" }, { label: "limit_user_messages", value: "false" }, { label: "message_limit", value: "25" }, { label: "logo_filename", value: "anything-llm.png" }, diff --git a/server/swagger/openapi.json b/server/swagger/openapi.json index 2b5ee82e..571fef59 100644 --- a/server/swagger/openapi.json +++ b/server/swagger/openapi.json @@ -710,7 +710,6 @@ "type": "object", "example": { "settings": { - "users_can_delete_workspaces": true, "limit_user_messages": false, "message_limit": 10 } @@ -792,7 +791,6 @@ "content": { "application/json": { "example": { - "users_can_delete_workspaces": false, "limit_user_messages": true, "message_limit": 5 }