refac
This commit is contained in:
1 parent
f84dabe3d9
commit
77da3d8c81
1 file changed
+57
-31
@@ -35,6 +35,8 @@
|
|||||||
export let share = true;
|
export let share = true;
|
||||||
export let sharePublic = true;
|
export let sharePublic = true;
|
||||||
export let shareUsers = true;
|
export let shareUsers = true;
|
||||||
|
export let allowGroups = true;
|
||||||
|
export let defaultPermission: 'read' | 'write' = 'read';
|
||||||
|
|
||||||
let groups: any[] = [];
|
let groups: any[] = [];
|
||||||
const resolvingGroupIds = new Set<string>();
|
const resolvingGroupIds = new Set<string>();
|
||||||
@@ -326,10 +328,16 @@
|
|||||||
let next = [...currentGrants()];
|
let next = [...currentGrants()];
|
||||||
|
|
||||||
for (const groupId of groupIds) {
|
for (const groupId of groupIds) {
|
||||||
next = upsertPrincipalGrant('group', groupId, 'read', next);
|
if (defaultPermission === 'write') {
|
||||||
|
next = upsertPrincipalGrant('group', groupId, 'read', next);
|
||||||
|
}
|
||||||
|
next = upsertPrincipalGrant('group', groupId, defaultPermission, next);
|
||||||
}
|
}
|
||||||
for (const userId of userIds) {
|
for (const userId of userIds) {
|
||||||
next = upsertPrincipalGrant('user', userId, 'read', next);
|
if (defaultPermission === 'write') {
|
||||||
|
next = upsertPrincipalGrant('user', userId, 'read', next);
|
||||||
|
}
|
||||||
|
next = upsertPrincipalGrant('user', userId, defaultPermission, next);
|
||||||
}
|
}
|
||||||
commitAccessGrants(next);
|
commitAccessGrants(next);
|
||||||
};
|
};
|
||||||
@@ -442,7 +450,13 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<AddAccessModal bind:show={showAddAccessModal} {shareUsers} onAdd={handleAddAccess} />
|
<AddAccessModal
|
||||||
|
bind:show={showAddAccessModal}
|
||||||
|
{shareUsers}
|
||||||
|
{allowGroups}
|
||||||
|
{accessGrants}
|
||||||
|
onAdd={handleAddAccess}
|
||||||
|
/>
|
||||||
|
|
||||||
<div class=" rounded-lg flex flex-col gap-1">
|
<div class=" rounded-lg flex flex-col gap-1">
|
||||||
<div class="py-2">
|
<div class="py-2">
|
||||||
@@ -570,20 +584,26 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w-full flex justify-end items-center gap-2">
|
<div class="w-full flex justify-end items-center gap-2">
|
||||||
<button
|
{#if accessRoles.includes('write')}
|
||||||
type="button"
|
<select
|
||||||
on:click={() => {
|
aria-label={$i18n.t('Access level')}
|
||||||
if (accessRoles.includes('write')) {
|
class="bg-transparent text-sm"
|
||||||
togglePrincipalWrite('group', group.id);
|
value={writeGroupIds.includes(group.id) ? 'write' : 'read'}
|
||||||
}
|
on:change={(e) => {
|
||||||
}}
|
if (
|
||||||
>
|
((e.target as HTMLSelectElement).value === 'write') !==
|
||||||
{#if writeGroupIds.includes(group.id)}
|
writeGroupIds.includes(group.id)
|
||||||
<Badge type={'success'} content={$i18n.t('Write')} />
|
) {
|
||||||
{:else}
|
togglePrincipalWrite('group', group.id);
|
||||||
<Badge type={'info'} content={$i18n.t('Read')} />
|
}
|
||||||
{/if}
|
}}
|
||||||
</button>
|
>
|
||||||
|
<option value="read">{$i18n.t('Read')}</option>
|
||||||
|
<option value="write">{$i18n.t('Write')}</option>
|
||||||
|
</select>
|
||||||
|
{: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"
|
class=" rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-850 transition"
|
||||||
@@ -618,20 +638,26 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="w-full flex justify-end items-center gap-2">
|
<div class="w-full flex justify-end items-center gap-2">
|
||||||
<button
|
{#if accessRoles.includes('write')}
|
||||||
type="button"
|
<select
|
||||||
on:click={() => {
|
aria-label={$i18n.t('Access level')}
|
||||||
if (accessRoles.includes('write')) {
|
class="bg-transparent text-sm"
|
||||||
togglePrincipalWrite('user', user.id);
|
value={writeUserIds.includes(user.id) ? 'write' : 'read'}
|
||||||
}
|
on:change={(e) => {
|
||||||
}}
|
if (
|
||||||
>
|
((e.target as HTMLSelectElement).value === 'write') !==
|
||||||
{#if writeUserIds.includes(user.id)}
|
writeUserIds.includes(user.id)
|
||||||
<Badge type={'success'} content={$i18n.t('Write')} />
|
) {
|
||||||
{:else}
|
togglePrincipalWrite('user', user.id);
|
||||||
<Badge type={'info'} content={$i18n.t('Read')} />
|
}
|
||||||
{/if}
|
}}
|
||||||
</button>
|
>
|
||||||
|
<option value="read">{$i18n.t('Read')}</option>
|
||||||
|
<option value="write">{$i18n.t('Write')}</option>
|
||||||
|
</select>
|
||||||
|
{: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"
|
class=" rounded-full p-1 hover:bg-gray-100 dark:hover:bg-gray-850 transition"
|
||||||
|
|||||||
Reference in new issue
Block a user