From 770d81350ab64f1dd0cba5c446f7958cfd5fb07c Mon Sep 17 00:00:00 2001 From: Eric P Green Date: Fri, 8 Sep 2023 11:52:00 -0400 Subject: [PATCH] Add "View As" popover --- .../authentication/UserButton.svelte | 139 ++++++++++-------- .../authentication/ViewAsUserChip.svelte | 60 ++++++++ .../authentication/ViewAsUserMenuItem.svelte | 1 + .../authentication/ViewAsUserPopover.svelte | 83 +++++++++++ .../authentication/viewAsUserStore.ts | 4 + .../navigation/TopNavigationBar.svelte | 5 + .../updateMimickedJWT.ts | 41 ++++++ 7 files changed, 273 insertions(+), 60 deletions(-) create mode 100644 web-admin/src/components/authentication/ViewAsUserChip.svelte create mode 100644 web-admin/src/components/authentication/ViewAsUserMenuItem.svelte create mode 100644 web-admin/src/components/authentication/ViewAsUserPopover.svelte create mode 100644 web-admin/src/components/authentication/viewAsUserStore.ts create mode 100644 web-common/src/features/dashboards/granular-access-policies/updateMimickedJWT.ts diff --git a/web-admin/src/components/authentication/UserButton.svelte b/web-admin/src/components/authentication/UserButton.svelte index ef78d4eb0b0..eb173fa7ee9 100644 --- a/web-admin/src/components/authentication/UserButton.svelte +++ b/web-admin/src/components/authentication/UserButton.svelte @@ -1,20 +1,21 @@ - (menuOpen = true)} - on:close={() => (menuOpen = false)} -> - avatar - + + avatar + + - {#if $page.params.organization && $page.params.project} - - { - handleClose(); - handleViewAs(); - }} + + {#if $page.params.organization && $page.params.project && $page.params.dashboard} + - View as - - - {/if} - { - handleClose(); - handleLogOut(); - }}>Logout - { - handleClose(); - handleDocumentation(); - }}>Documentation - - + + + + + View as + + + + + close1(undefined)} + /> + + + + + {/if} + { + // handleClose(); + handleLogOut(); + }}>Logout + { + // handleClose(); + handleDocumentation(); + }}>Documentation + + + diff --git a/web-admin/src/components/authentication/ViewAsUserChip.svelte b/web-admin/src/components/authentication/ViewAsUserChip.svelte new file mode 100644 index 00000000000..e61fa50e622 --- /dev/null +++ b/web-admin/src/components/authentication/ViewAsUserChip.svelte @@ -0,0 +1,60 @@ + + + + { + // updateMimickedJWT(queryClient, null); + viewAsUserStore.set(null); + }} + active={open} + > +
+ +
+
+ Viewing as {$viewAsUserStore.email} +
+
+ +
+ +
+
+
+
+
+ + close(undefined)} + /> + +
+ + Clear view + +
+
diff --git a/web-admin/src/components/authentication/ViewAsUserMenuItem.svelte b/web-admin/src/components/authentication/ViewAsUserMenuItem.svelte new file mode 100644 index 00000000000..2e2e8969d4e --- /dev/null +++ b/web-admin/src/components/authentication/ViewAsUserMenuItem.svelte @@ -0,0 +1 @@ + diff --git a/web-admin/src/components/authentication/ViewAsUserPopover.svelte b/web-admin/src/components/authentication/ViewAsUserPopover.svelte new file mode 100644 index 00000000000..a3a2725e3ea --- /dev/null +++ b/web-admin/src/components/authentication/ViewAsUserPopover.svelte @@ -0,0 +1,83 @@ + + + +
+ Test your security policies by viewing this project from the perspective of another user. +
+ + {#if visibleUsers.length > 0} +
+ {#each visibleUsers as user} + viewAsUser(user)} + > + {user.email} + + {/each} +
+ {:else} +
no results
+ {/if} +
diff --git a/web-admin/src/components/authentication/viewAsUserStore.ts b/web-admin/src/components/authentication/viewAsUserStore.ts new file mode 100644 index 00000000000..a2f9a0f0fa4 --- /dev/null +++ b/web-admin/src/components/authentication/viewAsUserStore.ts @@ -0,0 +1,4 @@ +import { writable } from "svelte/store"; +import type { V1User } from "../../client"; + +export const viewAsUserStore = writable(null); diff --git a/web-admin/src/components/navigation/TopNavigationBar.svelte b/web-admin/src/components/navigation/TopNavigationBar.svelte index 52a365f6cea..ed3eecdee9a 100644 --- a/web-admin/src/components/navigation/TopNavigationBar.svelte +++ b/web-admin/src/components/navigation/TopNavigationBar.svelte @@ -6,6 +6,8 @@ import { createAdminServiceGetCurrentUser } from "../../client"; import SignIn from "../authentication/SignIn.svelte"; import UserButton from "../authentication/UserButton.svelte"; + import ViewAsUserChip from "../authentication/ViewAsUserChip.svelte"; + import { viewAsUserStore } from "../authentication/viewAsUserStore"; import { isErrorStoreEmpty } from "../errors/error-store"; import Breadcrumbs from "./Breadcrumbs.svelte"; @@ -38,6 +40,9 @@
{/if}