From 5e59e707cc2a2f5546b334c4fbb023ca04a06a94 Mon Sep 17 00:00:00 2001
From: Antoine Dewez <44063631+Zewed@users.noreply.github.com>
Date: Fri, 23 Aug 2024 12:33:18 +0200
Subject: [PATCH] fix(frontend): only owner can access knowledge and edit brain
snippet (#3073)
# Description
Please include a summary of the changes and the related issue. Please
also include relevant motivation and context.
## Checklist before requesting a review
Please delete options that are not relevant.
- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented hard-to-understand areas
- [ ] I have ideally added tests that prove my fix is effective or that
my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged
## Screenshots (if appropriate):
---
.../BrainManagementTabs.tsx | 29 +++++--------
.../components/KnowledgeTab/KnowledgeTab.tsx | 14 +++++++
.../SettingsTab/SettingsTab.module.scss | 7 +++-
.../components/SettingsTab/SettingsTab.tsx | 41 +++++++++++--------
4 files changed, 53 insertions(+), 38 deletions(-)
diff --git a/frontend/app/studio/[brainId]/BrainManagementTabs/BrainManagementTabs.tsx b/frontend/app/studio/[brainId]/BrainManagementTabs/BrainManagementTabs.tsx
index 6c75fc6b6..69db87470 100644
--- a/frontend/app/studio/[brainId]/BrainManagementTabs/BrainManagementTabs.tsx
+++ b/frontend/app/studio/[brainId]/BrainManagementTabs/BrainManagementTabs.tsx
@@ -1,7 +1,7 @@
/* eslint-disable max-lines */
import { useRouter } from "next/navigation";
-import { useEffect, useState } from "react";
+import { useState } from "react";
import { Icon } from "@/lib/components/ui/Icon/Icon";
import { LoaderIcon } from "@/lib/components/ui/LoaderIcon/LoaderIcon";
@@ -22,27 +22,20 @@ export const BrainManagementTabs = (): JSX.Element => {
const { allKnowledge } = useAddedKnowledge({ brainId: brainId ?? undefined });
const router = useRouter();
- const { brain, isLoading } = useBrainFetcher({
+ const { isLoading } = useBrainFetcher({
brainId,
});
- const knowledgeTabDisabled = (): boolean => {
- return (
- !hasEditRights ||
- (brain?.integration_description?.max_files === 0 &&
- brain.brain_type !== "doc")
- );
- };
-
const brainManagementTabs: Tab[] = [
{
- label: `Knowledge${allKnowledge.length > 1 ? "s" : ""} (${
- allKnowledge.length
- })`,
+ label: hasEditRights
+ ? `Knowledge${allKnowledge.length > 1 ? "s" : ""} (${
+ allKnowledge.length
+ })`
+ : "Knowledge",
isSelected: selectedTab === "Knowledge",
onClick: () => setSelectedTab("Knowledge"),
iconName: "file",
- disabled: knowledgeTabDisabled(),
},
{
label: "Settings",
@@ -59,10 +52,6 @@ export const BrainManagementTabs = (): JSX.Element => {
},
];
- useEffect(() => {
- brainManagementTabs[2].disabled = knowledgeTabDisabled();
- }, [hasEditRights]);
-
if (!brainId) {
return
;
}
@@ -89,7 +78,9 @@ export const BrainManagementTabs = (): JSX.Element => {
- {selectedTab === "Settings" && }
+ {selectedTab === "Settings" && (
+
+ )}
{selectedTab === "People" && }
{selectedTab === "Knowledge" && (
{
const { isPending } = useAddedKnowledge({
brainId,
});
const { setShouldDisplayFeedCard } = useKnowledgeToFeedContext();
+ if (hasEditRights) {
+ return (
+
+
+
+ You don't have permission to access the knowledge in this
+ brain.
+
+
+
+ );
+ }
+
if (isPending) {
return ;
}
diff --git a/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.module.scss b/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.module.scss
index 53ce2a2cc..a41f6b25f 100644
--- a/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.module.scss
+++ b/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.module.scss
@@ -61,7 +61,6 @@
display: flex;
justify-content: center;
align-items: center;
- cursor: pointer;
font-size: Typography.$very_large;
}
@@ -72,6 +71,12 @@
font-size: Typography.$small;
gap: Spacings.$spacing03;
}
+
+ &.clickable {
+ .brain_snippet {
+ cursor: pointer;
+ }
+ }
}
.general_information {
diff --git a/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.tsx b/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.tsx
index 21d6d264d..09c88cb9a 100644
--- a/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.tsx
+++ b/frontend/app/studio/[brainId]/BrainManagementTabs/components/SettingsTab/SettingsTab.tsx
@@ -14,7 +14,6 @@ import { GeneralInformation } from "./components/GeneralInformation/GeneralInfor
import { ModelSelection } from "./components/ModelSelection/ModelSelection";
import { Prompt } from "./components/Prompt/Prompt";
import { useBrainFormState } from "./hooks/useBrainFormState";
-import { usePermissionsController } from "./hooks/usePermissionsController";
import { UsePromptProps } from "./hooks/usePrompt";
import { useSettingsTab } from "./hooks/useSettingsTab";
@@ -22,20 +21,18 @@ import { useBrainFetcher } from "../../hooks/useBrainFetcher";
type SettingsTabProps = {
brainId: UUID;
+ hasEditRights: boolean;
};
export const SettingsTabContent = ({
brainId,
+ hasEditRights,
}: SettingsTabProps): JSX.Element => {
const { t } = useTranslation(["translation", "brain", "config"]);
const [editSnippet, setEditSnippet] = useState(false);
const [snippetColor, setSnippetColor] = useState("");
const [snippetEmoji, setSnippetEmoji] = useState("");
- const { hasEditRights } = usePermissionsController({
- brainId,
- });
-
const { brain } = useBrainFetcher({
brainId,
});
@@ -81,7 +78,11 @@ export const SettingsTabContent = ({
{editSnippet && (
-
+
{
- if (!editSnippet) {
+ if (!editSnippet && hasEditRights) {
setEditSnippet(true);
}
}}
>
{snippetEmoji}
-
setEditSnippet(true)}
- small={true}
- />
+ {hasEditRights && (
+ setEditSnippet(true)}
+ small={true}
+ />
+ )}
- {(!!brain.integration_description?.allow_model_change ||
- brain.brain_type === "doc") && (
+ {brain.brain_type === "doc" && (
{
+export const SettingsTab = ({
+ brainId,
+ hasEditRights,
+}: SettingsTabProps): JSX.Element => {
const methods = useForm();
return (
-
+
);
};