-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Add impersonate banner #14734
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
Add impersonate banner #14734
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { jwtDecode } from 'jwt-decode'; | ||
import { selector } from 'recoil'; | ||
import { isDefined } from 'twenty-shared/utils'; | ||
import { tokenPairState } from './tokenPairState'; | ||
|
||
export const isImpersonatingState = selector<boolean>({ | ||
key: 'isImpersonatingState', | ||
get: ({ get }) => { | ||
const tokenPair = get(tokenPairState); | ||
|
||
if (!isDefined(tokenPair?.accessOrWorkspaceAgnosticToken?.token)) { | ||
return false; | ||
} | ||
|
||
try { | ||
const decodedToken = jwtDecode<{ isImpersonating: boolean }>( | ||
tokenPair.accessOrWorkspaceAgnosticToken.token, | ||
); | ||
return decodedToken?.isImpersonating ?? false; | ||
} catch { | ||
return false; | ||
} | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import { useAuth } from '@/auth/hooks/useAuth'; | ||
import { currentWorkspaceMemberState } from '@/auth/states/currentWorkspaceMemberState'; | ||
import { InformationBanner } from '@/information-banner/components/InformationBanner'; | ||
import { t } from '@lingui/core/macro'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { isDefined } from 'twenty-shared/utils'; | ||
import { IconLogout } from 'twenty-ui/display'; | ||
|
||
export const InformationBannerIsImpersonating = () => { | ||
const currentWorkspaceMember = useRecoilValue(currentWorkspaceMemberState); | ||
const { signOut } = useAuth(); | ||
|
||
if (!isDefined(currentWorkspaceMember)) { | ||
return null; | ||
} | ||
|
||
const impersonatedUser = `${currentWorkspaceMember.name.firstName} ${currentWorkspaceMember.name.lastName} (${currentWorkspaceMember.userEmail})`; | ||
|
||
return ( | ||
<InformationBanner | ||
message={t`Logged in as ${impersonatedUser}`} | ||
buttonTitle={t`Stop impersonating`} | ||
buttonIcon={IconLogout} | ||
buttonOnClick={signOut} | ||
/> | ||
); | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { isImpersonatingState } from '@/auth/states/isImpersonatingState'; | ||
import { useHasPermissionFlag } from '@/settings/roles/hooks/useHasPermissionFlag'; | ||
import { Dropdown } from '@/ui/layout/dropdown/components/Dropdown'; | ||
import { DropdownContent } from '@/ui/layout/dropdown/components/DropdownContent'; | ||
import { DropdownMenuItemsContainer } from '@/ui/layout/dropdown/components/DropdownMenuItemsContainer'; | ||
import { useCloseDropdown } from '@/ui/layout/dropdown/hooks/useCloseDropdown'; | ||
import { type WorkspaceMember } from '@/workspace-member/types/WorkspaceMember'; | ||
import { t } from '@lingui/core/macro'; | ||
import { useRecoilValue } from 'recoil'; | ||
import { IconDotsVertical, IconSpy, IconTrash } from 'twenty-ui/display'; | ||
import { LightIconButton } from 'twenty-ui/input'; | ||
import { MenuItem } from 'twenty-ui/navigation'; | ||
|
@@ -24,7 +26,9 @@ export const ManageMembersDropdownMenu = ({ | |
onImpersonate, | ||
}: ManageMembersDropdownMenuProps) => { | ||
const { closeDropdown } = useCloseDropdown(); | ||
const canImpersonate = useHasPermissionFlag(PermissionFlagType.IMPERSONATE); | ||
const isImpersonating = useRecoilValue(isImpersonatingState); | ||
const canImpersonate = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are we not looking at canImpersonate from user state as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It has been approved in previous PR like that. And I think I'm ok with it because impersonation can be done at two levels, workspace and server. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, makes sense, ok SGDM! |
||
useHasPermissionFlag(PermissionFlagType.IMPERSONATE) && !isImpersonating; | ||
|
||
return ( | ||
<Dropdown | ||
|
Uh oh!
There was an error while loading. Please reload this page.