diff --git a/app/api/missions/[missionId]/files/folder/route.ts b/app/api/missions/[missionId]/files/folder/route.ts index 35eceee..867fa66 100644 --- a/app/api/missions/[missionId]/files/folder/route.ts +++ b/app/api/missions/[missionId]/files/folder/route.ts @@ -19,11 +19,13 @@ const missionsS3Client = new S3Client({ const MISSIONS_BUCKET = 'missions'; // Helper function to check if user can manage files (creator or gardien) -async function checkCanManage(userId: string, missionId: string): Promise { +// Also checks if mission is closed (closed missions cannot be modified) +async function checkCanManage(userId: string, missionId: string): Promise<{ canManage: boolean; isClosed: boolean }> { const mission = await prisma.mission.findFirst({ where: { id: missionId }, select: { creatorId: true, + isClosed: true, missionUsers: { where: { userId }, select: { role: true } @@ -31,14 +33,20 @@ async function checkCanManage(userId: string, missionId: string): Promise { +// Also checks if mission is closed (closed missions cannot be modified) +async function checkCanManage(userId: string, missionId: string): Promise<{ canManage: boolean; isClosed: boolean }> { const mission = await prisma.mission.findFirst({ where: { id: missionId }, select: { creatorId: true, + isClosed: true, missionUsers: { where: { userId }, select: { role: true } @@ -46,14 +48,20 @@ async function checkCanManage(userId: string, missionId: string): Promise { +// Also checks if mission is closed (closed missions cannot be modified) +async function checkCanManage(userId: string, missionId: string): Promise<{ canManage: boolean; isClosed: boolean }> { const mission = await prisma.mission.findFirst({ where: { id: missionId }, select: { creatorId: true, + isClosed: true, missionUsers: { where: { userId }, select: { role: true } @@ -17,14 +19,20 @@ async function checkCanManage(userId: string, missionId: string): Promise = ({ const isCreator = mission.creatorId === currentUserId; const userRole = mission.missionUsers?.find(mu => mu.userId === currentUserId)?.role; const isGardien = userRole === 'gardien-temps' || userRole === 'gardien-parole' || userRole === 'gardien-memoire'; - const canManage = isCreator || isGardien; + const isClosed = mission.isClosed || false; + const canManage = (isCreator || isGardien) && !isClosed; // Cannot manage if mission is closed const fetchFiles = async () => { try {