This commit is contained in:
Timothy Jaeryang Baek
2026-03-22 06:58:58 -05:00
parent 2e165926de
commit 945275faae
5 changed files with 56 additions and 6 deletions
@@ -12,6 +12,7 @@
import Plus from '$lib/components/icons/Plus.svelte';
import AddAccessModal from './AddAccessModal.svelte';
import Tooltip from '$lib/components/common/Tooltip.svelte';
import Switch from '$lib/components/common/Switch.svelte';
type AccessGrant = {
id?: string;
@@ -159,6 +160,12 @@
grant.principal_type === 'user' && grant.principal_id === '*' && grant.permission === 'read'
);
const hasPublicWriteGrant = (grants: AccessGrant[]): boolean =>
grants.some(
(grant) =>
grant.principal_type === 'user' && grant.principal_id === '*' && grant.permission === 'write'
);
const currentGrants = (): AccessGrant[] =>
Array.isArray(accessGrants) ? (accessGrants as AccessGrant[]) : [];
@@ -194,12 +201,12 @@
};
const setPublic = (isPublic: boolean) => {
// Remove all user:* grants
const filtered = currentGrants().filter(
(grant) =>
!(
grant.principal_type === 'user' &&
grant.principal_id === '*' &&
grant.permission === 'read'
grant.principal_id === '*'
)
);
if (isPublic) {
@@ -212,6 +219,23 @@
commitAccessGrants(filtered);
};
const togglePublicWrite = () => {
let next = [...currentGrants()];
if (hasPublicWriteGrant(next)) {
next = next.filter(
(grant) =>
!(
grant.principal_type === 'user' &&
grant.principal_id === '*' &&
grant.permission === 'write'
)
);
} else {
next = upsertPrincipalGrant('user', '*', 'write', next);
}
commitAccessGrants(next);
};
const upsertPrincipalGrant = (
principalType: 'user' | 'group',
principalId: string,
@@ -491,6 +515,20 @@
</div>
</div>
</div>
{#if hasPublicReadGrant(accessGrants ?? []) && accessRoles.includes('write')}
<div class="flex w-full justify-between mt-2 ml-0.5">
<div class="self-center text-xs">
{$i18n.t('Allow everyone to edit')}
</div>
<Switch
state={hasPublicWriteGrant(accessGrants ?? [])}
on:change={() => {
togglePublicWrite();
}}
/>
</div>
{/if}
</div>
{#if share}