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:
curo1305
2026-04-18 22:23:30 +02:00
parent fec3953009
commit ebf97b6f4a
@@ -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