fix: authorize super admins by dynamic highest rank

This commit is contained in:
Simo committed 2026-07-11 22:35:40 +02:00
1 parent bb847176ad
commit f08e56cf53
10 files changed
+173 -65

No files matched your search

+15
View File
@@ -0,0 +1,15 @@
import type { AuthorizationActor } from "@/lib/admin/authorization-policy";
export interface RankAuthorityDb {
user: { findUnique(args: { where: { id: number }; select: { id: true; username: true; rank: true } }): Promise<{ id: number; username: string; rank: number } | null> };
highestRank(): Promise<number | null>;
}
export async function resolveAuthorizationState(userId: number, db: RankAuthorityDb): Promise<{ actor: AuthorizationActor; highestRank: number | null } | null> {
const [user, highestRank] = await Promise.all([
db.user.findUnique({ where: { id: userId }, select: { id: true, username: true, rank: true } }),
db.highestRank(),
]);
if (!user) return null;
return { actor: user, highestRank };
}