Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/TestToolMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {useSidebarOrderedReportsActions} from '@hooks/useSidebarOrderedReports';
import useThemeStyles from '@hooks/useThemeStyles';

import {isUsingStagingApi} from '@libs/ApiUtils';
import {useIsAgentAccount} from '@libs/SessionUtils';

import {setShouldFailAllRequests, setShouldForceOffline, setShouldSimulatePoorConnection} from '@userActions/Network';
import {expireSessionWithDelay, invalidateAuthToken, invalidateCredentials} from '@userActions/Session';
Expand Down Expand Up @@ -37,6 +38,9 @@ function TestToolMenu() {
// Check if the user is authenticated to show options that require authentication
const isAuthenticated = useIsAuthenticated();

// Agent accounts can't have biometric multifactor authentication, so hide the biometrics test row for them.
const isAgentAccount = useIsAgentAccount();

return (
<>
<Text
Expand Down Expand Up @@ -107,7 +111,7 @@ function TestToolMenu() {
</TestToolRow>

{/* Allows testing and revoking biometric multifactor authentication */}
<BiometricsTestToolRow />
{!isAgentAccount && <BiometricsTestToolRow />}
</>
)}

Expand Down
267 changes: 101 additions & 166 deletions src/libs/Navigation/AppNavigator/ModalStackNavigators/index.tsx

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@ const loadInitialSettingsPage = () => require<ReactComponentModule>('../../../..
type Screens = Partial<Record<keyof SettingsSplitNavigatorParamList, () => React.ComponentType>>;

const CENTRAL_PANE_SETTINGS_SCREENS = {
[SCREENS.SETTINGS.PREFERENCES.ROOT]: withAgentAccessDenied(() => require<ReactComponentModule>('../../../../pages/settings/Preferences/PreferencesPage').default),
[SCREENS.SETTINGS.SECURITY]: withAgentAccessDenied(() => require<ReactComponentModule>('../../../../pages/settings/Security/SecuritySettingsPage').default),
[SCREENS.SETTINGS.PREFERENCES.ROOT]: () => require<ReactComponentModule>('../../../../pages/settings/Preferences/PreferencesPage').default,
[SCREENS.SETTINGS.SECURITY]: () => require<ReactComponentModule>('../../../../pages/settings/Security/SecuritySettingsPage').default,
[SCREENS.SETTINGS.COPILOT]: () => require<ReactComponentModule>('../../../../pages/settings/Copilot/CopilotPage').default,
[SCREENS.SETTINGS.PROFILE.ROOT]: () => require<ReactComponentModule>('../../../../pages/settings/Profile/ProfilePage').default,
[SCREENS.SETTINGS.WALLET.ROOT]: withAgentAccessDenied(() => require<ReactComponentModule>('../../../../pages/settings/Wallet/WalletPage').default),
[SCREENS.SETTINGS.WALLET.ROOT]: () => require<ReactComponentModule>('../../../../pages/settings/Wallet/WalletPage').default,
[SCREENS.SETTINGS.AGENTS.ROOT]: withAgentAccessDenied(() => require<ReactComponentModule>('../../../../pages/settings/Agents/AgentsPage').default),
[SCREENS.SETTINGS.RULES.ROOT]: () => require<ReactComponentModule>('../../../../pages/settings/Rules/ExpenseRulesPage').default,
[SCREENS.SETTINGS.HELP]: () => require<ReactComponentModule>('../../../../pages/settings/HelpPage/HelpPage').default,
[SCREENS.SETTINGS.ABOUT]: () => require<ReactComponentModule>('../../../../pages/settings/AboutPage/AboutPage').default,
[SCREENS.SETTINGS.TROUBLESHOOT]: () => require<ReactComponentModule>('../../../../pages/settings/Troubleshoot/TroubleshootPage').default,
[SCREENS.SETTINGS.SAVE_THE_WORLD]: () => require<ReactComponentModule>('../../../../pages/TeachersUnite/SaveTheWorldPage').default,
[SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: withAgentAccessDenied(() => require<ReactComponentModule>('../../../../pages/settings/Subscription/SubscriptionSettingsPage').default),
[SCREENS.SETTINGS.SUBSCRIPTION.ROOT]: () => require<ReactComponentModule>('../../../../pages/settings/Subscription/SubscriptionSettingsPage').default,
} satisfies Screens;

const Split = createSplitNavigator<SettingsSplitNavigatorParamList>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function withAgentAccessDenied(getComponent: () => React.ComponentType): () => R
if (!shouldRedirect) {
return;
}
Navigation.navigate(ROUTES.SETTINGS_PROFILE.getRoute());
Navigation.isNavigationReady().then(() => Navigation.navigate(ROUTES.SETTINGS_PROFILE.getRoute()));
}, [shouldRedirect]);

if (shouldRedirect) {
Expand Down
62 changes: 25 additions & 37 deletions src/pages/settings/InitialSettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -274,56 +274,44 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.PROFILE,
action: () => Navigation.navigate(ROUTES.SETTINGS_PROFILE.getRoute()),
},
...(!isAgentAccount
? [
{
translationKey: 'common.wallet' as const,
icon: icons.Wallet,
screenName: SCREENS.SETTINGS.WALLET.ROOT,
brickRoadIndicator: walletBrickRoadIndicator,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.WALLET,
action: () => Navigation.navigate(ROUTES.SETTINGS_WALLET),
badgeText: hasActivatedWallet ? convertToDisplayString(userWallet?.currentBalance, CONST.CURRENCY.USD) : undefined,
},
]
: []),
{
translationKey: 'common.wallet',
icon: icons.Wallet,
screenName: SCREENS.SETTINGS.WALLET.ROOT,
brickRoadIndicator: walletBrickRoadIndicator,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.WALLET,
action: () => Navigation.navigate(ROUTES.SETTINGS_WALLET),
badgeText: hasActivatedWallet ? convertToDisplayString(userWallet?.currentBalance, CONST.CURRENCY.USD) : undefined,
},
{
translationKey: 'expenseRulesPage.title',
icon: icons.Bolt,
screenName: SCREENS.SETTINGS.RULES.ROOT,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.RULES,
action: () => Navigation.navigate(ROUTES.SETTINGS_RULES),
},
...(!isAgentAccount
? [
{
translationKey: 'common.preferences' as const,
icon: icons.Gear,
screenName: SCREENS.SETTINGS.PREFERENCES.ROOT,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.PREFERENCES,
action: () => Navigation.navigate(ROUTES.SETTINGS_PREFERENCES),
},
]
: []),
{
translationKey: 'common.preferences',
icon: icons.Gear,
screenName: SCREENS.SETTINGS.PREFERENCES.ROOT,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.PREFERENCES,
action: () => Navigation.navigate(ROUTES.SETTINGS_PREFERENCES),
},
{
translationKey: 'delegate.copilot',
icon: icons.Users,
screenName: SCREENS.SETTINGS.COPILOT,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.COPILOT,
action: () => Navigation.navigate(ROUTES.SETTINGS_COPILOT),
},
...(!isAgentAccount
? [
{
translationKey: 'initialSettingsPage.security' as const,
icon: icons.Lock,
screenName: SCREENS.SETTINGS.SECURITY,
brickRoadIndicator: securityBrickRoadIndicator,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.SECURITY,
action: () => Navigation.navigate(ROUTES.SETTINGS_SECURITY),
},
]
: []),
{
translationKey: 'initialSettingsPage.security' as const,
icon: icons.Lock,
screenName: SCREENS.SETTINGS.SECURITY,
brickRoadIndicator: securityBrickRoadIndicator,
sentryLabel: CONST.SENTRY_LABEL.ACCOUNT.SECURITY,
action: () => Navigation.navigate(ROUTES.SETTINGS_SECURITY),
},
];

