Add fields for admin panel access and workspace version (#10451)
Prepare for better version upgrade system + split admin panel into two permissions + fix GraphQL generation detection --------- Co-authored-by: ehconitin <nitinkoche03@gmail.com>
This commit is contained in:
@ -9,7 +9,9 @@ export const AppRouter = () => {
|
||||
|
||||
const currentUser = useRecoilValue(currentUserState);
|
||||
|
||||
const isAdminPageEnabled = currentUser?.canImpersonate;
|
||||
const isAdminPageEnabled =
|
||||
(currentUser?.canImpersonate || currentUser?.canAccessFullAdminPanel) ??
|
||||
false;
|
||||
|
||||
return (
|
||||
<RouterProvider
|
||||
|
||||
@ -52,6 +52,7 @@ export const results = {
|
||||
firstName: 'firstName',
|
||||
lastName: 'lastName',
|
||||
email: 'email',
|
||||
canAccessFullAdminPanel: false,
|
||||
canImpersonate: 'canImpersonate',
|
||||
supportUserHash: 'supportUserHash',
|
||||
workspaceMember: {
|
||||
|
||||
@ -8,6 +8,7 @@ export type CurrentUser = Pick<
|
||||
| 'email'
|
||||
| 'supportUserHash'
|
||||
| 'analyticsTinybirdJwts'
|
||||
| 'canAccessFullAdminPanel'
|
||||
| 'canImpersonate'
|
||||
| 'onboardingStatus'
|
||||
| 'userVars'
|
||||
|
||||
@ -128,6 +128,7 @@ export const queries = {
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
canAccessFullAdminPanel
|
||||
canImpersonate
|
||||
supportUserHash
|
||||
analyticsTinybirdJwts {
|
||||
@ -284,6 +285,7 @@ export const responseData = {
|
||||
firstName: 'Test',
|
||||
lastName: 'User',
|
||||
email: 'test@example.com',
|
||||
canAccessFullAdminPanel: false,
|
||||
canImpersonate: false,
|
||||
supportUserHash: null,
|
||||
analyticsTinybirdJwts: {
|
||||
|
||||
@ -9,6 +9,7 @@ import { TabList } from '@/ui/layout/tab/components/TabList';
|
||||
import { useTabList } from '@/ui/layout/tab/hooks/useTabList';
|
||||
import { DEFAULT_WORKSPACE_LOGO } from '@/ui/navigation/navigation-drawer/constants/DefaultWorkspaceLogo';
|
||||
import styled from '@emotion/styled';
|
||||
import { t } from '@lingui/core/macro';
|
||||
import { isNonEmptyString } from '@sniptt/guards';
|
||||
import { useState } from 'react';
|
||||
import { useRecoilState, useRecoilValue } from 'recoil';
|
||||
@ -24,8 +25,8 @@ import {
|
||||
} from 'twenty-ui';
|
||||
import { REACT_APP_SERVER_BASE_URL } from '~/config';
|
||||
import { useUserLookupAdminPanelMutation } from '~/generated/graphql';
|
||||
import { t } from '@lingui/core/macro';
|
||||
|
||||
import { currentUserState } from '@/auth/states/currentUserState';
|
||||
import packageJson from '../../../../../package.json';
|
||||
|
||||
const StyledContainer = styled.div`
|
||||
@ -53,6 +54,11 @@ const StyledContentContainer = styled.div`
|
||||
padding: ${({ theme }) => theme.spacing(4)} 0;
|
||||
`;
|
||||
|
||||
const StyledErrorMessage = styled.div`
|
||||
color: ${({ theme }) => theme.color.red};
|
||||
margin-top: ${({ theme }) => theme.spacing(2)};
|
||||
`;
|
||||
|
||||
export const SettingsAdminGeneral = () => {
|
||||
const [userIdentifier, setUserIdentifier] = useState('');
|
||||
const { enqueueSnackBar } = useSnackBar();
|
||||
@ -67,6 +73,10 @@ export const SettingsAdminGeneral = () => {
|
||||
|
||||
const [userLookup] = useUserLookupAdminPanelMutation();
|
||||
|
||||
const currentUser = useRecoilValue(currentUserState);
|
||||
|
||||
const canImpersonate = currentUser?.canImpersonate;
|
||||
|
||||
const canManageFeatureFlags = useRecoilValue(canManageFeatureFlagsState);
|
||||
|
||||
const handleSearch = async () => {
|
||||
@ -154,9 +164,16 @@ export const SettingsAdminGeneral = () => {
|
||||
accent="blue"
|
||||
title={t`Search`}
|
||||
onClick={handleSearch}
|
||||
disabled={!userIdentifier.trim() || isUserLookupLoading}
|
||||
disabled={
|
||||
!userIdentifier.trim() || isUserLookupLoading || !canImpersonate
|
||||
}
|
||||
/>
|
||||
</StyledContainer>
|
||||
{!canImpersonate && (
|
||||
<StyledErrorMessage>
|
||||
{t`You do not have access to impersonate users.`}
|
||||
</StyledErrorMessage>
|
||||
)}
|
||||
</Section>
|
||||
|
||||
{isDefined(userLookupResult) && (
|
||||
|
||||
@ -21,6 +21,7 @@ const mockCurrentUser = {
|
||||
email: 'fake@email.com',
|
||||
supportUserHash: null,
|
||||
analyticsTinybirdJwts: null,
|
||||
canAccessFullAdminPanel: false,
|
||||
canImpersonate: false,
|
||||
onboardingStatus: OnboardingStatus.COMPLETED,
|
||||
userVars: {},
|
||||
|
||||
@ -56,7 +56,9 @@ const useSettingsNavigationItems = (): SettingsNavigationSection[] => {
|
||||
const isFunctionSettingsEnabled = false;
|
||||
const isBillingEnabled = billing?.isBillingEnabled ?? false;
|
||||
const currentUser = useRecoilValue(currentUserState);
|
||||
const isAdminEnabled = currentUser?.canImpersonate ?? false;
|
||||
const isAdminEnabled =
|
||||
(currentUser?.canImpersonate || currentUser?.canAccessFullAdminPanel) ??
|
||||
false;
|
||||
const labPublicFeatureFlags = useRecoilValue(labPublicFeatureFlagsState);
|
||||
|
||||
const featureFlags = useFeatureFlagsMap();
|
||||
|
||||
@ -7,6 +7,7 @@ export const USER_QUERY_FRAGMENT = gql`
|
||||
firstName
|
||||
lastName
|
||||
email
|
||||
canAccessFullAdminPanel
|
||||
canImpersonate
|
||||
supportUserHash
|
||||
analyticsTinybirdJwts {
|
||||
|
||||
Reference in New Issue
Block a user