mirror of
https://github.com/open-webui/open-webui
synced 2025-06-26 18:26:48 +00:00
refac: access control
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
|
||||
let name = '';
|
||||
let description = '';
|
||||
let accessControl = null;
|
||||
|
||||
const submitHandler = async () => {
|
||||
loading = true;
|
||||
@@ -24,7 +25,12 @@
|
||||
return;
|
||||
}
|
||||
|
||||
const res = await createNewKnowledge(localStorage.token, name, description).catch((e) => {
|
||||
const res = await createNewKnowledge(
|
||||
localStorage.token,
|
||||
name,
|
||||
description,
|
||||
accessControl
|
||||
).catch((e) => {
|
||||
toast.error(e);
|
||||
});
|
||||
|
||||
@@ -105,7 +111,9 @@
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<AccessControl />
|
||||
<div class="px-3 py-2 bg-gray-50 dark:bg-gray-950 rounded-lg">
|
||||
<AccessControl bind:accessControl />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex justify-end mt-2">
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
import EllipsisVertical from '$lib/components/icons/EllipsisVertical.svelte';
|
||||
import Drawer from '$lib/components/common/Drawer.svelte';
|
||||
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
||||
import MenuLines from '$lib/components/icons/MenuLines.svelte';
|
||||
import AccessControl from '../common/AccessControl.svelte';
|
||||
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
||||
import AccessControlModal from '../common/AccessControlModal.svelte';
|
||||
|
||||
let largeScreen = true;
|
||||
|
||||
@@ -63,6 +63,7 @@
|
||||
|
||||
let showAddTextContentModal = false;
|
||||
let showSyncConfirmModal = false;
|
||||
let showAccessControlModal = false;
|
||||
|
||||
let inputFiles = null;
|
||||
|
||||
@@ -421,7 +422,8 @@
|
||||
|
||||
const res = await updateKnowledgeById(localStorage.token, id, {
|
||||
name: knowledge.name,
|
||||
description: knowledge.description
|
||||
description: knowledge.description,
|
||||
access_control: knowledge.access_control
|
||||
}).catch((e) => {
|
||||
toast.error(e);
|
||||
});
|
||||
@@ -599,6 +601,61 @@
|
||||
|
||||
<div class="flex flex-col w-full h-full max-h-[100dvh] translate-y-1" id="collection-container">
|
||||
{#if id && knowledge}
|
||||
<AccessControlModal
|
||||
bind:show={showAccessControlModal}
|
||||
bind:accessControl={knowledge.access_control}
|
||||
onChange={() => {
|
||||
changeDebounceHandler();
|
||||
}}
|
||||
/>
|
||||
<div class="w-full mb-2.5">
|
||||
<div class=" flex w-full">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center justify-between w-full px-0.5 mb-1">
|
||||
<div class="w-full">
|
||||
<input
|
||||
type="text"
|
||||
class="text-left w-full font-semibold text-2xl font-primary bg-transparent outline-none"
|
||||
bind:value={knowledge.name}
|
||||
placeholder="Knowledge Name"
|
||||
on:input={() => {
|
||||
changeDebounceHandler();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="self-center">
|
||||
<button
|
||||
class="bg-gray-50 hover:bg-gray-100 text-black transition px-2 py-1 rounded-full flex gap-1 items-center"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
showAccessControlModal = true;
|
||||
}}
|
||||
>
|
||||
<LockClosed strokeWidth="2.5" />
|
||||
|
||||
<div class="text-sm font-medium flex-shrink-0">
|
||||
{$i18n.t('Share')}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex w-full px-1">
|
||||
<input
|
||||
type="text"
|
||||
class="text-left text-xs w-full text-gray-500 bg-transparent outline-none"
|
||||
bind:value={knowledge.description}
|
||||
placeholder="Knowledge Description"
|
||||
on:input={() => {
|
||||
changeDebounceHandler();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-row flex-1 h-full max-h-full pb-2.5">
|
||||
<PaneGroup direction="horizontal">
|
||||
<Pane
|
||||
@@ -764,41 +821,7 @@
|
||||
</div>
|
||||
</div>
|
||||
{:else}
|
||||
<div class="m-auto pb-20">
|
||||
<div>
|
||||
<div class=" flex w-full mt-1 mb-3.5">
|
||||
<div class="flex-1">
|
||||
<div class="flex items-center justify-between w-full px-0.5 mb-1">
|
||||
<div class="w-full">
|
||||
<input
|
||||
type="text"
|
||||
class="text-center w-full font-medium text-3xl font-primary bg-transparent outline-none"
|
||||
bind:value={knowledge.name}
|
||||
on:input={() => {
|
||||
changeDebounceHandler();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="flex w-full px-1">
|
||||
<input
|
||||
type="text"
|
||||
class="text-center w-full text-gray-500 bg-transparent outline-none"
|
||||
bind:value={knowledge.description}
|
||||
on:input={() => {
|
||||
changeDebounceHandler();
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mt-2">
|
||||
<AccessControl />
|
||||
</div>
|
||||
</div>
|
||||
<div></div>
|
||||
{/if}
|
||||
</div>
|
||||
</Pane>
|
||||
|
||||
@@ -9,12 +9,16 @@
|
||||
import Badge from '$lib/components/common/Badge.svelte';
|
||||
import ChevronLeft from '$lib/components/icons/ChevronLeft.svelte';
|
||||
import Tooltip from '$lib/components/common/Tooltip.svelte';
|
||||
import LockClosed from '$lib/components/icons/LockClosed.svelte';
|
||||
import AccessControlModal from '../common/AccessControlModal.svelte';
|
||||
|
||||
const dispatch = createEventDispatcher();
|
||||
|
||||
let formElement = null;
|
||||
let loading = false;
|
||||
|
||||
let showConfirm = false;
|
||||
let showAccessControlModal = false;
|
||||
|
||||
export let edit = false;
|
||||
export let clone = false;
|
||||
@@ -25,6 +29,8 @@
|
||||
description: ''
|
||||
};
|
||||
export let content = '';
|
||||
export let accessControl = null;
|
||||
|
||||
let _content = '';
|
||||
|
||||
$: if (content) {
|
||||
@@ -148,7 +154,8 @@ class Tools:
|
||||
id,
|
||||
name,
|
||||
meta,
|
||||
content
|
||||
content,
|
||||
access_control: accessControl
|
||||
});
|
||||
};
|
||||
|
||||
@@ -172,6 +179,8 @@ class Tools:
|
||||
};
|
||||
</script>
|
||||
|
||||
<AccessControlModal bind:show={showAccessControlModal} bind:accessControl />
|
||||
|
||||
<div class=" flex flex-col justify-between w-full overflow-y-auto h-full">
|
||||
<div class="mx-auto w-full md:px-0 h-full">
|
||||
<form
|
||||
@@ -205,7 +214,7 @@ class Tools:
|
||||
<div class="flex-1">
|
||||
<Tooltip content={$i18n.t('e.g. My Tools')} placement="top-start">
|
||||
<input
|
||||
class="w-full text-2xl font-medium bg-transparent outline-none"
|
||||
class="w-full text-2xl font-semibold bg-transparent outline-none"
|
||||
type="text"
|
||||
placeholder={$i18n.t('Tool Name')}
|
||||
bind:value={name}
|
||||
@@ -215,7 +224,19 @@ class Tools:
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<Badge type="muted" content={$i18n.t('Tool')} />
|
||||
<button
|
||||
class="bg-gray-50 hover:bg-gray-100 text-black transition px-2 py-1 rounded-full flex gap-1 items-center"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
showAccessControlModal = true;
|
||||
}}
|
||||
>
|
||||
<LockClosed strokeWidth="2.5" />
|
||||
|
||||
<div class="text-sm font-medium flex-shrink-0">
|
||||
{$i18n.t('Share')}
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
import UserCircleSolid from '$lib/components/icons/UserCircleSolid.svelte';
|
||||
import XMark from '$lib/components/icons/XMark.svelte';
|
||||
|
||||
export let onChange: Function = () => {};
|
||||
|
||||
export let accessControl = null;
|
||||
|
||||
let selectedGroupId = '';
|
||||
@@ -17,6 +19,8 @@
|
||||
onMount(async () => {
|
||||
groups = await getGroups(localStorage.token);
|
||||
});
|
||||
|
||||
$: onChange(accessControl);
|
||||
</script>
|
||||
|
||||
<div class=" rounded-lg flex flex-col gap-2">
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<script>
|
||||
import { getContext } from 'svelte';
|
||||
const i18n = getContext('i18n');
|
||||
|
||||
import Modal from '$lib/components/common/Modal.svelte';
|
||||
import AccessControl from './AccessControl.svelte';
|
||||
|
||||
export let show = false;
|
||||
export let accessControl = null;
|
||||
|
||||
export let onChange = () => {};
|
||||
</script>
|
||||
|
||||
<Modal size="sm" bind:show>
|
||||
<div>
|
||||
<div class=" flex justify-between dark:text-gray-100 px-5 pt-3 pb-1">
|
||||
<div class=" text-lg font-medium self-center font-primary">
|
||||
{$i18n.t('Share')}
|
||||
</div>
|
||||
<button
|
||||
class="self-center"
|
||||
on:click={() => {
|
||||
show = false;
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
viewBox="0 0 20 20"
|
||||
fill="currentColor"
|
||||
class="w-5 h-5"
|
||||
>
|
||||
<path
|
||||
d="M6.28 5.22a.75.75 0 00-1.06 1.06L8.94 10l-3.72 3.72a.75.75 0 101.06 1.06L10 11.06l3.72 3.72a.75.75 0 101.06-1.06L11.06 10l3.72-3.72a.75.75 0 00-1.06-1.06L10 8.94 6.28 5.22z"
|
||||
/>
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="w-full px-5 pb-4">
|
||||
<AccessControl bind:accessControl {onChange} />
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
Reference in New Issue
Block a user