fix: add site_admin support to tournament permissions and fix session cache issues

This commit is contained in:
2026-03-30 22:09:50 -07:00
parent fa7a422ce3
commit 4d9cbc9259
2 changed files with 35 additions and 16 deletions
+21 -12
View File
@@ -114,8 +114,8 @@ export async function canManageTournament(tournamentId: number): Promise<Permiss
const userRole = user.role as UserRole;
// Club admins can manage all tournaments
if (userRole === 'club_admin') {
// Site admins and club admins can manage all tournaments
if (userRole === 'site_admin' || userRole === 'club_admin') {
return { allowed: true };
}
@@ -188,11 +188,25 @@ export async function getManageableTournaments() {
return [];
}
const userRole = session.user?.role as UserRole;
const userId = session.user?.id;
if (!userId) {
return [];
}
if (userRole === 'club_admin') {
// Club admins can see all tournaments
// Fetch user from database to get current role (bypasses session cache)
const user = await prisma.user.findUnique({
where: { id: userId },
select: { role: true }
});
if (!user) {
return [];
}
const userRole = user.role as UserRole;
if (userRole === 'site_admin' || userRole === 'club_admin') {
// Site admins and club admins can see all tournaments
return prisma.event.findMany({
where: { eventType: 'tournament' },
include: { participants: true },
@@ -264,13 +278,8 @@ export async function canDeleteTournament(tournamentId: number): Promise<Permiss
const userRole = user.role as UserRole;
// Site admins can delete any tournament
if (userRole === 'site_admin') {
return { allowed: true };
}
// Club admins can delete tournaments they can manage
if (userRole === 'club_admin') {
// Site admins and club admins can delete any tournament
if (userRole === 'site_admin' || userRole === 'club_admin') {
return { allowed: true };
}