[FEAT] Remove users_can_delete_workspaces feature (#1742)

remove all references to users_can_delete_workspaces option
This commit is contained in:
Sean Hatfield 2024-06-25 16:46:06 -07:00 committed by GitHub
parent b5ac62ff9f
commit 77916d920b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
14 changed files with 30 additions and 112 deletions

View File

@ -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",

View File

@ -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",

View File

@ -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",

View File

@ -78,6 +78,9 @@ const TRANSLATIONS = {
remove: "Удалить изображение рабочего пространства",
},
delete: {
title: "Удалить Рабочее Пространство",
description:
"Удалите это рабочее пространство и все его данные. Это удалит рабочее пространство для всех пользователей.",
delete: "Удалить рабочее пространство",
deleting: "Удаление рабочего пространства...",
"confirm-start": "Вы собираетесь удалить весь ваш",

View File

@ -84,6 +84,8 @@ const TRANSLATIONS = {
remove: "移除工作区图像",
},
delete: {
title: "删除工作区",
description: "删除此工作区及其所有数据。这将删除所有用户的工作区。",
delete: "删除工作区",
deleting: "正在删除工作区...",
"confirm-start": "您即将删除整个",

View File

@ -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",

View File

@ -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() {
</div>
)}
<div className="mt-4 mb-8">
<div className="flex flex-col gap-y-1">
<h2 className="text-base leading-6 font-bold text-white">
Users can delete workspaces
</h2>
<p className="text-xs leading-[18px] font-base text-white/60">
Allow non-admin users to delete workspaces that they are a part
of. This would delete the workspace for everyone.
</p>
<label className="relative inline-flex cursor-pointer items-center mt-2">
<input
type="checkbox"
name="users_can_delete_workspaces"
checked={canDelete}
onChange={(e) => setCanDelete(e.target.checked)}
className="peer sr-only"
/>
<div className="pointer-events-none peer h-6 w-11 rounded-full bg-stone-400 after:absolute after:left-[2px] after:top-[2px] after:h-5 after:w-5 after:rounded-full after:shadow-xl after:border after:border-gray-600 after:bg-white after:box-shadow-md after:transition-all after:content-[''] peer-checked:bg-lime-300 peer-checked:after:translate-x-full peer-checked:after:border-white peer-focus:outline-none peer-focus:ring-4 peer-focus:ring-blue-800"></div>
<span className="ml-3 text-sm font-medium text-gray-900 dark:text-gray-300"></span>
</label>
</div>
</div>
<div className="mb-8">
<div className="flex flex-col gap-y-1">
<h2 className="text-base leading-6 font-bold text-white">
Limit messages per user per day

View File

@ -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 (
<button
disabled={deleting}
onClick={deleteWorkspace}
type="button"
className="w-60 mt-[40px] transition-all duration-300 border border-transparent rounded-lg whitespace-nowrap text-sm px-5 py-2.5 focus:z-10 bg-red-500/25 text-red-200 hover:text-white hover:bg-red-600 disabled:bg-red-600 disabled:text-red-200 disabled:animate-pulse"
>
{deleting ? t("general.delete.deleting") : t("general.delete.delete")}
</button>
<div className="flex flex-col mt-10">
<label className="block input-label">{t("general.delete.title")}</label>
<p className="text-white text-opacity-60 text-xs font-medium py-1.5">
{t("general.delete.description")}
</p>
<button
disabled={deleting}
onClick={deleteWorkspace}
type="button"
className="w-60 mt-4 transition-all duration-300 border border-transparent rounded-lg whitespace-nowrap text-sm px-5 py-2.5 focus:z-10 bg-red-500/25 text-red-200 hover:text-white hover:bg-red-600 disabled:bg-red-600 disabled:text-red-200 disabled:animate-pulse"
>
{deleting ? t("general.delete.deleting") : t("general.delete.delete")}
</button>
</div>
);
}

View File

@ -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",

View File

@ -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,
}

View File

@ -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])],

View File

@ -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");

View File

@ -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" },

View File

@ -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
}