feat: public sharing permissions

Co-Authored-By: Taylor Wilsdon <6508528+taylorwilsdon@users.noreply.github.com>
This commit is contained in:
Timothy Jaeryang Baek 2025-03-31 17:28:25 -07:00
parent 50b3f47f81
commit 580965df17
7 changed files with 57 additions and 9 deletions

View File

@ -5,7 +5,7 @@
import { createNewKnowledge, getKnowledgeBases } from '$lib/apis/knowledge'; import { createNewKnowledge, getKnowledgeBases } from '$lib/apis/knowledge';
import { toast } from 'svelte-sonner'; import { toast } from 'svelte-sonner';
import { knowledge } from '$lib/stores'; import { knowledge, user } from '$lib/stores';
import AccessControl from '../common/AccessControl.svelte'; import AccessControl from '../common/AccessControl.svelte';
let loading = false; let loading = false;
@ -112,7 +112,11 @@
<div class="mt-2"> <div class="mt-2">
<div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg"> <div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
<AccessControl bind:accessControl accessRoles={['read', 'write']} /> <AccessControl
bind:accessControl
accessRoles={['read', 'write']}
allowPublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
/>
</div> </div>
</div> </div>

View File

@ -9,7 +9,7 @@
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/stores'; 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 { updateFileDataContentById, uploadFile, deleteFileById } from '$lib/apis/files';
import { import {
@ -619,6 +619,7 @@
<AccessControlModal <AccessControlModal
bind:show={showAccessControlModal} bind:show={showAccessControlModal}
bind:accessControl={knowledge.access_control} bind:accessControl={knowledge.access_control}
allowPublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
onChange={() => { onChange={() => {
changeDebounceHandler(); changeDebounceHandler();
}} }}

View File

@ -530,7 +530,11 @@
<div class="my-2"> <div class="my-2">
<div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg"> <div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
<AccessControl bind:accessControl accessRoles={['read', 'write']} /> <AccessControl
bind:accessControl
accessRoles={['read', 'write']}
allowPublic={$user?.permissions?.sharing?.public_models || $user?.role === 'admin'}
/>
</div> </div>
</div> </div>

View File

@ -7,6 +7,7 @@
import AccessControl from '../common/AccessControl.svelte'; import AccessControl from '../common/AccessControl.svelte';
import LockClosed from '$lib/components/icons/LockClosed.svelte'; import LockClosed from '$lib/components/icons/LockClosed.svelte';
import AccessControlModal from '../common/AccessControlModal.svelte'; import AccessControlModal from '../common/AccessControlModal.svelte';
import { user } from '$lib/stores';
export let onSubmit: Function; export let onSubmit: Function;
export let edit = false; export let edit = false;
@ -72,6 +73,7 @@
bind:show={showAccessControlModal} bind:show={showAccessControlModal}
bind:accessControl bind:accessControl
accessRoles={['read', 'write']} accessRoles={['read', 'write']}
allowPublic={$user?.permissions?.sharing?.public_prompts || $user?.role === 'admin'}
/> />
<div class="w-full max-h-full flex justify-center"> <div class="w-full max-h-full flex justify-center">

View File

@ -11,6 +11,7 @@
import Tooltip from '$lib/components/common/Tooltip.svelte'; import Tooltip from '$lib/components/common/Tooltip.svelte';
import LockClosed from '$lib/components/icons/LockClosed.svelte'; import LockClosed from '$lib/components/icons/LockClosed.svelte';
import AccessControlModal from '../common/AccessControlModal.svelte'; import AccessControlModal from '../common/AccessControlModal.svelte';
import { user } from '$lib/stores';
let formElement = null; let formElement = null;
let loading = false; let loading = false;
@ -183,6 +184,7 @@ class Tools:
bind:show={showAccessControlModal} bind:show={showAccessControlModal}
bind:accessControl bind:accessControl
accessRoles={['read', 'write']} accessRoles={['read', 'write']}
allowPublic={$user?.permissions?.sharing?.public_tools || $user?.role === 'admin'}
/> />
<div class=" flex flex-col justify-between w-full overflow-y-auto h-full"> <div class=" flex flex-col justify-between w-full overflow-y-auto h-full">

View File

@ -15,14 +15,44 @@
export let accessRoles = ['read']; export let accessRoles = ['read'];
export let accessControl = null; export let accessControl = null;
export let allowPublic = true;
let selectedGroupId = ''; let selectedGroupId = '';
let groups = []; let groups = [];
$: if (!allowPublic && accessControl === null) {
accessControl = {
read: {
group_ids: [],
user_ids: []
},
write: {
group_ids: [],
user_ids: []
}
};
onChange(accessControl);
}
onMount(async () => { onMount(async () => {
groups = await getGroups(localStorage.token); groups = await getGroups(localStorage.token);
if (accessControl === null) { if (accessControl === null) {
accessControl = null; if (allowPublic) {
accessControl = null;
} else {
accessControl = {
read: {
group_ids: [],
user_ids: []
},
write: {
group_ids: [],
user_ids: []
}
};
onChange(accessControl);
}
} else { } else {
accessControl = { accessControl = {
read: { read: {
@ -104,17 +134,21 @@
} else { } else {
accessControl = { accessControl = {
read: { read: {
group_ids: [] group_ids: [],
user_ids: []
}, },
write: { write: {
group_ids: [] group_ids: [],
user_ids: []
} }
}; };
} }
}} }}
> >
<option class=" text-gray-700" value="private" selected>{$i18n.t('Private')}</option> <option class=" text-gray-700" value="private" selected>{$i18n.t('Private')}</option>
<option class=" text-gray-700" value="public" selected>{$i18n.t('Public')}</option> {#if allowPublic}
<option class=" text-gray-700" value="public" selected>{$i18n.t('Public')}</option>
{/if}
</select> </select>
<div class=" text-xs text-gray-400 font-medium"> <div class=" text-xs text-gray-400 font-medium">

View File

@ -8,6 +8,7 @@
export let show = false; export let show = false;
export let accessControl = null; export let accessControl = null;
export let accessRoles = ['read']; export let accessRoles = ['read'];
export let allowPublic = true;
export let onChange = () => {}; export let onChange = () => {};
</script> </script>
@ -38,7 +39,7 @@
</div> </div>
<div class="w-full px-5 pb-4 dark:text-white"> <div class="w-full px-5 pb-4 dark:text-white">
<AccessControl bind:accessControl {onChange} {accessRoles} /> <AccessControl bind:accessControl {onChange} {accessRoles} {allowPublic} />
</div> </div>
</div> </div>
</Modal> </Modal>