mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-18 04:43:55 +00:00
refac
This commit is contained in:
parent
f4557ca06b
commit
4a70253bc8
3 changed files with 45 additions and 26 deletions
|
|
@ -267,19 +267,22 @@ async def get_shared_folders(
|
|||
]
|
||||
|
||||
# Also include child folders of shared folders (inheritance)
|
||||
seen_ids = {folder.id for folder in shared_folders}
|
||||
result_by_id = {folder['id']: folder for folder in results}
|
||||
for folder in shared_folders:
|
||||
children = await Folders.get_children_folders_by_id_and_user_id(folder.id, folder.user_id, db=db)
|
||||
for child in children or []:
|
||||
if child.id not in seen_ids:
|
||||
seen_ids.add(child.id)
|
||||
results.append(
|
||||
{
|
||||
**child.model_dump(),
|
||||
'owner_name': owner_names.get(child.user_id, 'Unknown'),
|
||||
'permission': 'write' if child.user_id == user.id else folder_perms[folder.id],
|
||||
}
|
||||
)
|
||||
permission = 'write' if folder.user_id == user.id or child.user_id == user.id else folder_perms[folder.id]
|
||||
if child.id in result_by_id:
|
||||
# A weaker direct grant must not hide inherited write access.
|
||||
if permission == 'write':
|
||||
result_by_id[child.id]['permission'] = 'write'
|
||||
else:
|
||||
result_by_id[child.id] = {
|
||||
**child.model_dump(),
|
||||
'owner_name': owner_names.get(child.user_id, 'Unknown'),
|
||||
'permission': permission,
|
||||
}
|
||||
results.append(result_by_id[child.id])
|
||||
|
||||
return results
|
||||
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
import type { Writable } from 'svelte/store';
|
||||
import type { i18n as i18nType } from 'i18next';
|
||||
import { getContext } from 'svelte';
|
||||
import { toast } from 'svelte-sonner';
|
||||
const i18n = getContext<Writable<i18nType>>('i18n');
|
||||
|
||||
import Modal from '$lib/components/common/Modal.svelte';
|
||||
|
|
@ -38,15 +39,17 @@
|
|||
shareMode = freshFolder.data?.share_mode ?? null;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to load folder access grants', e);
|
||||
toast.error(`${e}`);
|
||||
accessGrants = folder?.access_grants ?? [];
|
||||
shareMode = folder?.data?.share_mode ?? null;
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
};
|
||||
|
||||
const handleAccessChange = async () => {
|
||||
if (!folder) return;
|
||||
if (!folder || loading) return;
|
||||
loading = true;
|
||||
try {
|
||||
const res = await updateFolderAccessById(
|
||||
localStorage.token,
|
||||
|
|
@ -56,10 +59,13 @@
|
|||
);
|
||||
if (res) {
|
||||
accessGrants = res.access_grants ?? accessGrants;
|
||||
toast.success($i18n.t('Saved'));
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to update folder access', e);
|
||||
toast.error(`${e}`);
|
||||
await loadAccessGrants();
|
||||
} finally {
|
||||
loading = false;
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
|
@ -81,9 +87,13 @@
|
|||
</button>
|
||||
</div>
|
||||
|
||||
<div class="w-full px-5 pb-4 dark:text-white">
|
||||
<div class="w-full px-5 pb-4 dark:text-white" inert={loading} aria-busy={loading}>
|
||||
<AccessControl
|
||||
bind:accessGrants
|
||||
labels={{
|
||||
private: $i18n.t('Restricted'),
|
||||
empty: folder?.parent_id ? $i18n.t('No direct access grants.') : undefined
|
||||
}}
|
||||
onChange={handleAccessChange}
|
||||
accessRoles={['read', 'write']}
|
||||
defaultPermission="write"
|
||||
|
|
@ -93,19 +103,23 @@
|
|||
allowGroups={$user?.role === 'admin' ||
|
||||
($user?.permissions?.access_grants?.allow_groups ?? true)}
|
||||
>
|
||||
{#if accessGrants.length > 0}
|
||||
<label class="flex w-full items-center justify-between mt-3 mb-1 text-xs">
|
||||
<span>{$i18n.t('Sharing mode')}</span>
|
||||
<select
|
||||
class="bg-transparent text-xs outline-none"
|
||||
bind:value={shareMode}
|
||||
on:change={handleAccessChange}
|
||||
>
|
||||
<option value={null}>{$i18n.t('Clone only')}</option>
|
||||
<option value="continue">{$i18n.t('Allow replies')}</option>
|
||||
</select>
|
||||
</label>
|
||||
{#if folder?.parent_id}
|
||||
<p class="text-xs text-gray-500 dark:text-gray-400">
|
||||
{$i18n.t('Access granted to parent folders also applies here.')}
|
||||
</p>
|
||||
{/if}
|
||||
<label class="flex w-full items-center justify-between mt-3 mb-1 text-xs">
|
||||
<span>{$i18n.t('Sharing mode')}</span>
|
||||
<select
|
||||
class="bg-transparent text-xs outline-none"
|
||||
bind:value={shareMode}
|
||||
disabled={loading}
|
||||
on:change={handleAccessChange}
|
||||
>
|
||||
<option value={null}>{$i18n.t('Clone only')}</option>
|
||||
<option value="continue">{$i18n.t('Allow replies')}</option>
|
||||
</select>
|
||||
</label>
|
||||
</AccessControl>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -88,6 +88,7 @@
|
|||
"about the Roman Empire": "",
|
||||
"Accept Autocomplete Generation\nJump to Prompt Variable": "",
|
||||
"Access": "",
|
||||
"Access granted to parent folders also applies here.": "Access granted to parent folders also applies here.",
|
||||
"Access Control": "",
|
||||
"Access Grants": "",
|
||||
"Access level": "",
|
||||
|
|
@ -1719,6 +1720,7 @@
|
|||
"Next version": "",
|
||||
"No": "",
|
||||
"No access grants. Private to you.": "",
|
||||
"No direct access grants.": "No direct access grants.",
|
||||
"No actions found": "",
|
||||
"No activity data": "",
|
||||
"No additional headers are sent unless configured.": "",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue