Skip to content

Conversation

@juanlou1217
Copy link
Contributor

  • 新增 useAdminCheck 、useAdminList hook,用于检查当前用户是否为管理员与管理员列表
  • 在 MenuPicker 组件中集成管理员权限检查

@genedna
Copy link
Member

genedna commented Jan 24, 2026

@codex review

@chatgpt-codex-connector
Copy link

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds admin permission querying hooks and uses them to gate the Sidebar “Menu Order” settings UI so it only renders for admins.

Changes:

  • Added useAdminCheck hook for checking whether the current user is an admin.
  • Added useAdminList hook for fetching the admin list.
  • Integrated admin check into MenuPicker to hide the menu-order editor for non-admin users.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.

File Description
moon/apps/web/hooks/admin/useAdminList.ts New React Query hook to fetch admin list data.
moon/apps/web/hooks/admin/useAdminCheck.ts New React Query hook to fetch “am I admin” status.
moon/apps/web/components/Sidebar/SidebarMenu/MenuPicker.tsx Uses admin check to conditionally render the Menu Order UI.

Comment on lines +11 to +12
staleTime: 0,
retry: false
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

Same as useAdminCheck: retry: false overrides the app-wide retry policy (which already prevents retries for 4xx) and can cause avoidable failures on transient errors. Consider relying on the default retry strategy unless you have a concrete reason to disable retries for this endpoint.

Suggested change
staleTime: 0,
retry: false
staleTime: 0

Copilot uses AI. Check for mistakes.
Comment on lines 14 to 17
export const MenuPicker = () => {
const { data: adminCheck } = useAdminCheck()
const { data, refetch, isFetching } = useGetSidebarList()
const queryClient = useQueryClient()
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

useGetSidebarList() is still executed for non-admin users because hooks run before the early return null. This defeats the purpose of the admin gate and can trigger unnecessary/unauthorized requests. Consider adding an enabled option to useGetSidebarList (or wrapping it with another hook) and pass enabled: !!adminCheck?.data?.is_admin so the sidebar list query only runs once admin permission is confirmed.

Copilot uses AI. Check for mistakes.

import { legacyApiClient } from '@/utils/queryClient'

export function useAdminCheck(params?: RequestParams) {
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

The name useAdminCheck reads like it returns a boolean, but it actually returns a React Query result object. To avoid confusion for callers, consider renaming to something like useGetAdminMe/useAdminMeQuery, or alternatively wrap it in a useIsAdmin() hook that returns a boolean.

Suggested change
export function useAdminCheck(params?: RequestParams) {
export function useAdminMeQuery(params?: RequestParams) {

Copilot uses AI. Check for mistakes.
Comment on lines +10 to +12
queryFn: () => legacyApiClient.v1.getApiAdminMe().request(params),
staleTime: 0,
retry: false
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

Setting retry: false here bypasses the app-wide React Query retry policy defined in utils/queryClient.ts (which already avoids retrying 4xx errors). This makes the admin check more fragile on transient network/5xx failures. Consider removing retry: false (and the redundant staleTime: 0) unless there’s a specific reason to override defaults.

Suggested change
queryFn: () => legacyApiClient.v1.getApiAdminMe().request(params),
staleTime: 0,
retry: false
queryFn: () => legacyApiClient.v1.getApiAdminMe().request(params)

Copilot uses AI. Check for mistakes.

import { legacyApiClient } from '@/utils/queryClient'

export function useAdminList(params?: RequestParams) {
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

For consistency with the rest of the codebase’s query hooks (e.g. useGetSidebarList, useGetMergeQueueList), consider renaming useAdminList to useGetAdminList (or similar). The current name can be mistaken for a selector that returns an array rather than a React Query result object.

Suggested change
export function useAdminList(params?: RequestParams) {
export function useGetAdminList(params?: RequestParams) {

Copilot uses AI. Check for mistakes.
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

Comment on lines +8 to +13
return useQuery<GetApiAdminMeData, Error>({
queryKey: [...legacyApiClient.v1.getApiAdminMe().requestKey(), params],
queryFn: () => legacyApiClient.v1.getApiAdminMe().request(params),
staleTime: 0,
retry: false
})
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

retry: false disables the app-wide React Query retry policy (see moon/apps/web/utils/queryClient.ts:107-138), which currently avoids retries for 4xx but retries transient failures up to 3 times. Consider removing this override (or using the shared retry function) so admin checks are resilient to temporary network/API hiccups.

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +13
return useQuery<GetApiAdminListData, Error>({
queryKey: [...legacyApiClient.v1.getApiAdminList().requestKey(), params],
queryFn: () => legacyApiClient.v1.getApiAdminList().request(params),
staleTime: 0,
retry: false
})
Copy link

Copilot AI Jan 24, 2026

Choose a reason for hiding this comment

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

retry: false here overrides the global React Query retry behavior configured in moon/apps/web/utils/queryClient.ts:107-138 (no retry for 4xx, retry transient errors up to 3x). Unless there’s a specific reason to never retry this request, consider relying on the shared retry policy for consistency and resilience.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants