-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Feat/assume user #3742
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Feat/assume user #3742
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d209682
Allow admin users to assume user sessions
d53a41f
Add explicit role check
1776ee8
Fix lint
831f336
Remove admin panel when impersonating
1619ec2
Merge branch 'staging' into feat/assume-user
TheodoreSpeaks 6f97d5a
Fix lint
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
apps/sim/app/workspace/[workspaceId]/impersonation-banner.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| 'use client' | ||
|
|
||
| import { useState } from 'react' | ||
| import { Banner } from '@/components/emcn' | ||
| import { useSession } from '@/lib/auth/auth-client' | ||
| import { useStopImpersonating } from '@/hooks/queries/admin-users' | ||
|
|
||
| function getImpersonationBannerText(userLabel: string, userEmail?: string) { | ||
| return `Impersonating ${userLabel}${userEmail ? ` (${userEmail})` : ''}. Changes will apply to this account until you switch back.` | ||
| } | ||
|
|
||
| export function ImpersonationBanner() { | ||
| const { data: session, isPending } = useSession() | ||
| const stopImpersonating = useStopImpersonating() | ||
| const [isRedirecting, setIsRedirecting] = useState(false) | ||
| const userLabel = session?.user?.name || 'this user' | ||
| const userEmail = session?.user?.email | ||
|
|
||
| if (isPending || !session?.session?.impersonatedBy) { | ||
| return null | ||
| } | ||
|
|
||
| return ( | ||
| <Banner | ||
| variant='destructive' | ||
| text={getImpersonationBannerText(userLabel, userEmail)} | ||
| textClassName='text-red-700 dark:text-red-300' | ||
| actionLabel={ | ||
| stopImpersonating.isPending || isRedirecting ? 'Returning...' : 'Stop impersonating' | ||
| } | ||
| actionVariant='destructive' | ||
| actionDisabled={stopImpersonating.isPending || isRedirecting} | ||
| onAction={() => | ||
| stopImpersonating.mutate(undefined, { | ||
| onError: () => { | ||
| setIsRedirecting(false) | ||
| }, | ||
| onSuccess: () => { | ||
| setIsRedirecting(true) | ||
| window.location.assign('/workspace') | ||
| }, | ||
| }) | ||
| } | ||
| /> | ||
| ) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| 'use client' | ||
|
|
||
| import type { HTMLAttributes, ReactNode } from 'react' | ||
| import { cva, type VariantProps } from 'class-variance-authority' | ||
| import { Button, type ButtonProps } from '@/components/emcn/components/button/button' | ||
| import { cn } from '@/lib/core/utils/cn' | ||
|
|
||
| const bannerVariants = cva('shrink-0 px-[24px] py-[10px]', { | ||
| variants: { | ||
| variant: { | ||
| default: 'bg-[var(--surface-active)]', | ||
| destructive: 'bg-red-50 dark:bg-red-950/30', | ||
| }, | ||
| }, | ||
| defaultVariants: { | ||
| variant: 'default', | ||
| }, | ||
| }) | ||
|
|
||
| export interface BannerProps | ||
| extends HTMLAttributes<HTMLDivElement>, | ||
| VariantProps<typeof bannerVariants> { | ||
| actionClassName?: string | ||
| actionDisabled?: boolean | ||
| actionLabel?: ReactNode | ||
| actionProps?: Omit<ButtonProps, 'children' | 'className' | 'disabled' | 'onClick' | 'variant'> | ||
| actionVariant?: ButtonProps['variant'] | ||
| children?: ReactNode | ||
| contentClassName?: string | ||
| onAction?: () => void | ||
| text?: ReactNode | ||
| textClassName?: string | ||
| } | ||
|
|
||
| export function Banner({ | ||
| actionClassName, | ||
| actionDisabled, | ||
| actionLabel, | ||
| actionProps, | ||
| actionVariant = 'default', | ||
| children, | ||
| className, | ||
| contentClassName, | ||
| onAction, | ||
| text, | ||
| textClassName, | ||
| variant, | ||
| ...props | ||
| }: BannerProps) { | ||
| return ( | ||
| <div className={cn(bannerVariants({ variant }), className)} {...props}> | ||
| {children ?? ( | ||
| <div | ||
| className={cn( | ||
| 'mx-auto flex max-w-[1400px] items-center justify-between gap-[12px]', | ||
| contentClassName | ||
| )} | ||
| > | ||
| <p className={cn('text-[13px]', textClassName)}>{text}</p> | ||
| {actionLabel ? ( | ||
| <Button | ||
| variant={actionVariant} | ||
| className={cn('h-[28px] shrink-0 px-[8px] text-[12px]', actionClassName)} | ||
| onClick={onAction} | ||
| disabled={actionDisabled} | ||
| {...actionProps} | ||
| > | ||
| {actionLabel} | ||
| </Button> | ||
| ) : null} | ||
| </div> | ||
| )} | ||
| </div> | ||
| ) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.