From 580965df173cfccd35cf4f94aaec06f676ecad90 Mon Sep 17 00:00:00 2001 From: Timothy Jaeryang Baek Date: Mon, 31 Mar 2025 17:28:25 -0700 Subject: [PATCH] feat: public sharing permissions Co-Authored-By: Taylor Wilsdon <6508528+taylorwilsdon@users.noreply.github.com> --- .../Knowledge/CreateKnowledgeBase.svelte | 8 +++- .../workspace/Knowledge/KnowledgeBase.svelte | 3 +- .../workspace/Models/ModelEditor.svelte | 6 ++- .../workspace/Prompts/PromptEditor.svelte | 2 + .../workspace/Tools/ToolkitEditor.svelte | 2 + .../workspace/common/AccessControl.svelte | 42 +++++++++++++++++-- .../common/AccessControlModal.svelte | 3 +- 7 files changed, 57 insertions(+), 9 deletions(-) diff --git a/src/lib/components/workspace/Knowledge/CreateKnowledgeBase.svelte b/src/lib/components/workspace/Knowledge/CreateKnowledgeBase.svelte index 586564cd7..fefbbefcd 100644 --- a/src/lib/components/workspace/Knowledge/CreateKnowledgeBase.svelte +++ b/src/lib/components/workspace/Knowledge/CreateKnowledgeBase.svelte @@ -5,7 +5,7 @@ import { createNewKnowledge, getKnowledgeBases } from '$lib/apis/knowledge'; import { toast } from 'svelte-sonner'; - import { knowledge } from '$lib/stores'; + import { knowledge, user } from '$lib/stores'; import AccessControl from '../common/AccessControl.svelte'; let loading = false; @@ -112,7 +112,11 @@
- +
diff --git a/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte b/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte index 07ca0f1ed..c6f47e8de 100644 --- a/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte +++ b/src/lib/components/workspace/Knowledge/KnowledgeBase.svelte @@ -9,7 +9,7 @@ import { goto } from '$app/navigation'; import { page } from '$app/stores'; - import { mobile, showSidebar, knowledge as _knowledge, config } from '$lib/stores'; + import { mobile, showSidebar, knowledge as _knowledge, config, user } from '$lib/stores'; import { updateFileDataContentById, uploadFile, deleteFileById } from '$lib/apis/files'; import { @@ -619,6 +619,7 @@ { changeDebounceHandler(); }} diff --git a/src/lib/components/workspace/Models/ModelEditor.svelte b/src/lib/components/workspace/Models/ModelEditor.svelte index 170c37f22..4bd875ee2 100644 --- a/src/lib/components/workspace/Models/ModelEditor.svelte +++ b/src/lib/components/workspace/Models/ModelEditor.svelte @@ -530,7 +530,11 @@
- +
diff --git a/src/lib/components/workspace/Prompts/PromptEditor.svelte b/src/lib/components/workspace/Prompts/PromptEditor.svelte index 76ae9f851..4abe5c067 100644 --- a/src/lib/components/workspace/Prompts/PromptEditor.svelte +++ b/src/lib/components/workspace/Prompts/PromptEditor.svelte @@ -7,6 +7,7 @@ import AccessControl from '../common/AccessControl.svelte'; import LockClosed from '$lib/components/icons/LockClosed.svelte'; import AccessControlModal from '../common/AccessControlModal.svelte'; + import { user } from '$lib/stores'; export let onSubmit: Function; export let edit = false; @@ -72,6 +73,7 @@ bind:show={showAccessControlModal} bind:accessControl accessRoles={['read', 'write']} + allowPublic={$user?.permissions?.sharing?.public_prompts || $user?.role === 'admin'} />
diff --git a/src/lib/components/workspace/Tools/ToolkitEditor.svelte b/src/lib/components/workspace/Tools/ToolkitEditor.svelte index 63a54ab24..6057be6cb 100644 --- a/src/lib/components/workspace/Tools/ToolkitEditor.svelte +++ b/src/lib/components/workspace/Tools/ToolkitEditor.svelte @@ -11,6 +11,7 @@ import Tooltip from '$lib/components/common/Tooltip.svelte'; import LockClosed from '$lib/components/icons/LockClosed.svelte'; import AccessControlModal from '../common/AccessControlModal.svelte'; + import { user } from '$lib/stores'; let formElement = null; let loading = false; @@ -183,6 +184,7 @@ class Tools: bind:show={showAccessControlModal} bind:accessControl accessRoles={['read', 'write']} + allowPublic={$user?.permissions?.sharing?.public_tools || $user?.role === 'admin'} />
diff --git a/src/lib/components/workspace/common/AccessControl.svelte b/src/lib/components/workspace/common/AccessControl.svelte index e4c6e3e48..9c3e0dd8b 100644 --- a/src/lib/components/workspace/common/AccessControl.svelte +++ b/src/lib/components/workspace/common/AccessControl.svelte @@ -15,14 +15,44 @@ export let accessRoles = ['read']; export let accessControl = null; + export let allowPublic = true; + let selectedGroupId = ''; let groups = []; + $: if (!allowPublic && accessControl === null) { + accessControl = { + read: { + group_ids: [], + user_ids: [] + }, + write: { + group_ids: [], + user_ids: [] + } + }; + onChange(accessControl); + } + onMount(async () => { groups = await getGroups(localStorage.token); if (accessControl === null) { - accessControl = null; + if (allowPublic) { + accessControl = null; + } else { + accessControl = { + read: { + group_ids: [], + user_ids: [] + }, + write: { + group_ids: [], + user_ids: [] + } + }; + onChange(accessControl); + } } else { accessControl = { read: { @@ -104,17 +134,21 @@ } else { accessControl = { read: { - group_ids: [] + group_ids: [], + user_ids: [] }, write: { - group_ids: [] + group_ids: [], + user_ids: [] } }; } }} > - + {#if allowPublic} + + {/if}
diff --git a/src/lib/components/workspace/common/AccessControlModal.svelte b/src/lib/components/workspace/common/AccessControlModal.svelte index cc7c59c86..d69408263 100644 --- a/src/lib/components/workspace/common/AccessControlModal.svelte +++ b/src/lib/components/workspace/common/AccessControlModal.svelte @@ -8,6 +8,7 @@ export let show = false; export let accessControl = null; export let accessRoles = ['read']; + export let allowPublic = true; export let onChange = () => {}; @@ -38,7 +39,7 @@
- +