fix: show manage controls for system categories when user is superuser
canManage() returned false for system-scope categories unconditionally. Superusers can manage all categories (backend already permits it), so check is_admin from getMe() and short-circuit to true. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import {
|
||||
renameCategory,
|
||||
deleteCategory,
|
||||
getMyGroups,
|
||||
getMe,
|
||||
type CategoryOut,
|
||||
ApiError,
|
||||
} from "@/api/client";
|
||||
@@ -29,6 +30,9 @@ export default function ManageCategoriesDialog({ onClose }: Props) {
|
||||
queryFn: getMyGroups,
|
||||
});
|
||||
|
||||
const { data: me } = useQuery({ queryKey: ["me"], queryFn: getMe });
|
||||
const isSuperuser = me?.is_admin ?? false;
|
||||
|
||||
// Set of group IDs for which the current user is a group admin
|
||||
const adminGroupIds = new Set(myGroups.filter((g) => g.is_group_admin).map((g) => g.id));
|
||||
|
||||
@@ -60,9 +64,10 @@ export default function ManageCategoriesDialog({ onClose }: Props) {
|
||||
});
|
||||
|
||||
function canManage(cat: CategoryOut): boolean {
|
||||
if (isSuperuser) return true;
|
||||
if (cat.scope === "personal") return true;
|
||||
if (cat.scope === "group") return cat.group_id != null && adminGroupIds.has(cat.group_id);
|
||||
return false; // system — managed only by superuser via other means
|
||||
return false; // system — non-admin cannot manage
|
||||
}
|
||||
|
||||
const filtered = search
|
||||
|
||||
Reference in New Issue
Block a user