mirror of
https://github.com/open-webui/open-webui.git
synced 2025-12-12 04:15:25 +00:00
refac: access control
This commit is contained in:
parent
c8780a7f93
commit
32015c392d
1 changed files with 35 additions and 40 deletions
|
|
@ -21,6 +21,11 @@
|
||||||
let groups = [];
|
let groups = [];
|
||||||
|
|
||||||
$: if (!allowPublic && accessControl === null) {
|
$: if (!allowPublic && accessControl === null) {
|
||||||
|
initPublicAccess();
|
||||||
|
}
|
||||||
|
|
||||||
|
const initPublicAccess = () => {
|
||||||
|
if (!allowPublic && accessControl === null) {
|
||||||
accessControl = {
|
accessControl = {
|
||||||
read: {
|
read: {
|
||||||
group_ids: [],
|
group_ids: [],
|
||||||
|
|
@ -33,26 +38,13 @@
|
||||||
};
|
};
|
||||||
onChange(accessControl);
|
onChange(accessControl);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
groups = await getGroups(localStorage.token);
|
groups = await getGroups(localStorage.token);
|
||||||
|
|
||||||
if (accessControl === null) {
|
if (accessControl === null) {
|
||||||
if (allowPublic) {
|
initPublicAccess();
|
||||||
accessControl = null;
|
|
||||||
} else {
|
|
||||||
accessControl = {
|
|
||||||
read: {
|
|
||||||
group_ids: [],
|
|
||||||
user_ids: []
|
|
||||||
},
|
|
||||||
write: {
|
|
||||||
group_ids: [],
|
|
||||||
user_ids: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
onChange(accessControl);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
accessControl = {
|
accessControl = {
|
||||||
read: {
|
read: {
|
||||||
|
|
@ -66,20 +58,6 @@
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$: onChange(accessControl);
|
|
||||||
|
|
||||||
$: if (selectedGroupId) {
|
|
||||||
onSelectGroup();
|
|
||||||
}
|
|
||||||
|
|
||||||
const onSelectGroup = () => {
|
|
||||||
if (selectedGroupId !== '') {
|
|
||||||
accessControl.read.group_ids = [...(accessControl?.read?.group_ids ?? []), selectedGroupId];
|
|
||||||
|
|
||||||
selectedGroupId = '';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class=" rounded-lg flex flex-col gap-2">
|
<div class=" rounded-lg flex flex-col gap-2">
|
||||||
|
|
@ -143,6 +121,7 @@
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
onChange(accessControl);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<option class=" text-gray-700" value="private" selected>{$i18n.t('Private')}</option>
|
<option class=" text-gray-700" value="private" selected>{$i18n.t('Private')}</option>
|
||||||
|
|
@ -182,6 +161,17 @@
|
||||||
{selectedGroupId ? '' : 'text-gray-500'}
|
{selectedGroupId ? '' : 'text-gray-500'}
|
||||||
dark:placeholder-gray-500"
|
dark:placeholder-gray-500"
|
||||||
bind:value={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
|
<option class=" text-gray-700" value="" disabled selected
|
||||||
>{$i18n.t('Select a group')}</option
|
>{$i18n.t('Select a group')}</option
|
||||||
|
|
@ -238,6 +228,7 @@
|
||||||
group.id
|
group.id
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
onChange(accessControl);
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
@ -255,6 +246,10 @@
|
||||||
accessControl.read.group_ids = (accessControl?.read?.group_ids ?? []).filter(
|
accessControl.read.group_ids = (accessControl?.read?.group_ids ?? []).filter(
|
||||||
(id) => id !== group.id
|
(id) => id !== group.id
|
||||||
);
|
);
|
||||||
|
accessControl.write.group_ids = (
|
||||||
|
accessControl?.write?.group_ids ?? []
|
||||||
|
).filter((id) => id !== group.id);
|
||||||
|
onChange(accessControl);
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<XMark />
|
<XMark />
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue