Skip to content

Commit

Permalink
feat: bind allow anonymous in the frontend
Browse files Browse the repository at this point in the history
Signed-off-by: David Dal Busco <[email protected]>
  • Loading branch information
peterpeterparker committed Nov 12, 2023
1 parent 4237e3f commit 68e66d7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 6 deletions.
7 changes: 5 additions & 2 deletions src/frontend/src/lib/api/satellites.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ export const setRule = async ({
memory,
rule,
maxSize,
mutablePermissions
mutablePermissions,
allowAnonymous
}: {
satelliteId: Principal;
collection: string;
Expand All @@ -75,14 +76,16 @@ export const setRule = async ({
rule: Rule | undefined;
maxSize: number | undefined;
mutablePermissions: boolean;
allowAnonymous: boolean;
}) => {
const updateRule: SetRule = {
read: permissionFromText(read),
write: permissionFromText(write),
updated_at: isNullish(rule) ? [] : [rule.updated_at],
max_size: toNullable(nonNullish(maxSize) && maxSize > 0 ? BigInt(maxSize) : undefined),
memory: isNullish(rule) ? [memoryFromText(memory)] : [fromNullable(rule.memory) ?? MemoryHeap],
mutable_permissions: toNullable(mutablePermissions)
mutable_permissions: toNullable(mutablePermissions),
allow_anonymous: toNullable(allowAnonymous)
};

const actor = await getSatelliteActor(satelliteId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,14 @@
};
$: initMutable($store.rule?.[1] ?? undefined);
let currentAllowAnonymous: boolean;
let allowAnonymous: boolean;
const initAllowAnonymous = (initialRule: Rule | undefined) => {
currentAllowAnonymous = fromNullable(initialRule?.allow_anonymous ?? []) ?? false;
allowAnonymous = currentAllowAnonymous;
};
$: initAllowAnonymous($store.rule?.[1] ?? undefined);
let maxSize: number | undefined;
const initMaxLength = (size: [] | [bigint]) => {
const tmp = fromNullable(size);
Expand All @@ -78,7 +86,8 @@
type,
rule,
maxSize,
mutablePermissions: !immutable
mutablePermissions: !immutable,
allowAnonymous
});
toasts.success(
Expand Down Expand Up @@ -181,6 +190,17 @@
</div>
{/if}

<div class="checkbox">
<label>
<input
type="checkbox"
checked={allowAnonymous}
on:change={() => (allowAnonymous = !allowAnonymous)}
/>
<span>{$i18n.collections.allow_anonymous}</span>
</label>
</div>

{#if !currentImmutable}
<div class="checkbox">
<label>
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/lib/i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@
"memory": "Memory",
"heap": "Heap",
"stable": "Stable",
"immutable": "Make permissions immutable"
"immutable": "Make permissions immutable",
"allow_anonymous": "Allow anonymous calls"
},
"sort": {
"title": "Sort results",
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/lib/i18n/it.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@
"memory": "Memory",
"heap": "Heap",
"stable": "Stable",
"immutable": "Make permissions immutable"
"immutable": "Make permissions immutable",
"allow_anonymous": "Allow anonymous calls"
},
"sort": {
"title": "Ordina i risultati",
Expand Down
3 changes: 2 additions & 1 deletion src/frontend/src/lib/i18n/zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,8 @@
"memory": "内存",
"heap": "堆栈",
"stable": "稳定",
"immutable": "将权限改为只读"
"immutable": "将权限改为只读",
"allow_anonymous": "Allow anonymous calls"
},
"sort": {
"title": "排序结果",
Expand Down
1 change: 1 addition & 0 deletions src/frontend/src/lib/types/i18n.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@ interface I18nCollections {
heap: string;
stable: string;
immutable: string;
allow_anonymous: string;
}

interface I18nSort {
Expand Down

0 comments on commit 68e66d7

Please sign in to comment.