Enforce implied permissions on permission changes
Diff
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(-)
@@ -45,6 +45,7 @@
export interface CrateMembers {
possible_permissions: string[];
implied_permissions: [string[], string[]][];
members: CrateMember[];
}
@@ -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}
@@ -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"
/>
<label for={`${member.uuid}-${permission}`}>{permission}</label>
</div>
@@ -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}