mirror of
https://github.com/Hackdex-App/hackdex-website.git
synced 2026-03-21 17:54:09 -05:00
Fix unapproved hack viewing permissions
This commit is contained in:
parent
456832aad3
commit
f0875bc929
|
|
@ -134,20 +134,21 @@ export default async function HackDetail({ params }: HackDetailProps) {
|
|||
canEdit: canUploadPatch,
|
||||
} = await checkPatchEditPermission(hack, user?.id as string, supabase);
|
||||
|
||||
// isAdmin always needs to be checked for archive hacks
|
||||
let isAdmin = false;
|
||||
if (!hack.approved || isArchive) {
|
||||
const { data: admin } = await supabase.rpc("is_admin");
|
||||
if (admin) {
|
||||
isAdmin = true;
|
||||
} else if (!isArchive) {
|
||||
return notFound();
|
||||
} else if (!hack.approved) {
|
||||
if (isArchive && !canEditAsArchiver) {
|
||||
return notFound();
|
||||
} else if (!canEdit) {
|
||||
return notFound();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (isArchive && !isAdmin && !canEditAsArchiver) {
|
||||
return notFound();
|
||||
}
|
||||
|
||||
// Extract patch info from cached metadata
|
||||
const patchFilename = patch?.filename || null;
|
||||
const patchVersion = isArchive ? "Archive" : (patch?.version || "");
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { createClient } from "@/utils/supabase/server";
|
|||
import { notFound, redirect } from "next/navigation";
|
||||
import HackStatsClient from "@/components/Hack/Stats/HackStatsClient";
|
||||
import { getDownloadsSeriesAll, getHackInsights } from "@/app/dashboard/actions";
|
||||
import { isArchiveHack, canEditAsArchiver } from "@/utils/hack";
|
||||
import { checkEditPermission } from "@/utils/hack";
|
||||
|
||||
export default async function HackStatsPage({ params: { slug } }: { params: { slug: string } }) {
|
||||
const supa = await createClient();
|
||||
|
|
@ -17,11 +17,9 @@ export default async function HackStatsPage({ params: { slug } }: { params: { sl
|
|||
.maybeSingle();
|
||||
if (!hack) notFound();
|
||||
|
||||
let isOwner = hack.created_by === user.id;
|
||||
if (!isOwner) {
|
||||
const isArchive = isArchiveHack(hack);
|
||||
const isEditableByArchiver = await canEditAsArchiver(hack, user.id, supa);
|
||||
if (!isOwner && !isArchive && !isEditableByArchiver) notFound();
|
||||
const permission = await checkEditPermission(hack, user.id, supa);
|
||||
if (!permission.canEdit) {
|
||||
redirect(`/hack/${slug}`);
|
||||
}
|
||||
|
||||
const allSeries = await getDownloadsSeriesAll({ days: 30 });
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user