From efc6ce2225a5d6ba530be037eae365181efeedf8 Mon Sep 17 00:00:00 2001 From: Jordan Doyle Date: Sat, 10 Sep 2022 11:56:07 +0100 Subject: [PATCH] Enforce implied permissions on permission changes --- chartered-frontend/src/types/crate.ts | 1 + chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte | 2 ++ chartered-frontend/src/routes/(authed)/crates/[organisation]/Member.svelte | 29 ++++++++++++++++++++++++++++- chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/MemberTab.svelte | 2 ++ 4 files changed, 32 insertions(+), 2 deletions(-) diff --git a/chartered-frontend/src/types/crate.ts b/chartered-frontend/src/types/crate.ts index 661975b..a44a7fc 100644 --- a/chartered-frontend/src/types/crate.ts +++ a/chartered-frontend/src/types/crate.ts @@ -45,6 +45,7 @@ export interface CrateMembers { possible_permissions: string[]; + implied_permissions: [string[], string[]][]; members: CrateMember[]; } diff --git a/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte b/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte index a3d8d5f..49a1bc6 100644 --- a/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte +++ a/chartered-frontend/src/routes/(authed)/crates/[organisation]/+page.svelte @@ -183,6 +183,7 @@ {member} organisation={$page.params.organisation} possiblePermissions={organisation.possible_permissions} + impliedPermissions={organisation.implied_permissions} on:updated={reload} /> {/each} @@ -193,6 +194,7 @@ newPermissions={['VISIBLE']} organisation={$page.params.organisation} possiblePermissions={organisation.possible_permissions} + impliedPermissions={organisation.implied_permissions} on:updated={reload} /> {/if} diff --git a/chartered-frontend/src/routes/(authed)/crates/[organisation]/Member.svelte b/chartered-frontend/src/routes/(authed)/crates/[organisation]/Member.svelte index 6273faa..f4e5ba0 100644 --- a/chartered-frontend/src/routes/(authed)/crates/[organisation]/Member.svelte +++ a/chartered-frontend/src/routes/(authed)/crates/[organisation]/Member.svelte @@ -38,12 +38,36 @@ * A list of possible permissions this user can be given. */ export let possiblePermissions: string[]; - /** * A list of CSS classes to add to the outer div. */ let clazz = ''; export { clazz as class }; + + /** + * A list of permissions on the left that, when selected, imply that permissions on the other right will always + * apply to the user. + */ + export let impliedPermissions: [string[], string[]][]; + + /** + * A list of permissions, currently set on the member, that are enforced by implied permissions. + */ + let enforcedPermissions: string[] = []; + + // whenever the selected permissions changes, enforce impliedPermissions over the set + $: { + enforcedPermissions = []; + + for (const [expected, implied] of impliedPermissions) { + // if the selected permissions matches every expected permission... + if (expected.every((perm) => newPermissions.includes(perm))) { + /// ...apply all the implied permissions too + newPermissions = [...new Set(newPermissions.concat(implied))]; + enforcedPermissions = enforcedPermissions.concat(implied); + } + } + } /** * Whether the member is currently being persisted to the backend and a spinner is showing. @@ -150,8 +174,9 @@ id={`${member.uuid}-${permission}`} bind:group={newPermissions} value={permission} + disabled={enforcedPermissions.includes(permission)} type="checkbox" - class="w-4 h-4 mr-2 rounded border border-gray-200 dark:border-gray-700 bg-transparent ring-blue-500 focus:border-blue-500 !ring-offset-0" + class="w-4 h-4 mr-2 rounded disabled:bg-gray-300 disabled:hover:bg-gray-300 border border-gray-200 dark:border-gray-700 bg-transparent ring-blue-500 focus:border-blue-500 !ring-offset-0" /> diff --git a/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/MemberTab.svelte b/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/MemberTab.svelte index 9abfc2e..c2ab936 100644 --- a/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/MemberTab.svelte +++ a/chartered-frontend/src/routes/(authed)/crates/[organisation]/[crate]/MemberTab.svelte @@ -33,6 +33,7 @@ organisation={$page.params.organisation} crate={$page.params.crate} possiblePermissions={members.possible_permissions} + impliedPermissions={members.implied_permissions} on:updated={reloadMembers} /> {/each} @@ -44,6 +45,7 @@ organisation={$page.params.organisation} crate={$page.params.crate} possiblePermissions={members.possible_permissions} + impliedPermissions={members.implied_permissions} on:updated={reloadMembers} /> {/if} -- rgit 0.1.3