mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-11 20:05:19 +00:00
feat/enh: user sharing perms
This commit is contained in:
parent
849278ca4f
commit
f69e37a850
11 changed files with 297 additions and 144 deletions
|
|
@ -1276,6 +1276,12 @@ USER_PERMISSIONS_WORKSPACE_TOOLS_EXPORT = (
|
|||
os.environ.get("USER_PERMISSIONS_WORKSPACE_TOOLS_EXPORT", "False").lower() == "true"
|
||||
)
|
||||
|
||||
|
||||
USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_SHARING = (
|
||||
os.environ.get("USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_SHARING", "False").lower()
|
||||
== "true"
|
||||
)
|
||||
|
||||
USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_PUBLIC_SHARING = (
|
||||
os.environ.get(
|
||||
"USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_PUBLIC_SHARING", "False"
|
||||
|
|
@ -1283,8 +1289,10 @@ USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_PUBLIC_SHARING = (
|
|||
== "true"
|
||||
)
|
||||
|
||||
USER_PERMISSIONS_NOTES_ALLOW_PUBLIC_SHARING = (
|
||||
os.environ.get("USER_PERMISSIONS_NOTES_ALLOW_PUBLIC_SHARING", "False").lower()
|
||||
USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_ALLOW_SHARING = (
|
||||
os.environ.get(
|
||||
"USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_ALLOW_PUBLIC_SHARING", "False"
|
||||
).lower()
|
||||
== "true"
|
||||
)
|
||||
|
||||
|
|
@ -1295,6 +1303,11 @@ USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_ALLOW_PUBLIC_SHARING = (
|
|||
== "true"
|
||||
)
|
||||
|
||||
USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_SHARING = (
|
||||
os.environ.get("USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_SHARING", "False").lower()
|
||||
== "true"
|
||||
)
|
||||
|
||||
USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_PUBLIC_SHARING = (
|
||||
os.environ.get(
|
||||
"USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_PUBLIC_SHARING", "False"
|
||||
|
|
@ -1302,6 +1315,12 @@ USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_PUBLIC_SHARING = (
|
|||
== "true"
|
||||
)
|
||||
|
||||
|
||||
USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_SHARING = (
|
||||
os.environ.get("USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_SHARING", "False").lower()
|
||||
== "true"
|
||||
)
|
||||
|
||||
USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_PUBLIC_SHARING = (
|
||||
os.environ.get(
|
||||
"USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_PUBLIC_SHARING", "False"
|
||||
|
|
@ -1310,6 +1329,17 @@ USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_PUBLIC_SHARING = (
|
|||
)
|
||||
|
||||
|
||||
USER_PERMISSIONS_NOTES_ALLOW_SHARING = (
|
||||
os.environ.get("USER_PERMISSIONS_NOTES_ALLOW_PUBLIC_SHARING", "False").lower()
|
||||
== "true"
|
||||
)
|
||||
|
||||
USER_PERMISSIONS_NOTES_ALLOW_PUBLIC_SHARING = (
|
||||
os.environ.get("USER_PERMISSIONS_NOTES_ALLOW_PUBLIC_SHARING", "False").lower()
|
||||
== "true"
|
||||
)
|
||||
|
||||
|
||||
USER_PERMISSIONS_CHAT_CONTROLS = (
|
||||
os.environ.get("USER_PERMISSIONS_CHAT_CONTROLS", "True").lower() == "true"
|
||||
)
|
||||
|
|
@ -1431,10 +1461,15 @@ DEFAULT_USER_PERMISSIONS = {
|
|||
"tools_export": USER_PERMISSIONS_WORKSPACE_TOOLS_EXPORT,
|
||||
},
|
||||
"sharing": {
|
||||
"models": USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_SHARING,
|
||||
"public_models": USER_PERMISSIONS_WORKSPACE_MODELS_ALLOW_PUBLIC_SHARING,
|
||||
"knowledge": USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_ALLOW_SHARING,
|
||||
"public_knowledge": USER_PERMISSIONS_WORKSPACE_KNOWLEDGE_ALLOW_PUBLIC_SHARING,
|
||||
"prompts": USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_SHARING,
|
||||
"public_prompts": USER_PERMISSIONS_WORKSPACE_PROMPTS_ALLOW_PUBLIC_SHARING,
|
||||
"tools": USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_SHARING,
|
||||
"public_tools": USER_PERMISSIONS_WORKSPACE_TOOLS_ALLOW_PUBLIC_SHARING,
|
||||
"notes": USER_PERMISSIONS_NOTES_ALLOW_SHARING,
|
||||
"public_notes": USER_PERMISSIONS_NOTES_ALLOW_PUBLIC_SHARING,
|
||||
},
|
||||
"chat": {
|
||||
|
|
|
|||
|
|
@ -183,10 +183,15 @@ class WorkspacePermissions(BaseModel):
|
|||
|
||||
|
||||
class SharingPermissions(BaseModel):
|
||||
public_models: bool = True
|
||||
public_knowledge: bool = True
|
||||
public_prompts: bool = True
|
||||
models: bool = False
|
||||
public_models: bool = False
|
||||
knowledge: bool = False
|
||||
public_knowledge: bool = False
|
||||
prompts: bool = False
|
||||
public_prompts: bool = False
|
||||
tools: bool = False
|
||||
public_tools: bool = True
|
||||
notes: bool = False
|
||||
public_notes: bool = True
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -49,10 +49,15 @@
|
|||
tools_export: false
|
||||
},
|
||||
sharing: {
|
||||
models: false,
|
||||
public_models: false,
|
||||
knowledge: false,
|
||||
public_knowledge: false,
|
||||
prompts: false,
|
||||
public_prompts: false,
|
||||
tools: false,
|
||||
public_tools: false,
|
||||
notes: false,
|
||||
public_notes: false
|
||||
},
|
||||
chat: {
|
||||
|
|
|
|||
|
|
@ -20,10 +20,15 @@
|
|||
tools_export: false
|
||||
},
|
||||
sharing: {
|
||||
models: false,
|
||||
public_models: false,
|
||||
knowledge: false,
|
||||
public_knowledge: false,
|
||||
prompts: false,
|
||||
public_prompts: false,
|
||||
tools: false,
|
||||
public_tools: false,
|
||||
notes: false,
|
||||
public_notes: false
|
||||
},
|
||||
chat: {
|
||||
|
|
@ -217,11 +222,11 @@
|
|||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Models Public Sharing')}
|
||||
{$i18n.t('Models Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_models} />
|
||||
<Switch bind:state={permissions.sharing.models} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_models && !permissions.sharing.public_models}
|
||||
{#if defaultPermissions?.sharing?.models && !permissions.sharing.models}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
|
|
@ -230,14 +235,32 @@
|
|||
{/if}
|
||||
</div>
|
||||
|
||||
{#if permissions.sharing.models}
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Models Public Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_models} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_models && !permissions.sharing.public_models}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Knowledge Public Sharing')}
|
||||
{$i18n.t('Knowledge Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_knowledge} />
|
||||
<Switch bind:state={permissions.sharing.knowledge} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_knowledge && !permissions.sharing.public_knowledge}
|
||||
{#if defaultPermissions?.sharing?.knowledge && !permissions.sharing.knowledge}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
|
|
@ -246,14 +269,32 @@
|
|||
{/if}
|
||||
</div>
|
||||
|
||||
{#if permissions.sharing.knowledge}
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Knowledge Public Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_knowledge} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_knowledge && !permissions.sharing.public_knowledge}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Prompts Public Sharing')}
|
||||
{$i18n.t('Prompts Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_prompts} />
|
||||
<Switch bind:state={permissions.sharing.prompts} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_prompts && !permissions.sharing.public_prompts}
|
||||
{#if defaultPermissions?.sharing?.prompts && !permissions.sharing.prompts}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
|
|
@ -262,14 +303,32 @@
|
|||
{/if}
|
||||
</div>
|
||||
|
||||
{#if permissions.sharing.prompts}
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Prompts Public Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_prompts} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_prompts && !permissions.sharing.public_prompts}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Tools Public Sharing')}
|
||||
{$i18n.t('Tools Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_tools} />
|
||||
<Switch bind:state={permissions.sharing.tools} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_tools && !permissions.sharing.public_tools}
|
||||
{#if defaultPermissions?.sharing?.tools && !permissions.sharing.tools}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
|
|
@ -278,14 +337,32 @@
|
|||
{/if}
|
||||
</div>
|
||||
|
||||
{#if permissions.sharing.tools}
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Tools Public Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_tools} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_tools && !permissions.sharing.public_tools}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Notes Public Sharing')}
|
||||
{$i18n.t('Notes Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_notes} />
|
||||
<Switch bind:state={permissions.sharing.notes} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_notes && !permissions.sharing.public_notes}
|
||||
{#if defaultPermissions?.sharing?.notes && !permissions.sharing.notes}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
|
|
@ -293,6 +370,24 @@
|
|||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
{#if permissions.sharing.notes}
|
||||
<div class="flex flex-col w-full">
|
||||
<div class="flex w-full justify-between my-1">
|
||||
<div class=" self-center text-xs font-medium">
|
||||
{$i18n.t('Notes Public Sharing')}
|
||||
</div>
|
||||
<Switch bind:state={permissions.sharing.public_notes} />
|
||||
</div>
|
||||
{#if defaultPermissions?.sharing?.public_notes && !permissions.sharing.public_notes}
|
||||
<div>
|
||||
<div class="text-xs text-gray-500">
|
||||
{$i18n.t('This is a default user permission and will remain enabled.')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<hr class=" border-gray-100 dark:border-gray-850" />
|
||||
|
|
|
|||
|
|
@ -116,7 +116,8 @@
|
|||
<AccessControl
|
||||
bind:accessControl
|
||||
accessRoles={['read', 'write']}
|
||||
allowPublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
|
||||
share={$user?.permissions?.sharing?.knowledge || $user?.role === 'admin'}
|
||||
sharePublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -547,39 +547,41 @@
|
|||
dragged = false;
|
||||
|
||||
const handleUploadingFileFolder = (items) => {
|
||||
for(const item of items) {
|
||||
|
||||
if(item.isFile) {
|
||||
for (const item of items) {
|
||||
if (item.isFile) {
|
||||
item.file((file) => {
|
||||
uploadFileHandler(file);
|
||||
})
|
||||
});
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
// Not sure why you have to call webkitGetAsEntry and isDirectory seperate, but it won't work if you try item.webkitGetAsEntry().isDirectory
|
||||
const wkentry = item.webkitGetAsEntry();
|
||||
const isDirectory = wkentry.isDirectory;
|
||||
if(isDirectory) {
|
||||
if (isDirectory) {
|
||||
// Read the directory
|
||||
wkentry.createReader().readEntries((entries) => {
|
||||
handleUploadingFileFolder(entries)
|
||||
}, (error) => {
|
||||
console.error('Error reading directory entries:', error);
|
||||
});
|
||||
wkentry.createReader().readEntries(
|
||||
(entries) => {
|
||||
handleUploadingFileFolder(entries);
|
||||
},
|
||||
(error) => {
|
||||
console.error('Error reading directory entries:', error);
|
||||
}
|
||||
);
|
||||
} else {
|
||||
toast.info($i18n.t('Uploading file...'));
|
||||
uploadFileHandler(item.getAsFile());
|
||||
toast.success($i18n.t('File uploaded!'));
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
if (e.dataTransfer?.types?.includes('Files')) {
|
||||
if (e.dataTransfer?.files) {
|
||||
const inputItems = e.dataTransfer?.items;
|
||||
|
||||
if (inputItems && inputItems.length > 0) {
|
||||
handleUploadingFileFolder(inputItems)
|
||||
handleUploadingFileFolder(inputItems);
|
||||
} else {
|
||||
toast.error($i18n.t(`File not found.`));
|
||||
}
|
||||
|
|
@ -708,7 +710,8 @@
|
|||
<AccessControlModal
|
||||
bind:show={showAccessControlModal}
|
||||
bind:accessControl={knowledge.access_control}
|
||||
allowPublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
|
||||
share={$user?.permissions?.sharing?.knowledge || $user?.role === 'admin'}
|
||||
sharePublic={$user?.permissions?.sharing?.public_knowledge || $user?.role === 'admin'}
|
||||
onChange={() => {
|
||||
changeDebounceHandler();
|
||||
}}
|
||||
|
|
|
|||
|
|
@ -591,7 +591,8 @@
|
|||
<AccessControl
|
||||
bind:accessControl
|
||||
accessRoles={['read', 'write']}
|
||||
allowPublic={$user?.permissions?.sharing?.public_models || $user?.role === 'admin'}
|
||||
share={$user?.permissions?.sharing?.models || $user?.role === 'admin'}
|
||||
sharePublic={$user?.permissions?.sharing?.public_models || $user?.role === 'admin'}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -83,7 +83,8 @@
|
|||
bind:show={showAccessControlModal}
|
||||
bind:accessControl
|
||||
accessRoles={['read', 'write']}
|
||||
allowPublic={$user?.permissions?.sharing?.public_prompts || $user?.role === 'admin'}
|
||||
share={$user?.permissions?.sharing?.prompts || $user?.role === 'admin'}
|
||||
sharePublic={$user?.permissions?.sharing?.public_prompts || $user?.role === 'admin'}
|
||||
/>
|
||||
|
||||
<div class="w-full max-h-full flex justify-center">
|
||||
|
|
|
|||
|
|
@ -189,7 +189,8 @@ class Tools:
|
|||
bind:show={showAccessControlModal}
|
||||
bind:accessControl
|
||||
accessRoles={['read', 'write']}
|
||||
allowPublic={$user?.permissions?.sharing?.public_tools || $user?.role === 'admin'}
|
||||
share={$user?.permissions?.sharing?.tools || $user?.role === 'admin'}
|
||||
sharePublic={$user?.permissions?.sharing?.public_tools || $user?.role === 'admin'}
|
||||
/>
|
||||
|
||||
<div class=" flex flex-col justify-between w-full overflow-y-auto h-full">
|
||||
|
|
|
|||
|
|
@ -15,17 +15,18 @@
|
|||
export let accessRoles = ['read'];
|
||||
export let accessControl = {};
|
||||
|
||||
export let allowPublic = true;
|
||||
export let share = true;
|
||||
export let sharePublic = true;
|
||||
|
||||
let selectedGroupId = '';
|
||||
let groups = [];
|
||||
|
||||
$: if (!allowPublic && accessControl === null) {
|
||||
$: if (!sharePublic && accessControl === null) {
|
||||
initPublicAccess();
|
||||
}
|
||||
|
||||
const initPublicAccess = () => {
|
||||
if (!allowPublic && accessControl === null) {
|
||||
if (!sharePublic && accessControl === null) {
|
||||
accessControl = {
|
||||
read: {
|
||||
group_ids: [],
|
||||
|
|
@ -125,7 +126,7 @@
|
|||
}}
|
||||
>
|
||||
<option class=" text-gray-700" value="private" selected>{$i18n.t('Private')}</option>
|
||||
{#if allowPublic}
|
||||
{#if share && sharePublic}
|
||||
<option class=" text-gray-700" value="public" selected>{$i18n.t('Public')}</option>
|
||||
{/if}
|
||||
</select>
|
||||
|
|
@ -140,48 +141,50 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{#if accessControl !== null}
|
||||
{@const accessGroups = groups.filter((group) =>
|
||||
(accessControl?.read?.group_ids ?? []).includes(group.id)
|
||||
)}
|
||||
<div>
|
||||
<div class="">
|
||||
<div class="flex justify-between mb-1.5">
|
||||
<div class="text-sm font-semibold">
|
||||
{$i18n.t('Groups')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-1">
|
||||
<div class="flex w-full">
|
||||
<div class="flex flex-1 items-center">
|
||||
<div class="w-full px-0.5">
|
||||
<select
|
||||
class="outline-hidden bg-transparent text-sm rounded-lg block w-full pr-10 max-w-full
|
||||
{#if share}
|
||||
{#if accessControl !== null}
|
||||
{@const accessGroups = groups.filter((group) =>
|
||||
(accessControl?.read?.group_ids ?? []).includes(group.id)
|
||||
)}
|
||||
<div>
|
||||
<div class="">
|
||||
<div class="flex justify-between mb-1.5">
|
||||
<div class="text-sm font-semibold">
|
||||
{$i18n.t('Groups')}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-1">
|
||||
<div class="flex w-full">
|
||||
<div class="flex flex-1 items-center">
|
||||
<div class="w-full px-0.5">
|
||||
<select
|
||||
class="outline-hidden bg-transparent text-sm rounded-lg block w-full pr-10 max-w-full
|
||||
{selectedGroupId ? '' : 'text-gray-500'}
|
||||
dark:placeholder-gray-500"
|
||||
bind:value={selectedGroupId}
|
||||
on:change={() => {
|
||||
if (selectedGroupId !== '') {
|
||||
accessControl.read.group_ids = [
|
||||
...(accessControl?.read?.group_ids ?? []),
|
||||
selectedGroupId
|
||||
];
|
||||
bind:value={selectedGroupId}
|
||||
on:change={() => {
|
||||
if (selectedGroupId !== '') {
|
||||
accessControl.read.group_ids = [
|
||||
...(accessControl?.read?.group_ids ?? []),
|
||||
selectedGroupId
|
||||
];
|
||||
|
||||
selectedGroupId = '';
|
||||
onChange(accessControl);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<option class=" text-gray-700" value="" disabled selected
|
||||
>{$i18n.t('Select a group')}</option
|
||||
selectedGroupId = '';
|
||||
onChange(accessControl);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{#each groups.filter((group) => !(accessControl?.read?.group_ids ?? []).includes(group.id)) as group}
|
||||
<option class=" text-gray-700" value={group.id}>{group.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<!-- <div>
|
||||
<option class=" text-gray-700" value="" disabled selected
|
||||
>{$i18n.t('Select a group')}</option
|
||||
>
|
||||
{#each groups.filter((group) => !(accessControl?.read?.group_ids ?? []).includes(group.id)) as group}
|
||||
<option class=" text-gray-700" value={group.id}>{group.name}</option>
|
||||
{/each}
|
||||
</select>
|
||||
</div>
|
||||
<!-- <div>
|
||||
<Tooltip content={$i18n.t('Add Group')}>
|
||||
<button
|
||||
class=" p-1 rounded-xl bg-transparent dark:hover:bg-white/5 hover:bg-black/5 transition font-medium text-sm flex items-center space-x-1"
|
||||
|
|
@ -192,80 +195,81 @@
|
|||
</button>
|
||||
</Tooltip>
|
||||
</div> -->
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<hr class=" border-gray-100 dark:border-gray-700/10 mt-1.5 mb-2.5 w-full" />
|
||||
<hr class=" border-gray-100 dark:border-gray-700/10 mt-1.5 mb-2.5 w-full" />
|
||||
|
||||
<div class="flex flex-col gap-2 mb-1 px-0.5">
|
||||
{#if accessGroups.length > 0}
|
||||
{#each accessGroups as group}
|
||||
<div class="flex items-center gap-3 justify-between text-xs w-full transition">
|
||||
<div class="flex items-center gap-1.5 w-full font-medium">
|
||||
<div>
|
||||
<UserCircleSolid className="size-4" />
|
||||
<div class="flex flex-col gap-2 mb-1 px-0.5">
|
||||
{#if accessGroups.length > 0}
|
||||
{#each accessGroups as group}
|
||||
<div class="flex items-center gap-3 justify-between text-xs w-full transition">
|
||||
<div class="flex items-center gap-1.5 w-full font-medium">
|
||||
<div>
|
||||
<UserCircleSolid className="size-4" />
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{group.name}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
{group.name}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="w-full flex justify-end items-center gap-0.5">
|
||||
<button
|
||||
class=""
|
||||
type="button"
|
||||
on:click={() => {
|
||||
if (accessRoles.includes('write')) {
|
||||
if ((accessControl?.write?.group_ids ?? []).includes(group.id)) {
|
||||
accessControl.write.group_ids = (
|
||||
accessControl?.write?.group_ids ?? []
|
||||
).filter((group_id) => group_id !== group.id);
|
||||
} else {
|
||||
accessControl.write.group_ids = [
|
||||
...(accessControl?.write?.group_ids ?? []),
|
||||
group.id
|
||||
];
|
||||
<div class="w-full flex justify-end items-center gap-0.5">
|
||||
<button
|
||||
class=""
|
||||
type="button"
|
||||
on:click={() => {
|
||||
if (accessRoles.includes('write')) {
|
||||
if ((accessControl?.write?.group_ids ?? []).includes(group.id)) {
|
||||
accessControl.write.group_ids = (
|
||||
accessControl?.write?.group_ids ?? []
|
||||
).filter((group_id) => group_id !== group.id);
|
||||
} else {
|
||||
accessControl.write.group_ids = [
|
||||
...(accessControl?.write?.group_ids ?? []),
|
||||
group.id
|
||||
];
|
||||
}
|
||||
onChange(accessControl);
|
||||
}
|
||||
onChange(accessControl);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{#if (accessControl?.write?.group_ids ?? []).includes(group.id)}
|
||||
<Badge type={'success'} content={$i18n.t('Write')} />
|
||||
{:else}
|
||||
<Badge type={'info'} content={$i18n.t('Read')} />
|
||||
{/if}
|
||||
</button>
|
||||
}}
|
||||
>
|
||||
{#if (accessControl?.write?.group_ids ?? []).includes(group.id)}
|
||||
<Badge type={'success'} content={$i18n.t('Write')} />
|
||||
{:else}
|
||||
<Badge type={'info'} content={$i18n.t('Read')} />
|
||||
{/if}
|
||||
</button>
|
||||
|
||||
<button
|
||||
class=" rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-850 transition"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
accessControl.read.group_ids = (accessControl?.read?.group_ids ?? []).filter(
|
||||
(id) => id !== group.id
|
||||
);
|
||||
accessControl.write.group_ids = (
|
||||
accessControl?.write?.group_ids ?? []
|
||||
).filter((id) => id !== group.id);
|
||||
onChange(accessControl);
|
||||
}}
|
||||
>
|
||||
<XMark />
|
||||
</button>
|
||||
<button
|
||||
class=" rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-850 transition"
|
||||
type="button"
|
||||
on:click={() => {
|
||||
accessControl.read.group_ids = (
|
||||
accessControl?.read?.group_ids ?? []
|
||||
).filter((id) => id !== group.id);
|
||||
accessControl.write.group_ids = (
|
||||
accessControl?.write?.group_ids ?? []
|
||||
).filter((id) => id !== group.id);
|
||||
onChange(accessControl);
|
||||
}}
|
||||
>
|
||||
<XMark />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="flex items-center justify-center">
|
||||
<div class="text-gray-500 text-xs text-center py-2 px-10">
|
||||
{$i18n.t('No groups with access, add a group to grant access')}
|
||||
</div>
|
||||
</div>
|
||||
{/each}
|
||||
{:else}
|
||||
<div class="flex items-center justify-center">
|
||||
<div class="text-gray-500 text-xs text-center py-2 px-10">
|
||||
{$i18n.t('No groups with access, add a group to grant access')}
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
{/if}
|
||||
{/if}
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@
|
|||
export let show = false;
|
||||
export let accessControl = {};
|
||||
export let accessRoles = ['read'];
|
||||
export let allowPublic = true;
|
||||
|
||||
export let share = true;
|
||||
export let sharePublic = true;
|
||||
|
||||
export let onChange = () => {};
|
||||
</script>
|
||||
|
|
@ -31,7 +33,7 @@
|
|||
</div>
|
||||
|
||||
<div class="w-full px-5 pb-4 dark:text-white">
|
||||
<AccessControl bind:accessControl {onChange} {accessRoles} {allowPublic} />
|
||||
<AccessControl bind:accessControl {onChange} {accessRoles} {share} {sharePublic} />
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
|
|
|
|||
Loading…
Reference in a new issue