if (!isAgentAccount && isBetaEnabled(CONST.BETAS.CUSTOM_AGENT)) {
Expand All @@ -339,7 +327,7 @@ function InitialSettingsPage({currentUserPersonalDetails}: InitialSettingsPagePr
});
}

if (!isAgentAccount && (subscriptionPlan || (amountOwed ?? 0) > 0)) {
if (subscriptionPlan || (amountOwed ?? 0) > 0) {
accountItems.splice(1, 0, {
translationKey: 'allSettingsScreen.subscription',
icon: icons.CreditCard,
Expand Down
72 changes: 35 additions & 37 deletions src/pages/settings/Profile/ProfilePage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ function ProfilePage() {
.map((login) => login?.menuItemTitle)
.filter(Boolean)
.join(', '),
pageRoute: isAgentAccount ? undefined : ROUTES.SETTINGS_CONTACT_METHODS.route,
brickRoadIndicator: isAgentAccount ? undefined : contactMethodBrickRoadIndicator,
testID: isAgentAccount ? undefined : 'contact-method-menu-item',
pageRoute: ROUTES.SETTINGS_CONTACT_METHODS.route,
brickRoadIndicator: contactMethodBrickRoadIndicator,
testID: 'contact-method-menu-item',
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_PROFILE.CONTACT_METHODS,
},
{
Expand Down Expand Up @@ -284,41 +284,39 @@ function ProfilePage() {
sentryLabel={CONST.SENTRY_LABEL.SETTINGS_PROFILE.SHARE_CODE}
/>
</Section>
{!isAgentAccount && (
<Section
title={translate('profilePage.privateSection.title')}
subtitle={translate('profilePage.privateSection.subtitle')}
isCentralPane
subtitleMuted
childrenStyles={styles.pt3}
titleStyles={styles.accountSettingsSectionTitle}
>
{isLoadingApp ? (
<View style={[styles.flex1, styles.pRelative, StyleUtils.getBackgroundColorStyle(theme.cardBG)]}>
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
reasonAttributes={privateSectionReasonAttributes}
<Section
title={translate('profilePage.privateSection.title')}
subtitle={translate('profilePage.privateSection.subtitle')}
isCentralPane
subtitleMuted
childrenStyles={styles.pt3}
titleStyles={styles.accountSettingsSectionTitle}
>
{isLoadingApp ? (
<View style={[styles.flex1, styles.pRelative, StyleUtils.getBackgroundColorStyle(theme.cardBG)]}>
<ActivityIndicator
size={CONST.ACTIVITY_INDICATOR_SIZE.LARGE}
reasonAttributes={privateSectionReasonAttributes}
/>
</View>
) : (
<MenuItemGroup shouldUseSingleExecution={!isActingAsDelegate}>
{privateOptions.map((detail, index) => (
<MenuItemWithTopDescription
// eslint-disable-next-line react/no-array-index-key
key={`${detail.title}_${index}`}
shouldShowRightIcon
title={detail.title}
description={detail.description}
wrapperStyle={styles.sectionMenuItemTopDescription}
onPress={detail.action}
brickRoadIndicator={detail.brickRoadIndicator}
sentryLabel={detail.sentryLabel}
/>
</View>
) : (
<MenuItemGroup shouldUseSingleExecution={!isActingAsDelegate}>
{privateOptions.map((detail, index) => (
<MenuItemWithTopDescription
// eslint-disable-next-line react/no-array-index-key
key={`${detail.title}_${index}`}
shouldShowRightIcon
title={detail.title}
description={detail.description}
wrapperStyle={styles.sectionMenuItemTopDescription}
onPress={detail.action}
brickRoadIndicator={detail.brickRoadIndicator}
sentryLabel={detail.sentryLabel}
/>
))}
</MenuItemGroup>
)}
</Section>
)}
))}
</MenuItemGroup>
)}
</Section>
{isAgentAccount && (
<AgentAIPromptSection
accountID={accountID}
Expand Down
16 changes: 11 additions & 5 deletions src/pages/settings/Security/SecuritySettingsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import useWaitForNavigation from '@hooks/useWaitForNavigation';

import {openSecuritySettingsPage} from '@libs/actions/Delegate';
import Navigation from '@libs/Navigation/Navigation';
import {useIsAgentAccount} from '@libs/SessionUtils';
import {hasDeviceManagementError} from '@libs/UserUtils';

import colors from '@styles/theme/colors';
Expand Down Expand Up @@ -67,6 +68,7 @@ function SecuritySettingsPage() {
const {showLockedAccountModal} = useLockedAccountActions();
const {isActingAsDelegate} = useDelegateNoAccessState();
const {showDelegateNoAccessModal} = useDelegateNoAccessActions();
const isAgentAccount = useIsAgentAccount();

const hasEverRegisteredForMultifactorAuthentication = account?.multifactorAuthenticationPublicKeyIDs !== CONST.MULTIFACTOR_AUTHENTICATION.PUBLIC_KEYS_AUTHENTICATION_NEVER_REGISTERED;

Expand All @@ -75,8 +77,11 @@ function SecuritySettingsPage() {
}, []);

const securityMenuItems = useMemo(() => {
const baseMenuItems: BaseMenuItemType[] = [
{
const baseMenuItems: BaseMenuItemType[] = [];

// Agent accounts can't have two-factor/multifactor authentication, so hide those options for them.
if (!isAgentAccount) {
baseMenuItems.push({
translationKey: 'twoFactorAuth.headerTitle',
icon: icons.Shield,
sentryLabel: CONST.SENTRY_LABEL.SETTINGS_SECURITY.TWO_FACTOR_AUTH,
Expand All @@ -91,10 +96,10 @@ function SecuritySettingsPage() {
}
Navigation.navigate(getTwoFactorAuthRoute());
},
},
];
});
}

if (hasEverRegisteredForMultifactorAuthentication) {
if (!isAgentAccount && hasEverRegisteredForMultifactorAuthentication) {
Comment thread
NicolasBonet marked this conversation as resolved.
baseMenuItems.push({
translationKey: 'multifactorAuthentication.revoke.title',
icon: icons.Fingerprint,
Expand Down Expand Up @@ -182,6 +187,7 @@ function SecuritySettingsPage() {
icons.Monitor,
isAccountLocked,
isActingAsDelegate,
isAgentAccount,
getTwoFactorAuthRoute,
showDelegateNoAccessModal,
showLockedAccountModal,
Expand Down
12 changes: 6 additions & 6 deletions tests/ui/InitialSettingsPageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -165,16 +165,16 @@ describe('InitialSettingsPage - agent account', () => {
await waitForBatchedUpdatesWithAct();
}

it('hides Wallet, Preferences and Security for agent account', async () => {
it('shows Wallet, Preferences and Security for agent account', async () => {
await setupUser('agent_123@expensify.ai');

renderPage();
await waitForBatchedUpdatesWithAct();

await waitFor(() => {
expect(screen.queryByTestId('menu-item-Wallet')).toBeNull();
expect(screen.queryByTestId('menu-item-Preferences')).toBeNull();
expect(screen.queryByTestId('menu-item-Security')).toBeNull();
expect(screen.getByTestId('menu-item-Wallet')).toBeDefined();
expect(screen.getByTestId('menu-item-Preferences')).toBeDefined();
expect(screen.getByTestId('menu-item-Security')).toBeDefined();
});
});

Expand Down Expand Up @@ -202,15 +202,15 @@ describe('InitialSettingsPage - agent account', () => {
});
});

it('hides Subscription for agent account', async () => {
it('shows Subscription for agent account', async () => {
mockUseSubscriptionPlan.mockReturnValue(CONST.POLICY.TYPE.TEAM);
await setupUser('agent_123@expensify.ai');

renderPage();
await waitForBatchedUpdatesWithAct();

await waitFor(() => {
expect(screen.queryByTestId('menu-item-Subscription')).toBeNull();
expect(screen.getByTestId('menu-item-Subscription')).toBeDefined();
});
});

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/ProfilePageTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,16 @@ describe('ProfilePage - agent account', () => {
await waitForBatchedUpdatesWithAct();
}

it('hides contact methods, pronouns, timezone and private section for agent account', async () => {
it('shows contact methods and private section but hides pronouns and timezone for agent account', async () => {
await setupUser('agent_123@expensify.ai');

renderPageWithNavigation(SCREENS.SETTINGS.PROFILE.ROOT);
await waitForBatchedUpdatesWithAct();

expect(screen.queryByTestId('contact-method-menu-item')).toBeNull();
expect(screen.getByTestId('contact-method-menu-item')).toBeDefined();
expect(screen.queryByTestId('pronouns-menu-item')).toBeNull();
expect(screen.queryByTestId('timezone-menu-item')).toBeNull();
expect(screen.queryByText('Private')).toBeNull();
expect(screen.getByText('Private')).toBeDefined();
});

it('shows contact methods, pronouns, timezone and private section for non-agent account', async () => {
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/TestToolMenuBiometricsTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,11 @@ jest.mock('@libs/ApiUtils', () => ({
getCommandURL: () => 'https://test-api.expensify.com/api/Ping?',
}));

let mockIsAgentAccount = false;
jest.mock('@libs/SessionUtils', () => ({
useIsAgentAccount: () => mockIsAgentAccount,
}));

const mockExecuteScenario = jest.fn().mockResolvedValue(undefined);
jest.mock('@components/MultifactorAuthentication/Context', () => ({
useMultifactorAuthentication: () => ({
Expand Down Expand Up @@ -192,6 +197,7 @@ function setBiometricStatus(overrides: Partial<typeof mockBiometricStatus>) {
describe('TestToolMenu biometrics', () => {
afterEach(() => {
jest.clearAllMocks();
mockIsAgentAccount = false;
});

it('renders biometrics title with "Never registered" status', () => {
Expand Down Expand Up @@ -302,4 +308,14 @@ describe('TestToolMenu biometrics', () => {
expect(mockDismissModal).not.toHaveBeenCalled();
expect(mockExecuteScenario).toHaveBeenCalledWith(CONST.MULTIFACTOR_AUTHENTICATION.SCENARIO.BIOMETRICS_TEST);
});

it('hides the biometrics test row for agent accounts', () => {
mockIsAgentAccount = true;
setBiometricStatus({registrationStatus: REGISTRATION_STATUS.NEVER_REGISTERED});

render(<TestToolMenu />);

expect(screen.queryByText(/troubleshootBiometricsStatus/)).toBeNull();
expect(screen.queryByText('multifactorAuthentication.biometricsTest.test')).toBeNull();
});
});
Loading
Loading