From db8c4dd2492da31a4a93ff5bb03201c3f8d25f30 Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 18 Oct 2022 10:52:44 +0200 Subject: [PATCH] feat: add permissions to settings --- .../function/[function]/settings/+page.svelte | 48 ++++++++++++++++++- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/src/routes/console/project-[project]/functions/function/[function]/settings/+page.svelte b/src/routes/console/project-[project]/functions/function/[function]/settings/+page.svelte index 79163bfb4..60282b7e7 100644 --- a/src/routes/console/project-[project]/functions/function/[function]/settings/+page.svelte +++ b/src/routes/console/project-[project]/functions/function/[function]/settings/+page.svelte @@ -16,6 +16,8 @@ import { toLocaleDateTime } from '$lib/helpers/date'; import { variableList } from '../../../store'; import { breadcrumbs, title } from '$lib/stores/layout'; + import { Permissions } from '$lib/components/permissions'; + import { difference } from '$lib/helpers/array'; const functionId = $page.params.function; let showDelete = false; @@ -27,6 +29,8 @@ let timeout: number = null; let deployment: Models.Deployment = null; let functionName: string = null; + let permissions: string[] = []; + let arePermsDisabled = true; onMount(async () => { if ($func?.$id !== functionId) { @@ -36,6 +40,7 @@ deployment = await func.getDeployment(functionId, $func.deployment); timeout ??= $func.timeout; functionName ??= $func.name; + permissions ??= $func.execute; }); async function updateName() { @@ -57,6 +62,21 @@ }); } } + async function updatePermissions() { + try { + await sdkForProject.functions.update(functionId, $func.name, permissions); + $func.execute = permissions; + addNotification({ + message: 'Permissions have been updated', + type: 'success' + }); + } catch (error) { + addNotification({ + message: error.message, + type: 'error' + }); + } + } async function updateTimeout() { try { @@ -157,6 +177,12 @@ window.URL.revokeObjectURL(url); } } + + $: if (permissions) { + if (difference(permissions, $func.execute).length) { + arePermsDisabled = false; + } else arePermsDisabled = true; + } @@ -211,8 +237,26 @@ - + + + + + +
+ +
Execute Access
+

+ Choose who can execute this function using the client API. For more information, + check out the Permissions Guide in our documentation. +

+ + + + + +