Skip to content
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

Admin panel init #8742

Merged
merged 18 commits into from
Nov 28, 2024
Merged

Admin panel init #8742

merged 18 commits into from
Nov 28, 2024

Conversation

ehconitin
Copy link
Contributor

@ehconitin ehconitin commented Nov 25, 2024

WIP
Related issues -
#7090
#8547
Master issue -
#4499

@ehconitin ehconitin marked this pull request as draft November 25, 2024 19:52
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

This PR introduces an admin panel with user impersonation and feature flag management capabilities, along with necessary routing and state management changes.

  • Added useImpersonate hook in /settings/admin/hooks/useImpersonate.ts for user impersonation but missing lastVisitedView clearing (Clear lastVisitedView when impersonating #7090)
  • Added feature flag management table in /settings/admin/components/SettingsAdminFeatureFlags.tsx without loading/error states
  • Added admin panel access control via canImpersonate flag in AppRouter.tsx and SettingsNavigationDrawerItems.tsx
  • Refactored clearSession in useAuth.ts to support both sign-out and impersonation flows
  • Added admin panel route with conditional rendering based on user permissions in SettingsRoutes.tsx

11 file(s) reviewed, 12 comment(s)
Edit PR Review Bot Settings | Greptile

margin-top: ${({ theme }) => theme.spacing(0.5)};
`;

const StyledTableHeaderRow = styled(Table)`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: StyledTableHeaderRow extends Table instead of TableRow, which could cause layout issues

<TableHeader>Value</TableHeader>
</TableRow>
</StyledTableHeaderRow>
{currentWorkspace?.featureFlags?.map((flag) => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: No handling of empty/undefined featureFlags array - should show empty state message

`;

export const SettingsAdminFeatureFlags = () => {
const currentWorkspace = useRecoilValue(currentWorkspaceState);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: No loading or error state handling when fetching currentWorkspace

<Section>
<H2Title title="Feature Flags" description="Manage feature flags." />

<Table>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Table structure creates new Table component for each row instead of reusing one table with multiple rows

Comment on lines 44 to 51
<TextInput
value={userId}
onChange={setUserId}
placeholder="User ID"
fullWidth
disabled={isLoading}
dataTestId="impersonate-input"
/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: Consider adding input validation or pattern matching for valid user ID formats

setCurrentUser(user);
setTokenPair(tokens);
await sleep(0);
window.location.href = AppPath.Index;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: setIsLoading(false) missing before redirect - loading state will remain true if navigation fails

@twentyhq twentyhq deleted a comment from greptile-apps bot Nov 26, 2024
@twentyhq twentyhq deleted a comment from greptile-apps bot Nov 26, 2024
});

return true;
} catch (err) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear for me in what scenario this would happen and why we would not want it displayed to the user (or sent to Sentry if it's a real program error)

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! I think we're very close to merging

@FelixMalfait FelixMalfait marked this pull request as ready for review November 27, 2024 18:08
Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR Summary

(updates since last review)

Based on the latest changes, here's a summary of the key updates to the admin panel implementation:

Added server-side admin panel infrastructure with robust security and data management:

  • Added AdminPanelModule, AdminPanelService, and AdminPanelResolver in server codebase for handling admin operations
  • Implemented proper authorization guards and input validation for admin operations
  • Added GraphQL DTOs and entities for user lookup and feature flag management

Key points to note:

  • Server-side implementation includes comprehensive permission checks through canImpersonate flag
  • Added proper error handling for invalid inputs and unauthorized access attempts
  • Integrated with existing user and workspace entities using TypeORM
  • Structured admin panel operations around three core functions: impersonate, userLookup, and updateWorkspaceFeatureFlags

This complements the previous frontend changes and creates a complete admin panel solution with proper security controls and data management capabilities.

38 file(s) reviewed, 38 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 394 to 402
{isAdminPageEnabled && (
<>
<Route path={SettingsPath.Admin} element={<SettingsAdmin />} />
<Route
path={SettingsPath.FeatureFlags}
element={<SettingsAdminFeatureFlags />}
/>
</>
)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: Consider adding a UserAuthGuard or similar auth wrapper around admin routes to ensure double protection against unauthorized access

Comment on lines +14 to +16
@Field(() => String)
@IsNotEmpty()
featureFlag: FeatureFlagKey;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logic: featureFlag field is typed as String but accepts FeatureFlagKey enum - should use @field(() => FeatureFlagKey) for proper GraphQL enum type

Comment on lines +31 to +32
@Field(() => Number)
totalUsers: number;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: consider using Int instead of Number for totalUsers count

Copy link
Member

@FelixMalfait FelixMalfait left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@FelixMalfait FelixMalfait merged commit e96ad9a into twentyhq:main Nov 28, 2024
17 checks passed
Copy link

Thanks @ehconitin for your contribution!
This marks your 62nd PR on the repo. You're top 1% of all our contributors 🎉
See contributor page - Share on LinkedIn - Share on Twitter

Contributions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants