@axium/client 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/access.d.ts +3 -0
- package/dist/access.js +9 -0
- package/lib/AccessControlDialog.svelte +32 -16
- package/package.json +1 -1
package/dist/access.d.ts
ADDED
package/dist/access.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { fetchAPI } from './requests.js';
|
|
2
|
+
export async function setACL(itemType, itemId, data) {
|
|
3
|
+
if ('public' in data)
|
|
4
|
+
data.public = parseInt(data.public.toString());
|
|
5
|
+
return await fetchAPI('POST', 'acl/:itemType/:itemId', data, itemType, itemId);
|
|
6
|
+
}
|
|
7
|
+
export async function getACL(itemType, itemId) {
|
|
8
|
+
return await fetchAPI('GET', 'acl/:itemType/:itemId', {}, itemType, itemId);
|
|
9
|
+
}
|
|
@@ -1,24 +1,37 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import type { User } from '@axium/core';
|
|
3
|
-
import { permissionNames, type AccessControllable } from '@axium/core/access';
|
|
2
|
+
import type { AccessMap, User } from '@axium/core';
|
|
3
|
+
import { permissionNames, type AccessControllable, type AccessControl } from '@axium/core/access';
|
|
4
4
|
import type { Entries } from 'utilium';
|
|
5
5
|
import FormDialog from './FormDialog.svelte';
|
|
6
6
|
import UserCard from './UserCard.svelte';
|
|
7
|
+
import { userInfo } from '@axium/client/user';
|
|
8
|
+
import { getACL, setACL } from '@axium/client/access';
|
|
7
9
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
interface Props {
|
|
11
|
+
editable: boolean;
|
|
12
|
+
dialog?: HTMLDialogElement;
|
|
13
|
+
itemType: string;
|
|
14
|
+
item?: ({ name?: string; user?: User; id: string } & AccessControllable) | null;
|
|
15
|
+
acl?: AccessControl[];
|
|
16
|
+
}
|
|
17
|
+
let { item = $bindable(), itemType, editable, dialog = $bindable(), acl = $bindable(item?.acl) }: Props = $props();
|
|
18
|
+
|
|
19
|
+
if (!acl && item) getACL(itemType, item.id).then(fetched => (acl = item.acl = fetched));
|
|
13
20
|
|
|
14
21
|
const permEntries = Object.entries(permissionNames) as any as Entries<typeof permissionNames>;
|
|
15
22
|
|
|
16
|
-
const publicPerm = $derived(permissionNames[item
|
|
23
|
+
const publicPerm = $derived(permissionNames[item?.publicPermission || 0]);
|
|
17
24
|
</script>
|
|
18
25
|
|
|
19
|
-
<FormDialog
|
|
26
|
+
<FormDialog
|
|
27
|
+
bind:dialog
|
|
28
|
+
submitText="Save"
|
|
29
|
+
submit={async data => {
|
|
30
|
+
if (item) await setACL(itemType, item.id, data as any as AccessMap);
|
|
31
|
+
}}
|
|
32
|
+
>
|
|
20
33
|
{#snippet header()}
|
|
21
|
-
{#if item
|
|
34
|
+
{#if item?.name}
|
|
22
35
|
<h3>Permissions for <strong>{item.name}</strong></h3>
|
|
23
36
|
{:else}
|
|
24
37
|
<h3>Permissions</h3>
|
|
@@ -26,18 +39,21 @@
|
|
|
26
39
|
{/snippet}
|
|
27
40
|
|
|
28
41
|
<div class="AccessControl">
|
|
29
|
-
|
|
42
|
+
{#if item?.user}
|
|
43
|
+
<UserCard user={item.user} />
|
|
44
|
+
{:else if item}
|
|
45
|
+
{#await userInfo(item.userId) then user}<UserCard {user} />{/await}
|
|
46
|
+
{/if}
|
|
30
47
|
<span>Owner</span>
|
|
31
48
|
</div>
|
|
32
49
|
|
|
33
|
-
{#each
|
|
50
|
+
{#each acl ?? [] as control}
|
|
34
51
|
<div class="AccessControl">
|
|
35
52
|
{#if !control.user}<i>Unknown</i>
|
|
36
53
|
{:else}
|
|
37
54
|
<UserCard user={control.user} />
|
|
38
55
|
{#if editable}
|
|
39
|
-
<
|
|
40
|
-
<select name="permission">
|
|
56
|
+
<select name={control.userId}>
|
|
41
57
|
{#each permEntries as [key, name]}
|
|
42
58
|
<option value={key} selected={key == control.permission}>{name}</option>
|
|
43
59
|
{/each}
|
|
@@ -51,8 +67,8 @@
|
|
|
51
67
|
|
|
52
68
|
<div class="AccessControl public">
|
|
53
69
|
<strong>Public Access</strong>
|
|
54
|
-
{#if editable}
|
|
55
|
-
<select name="
|
|
70
|
+
{#if editable && item}
|
|
71
|
+
<select name="public">
|
|
56
72
|
{#each permEntries as [key, name]}
|
|
57
73
|
<option value={key} selected={key == item.publicPermission}>{name}</option>
|
|
58
74
|
{/each}
|