Skip to content

Connect, collaborate, and grow with a community of TypeScript developers

bug: admins can delete any solution (#1028)

Ayush Kumar Yadav82e0e9e6726b
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts
index 7df24af9..e3f16ba6 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts
+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/_actions.ts
@@ -59,8 +59,8 @@ export async function postSolution({ challengeId, description, slug, title, user
export async function deleteSolution(solutionToDelete: ChallengeSolution) {
const session = await getServerAuthSession();
- if (!isAuthor(session, solutionToDelete?.userId)) {
- throw new Error('Only author can delete their solution.');
+ if (!isAuthor(session, solutionToDelete?.userId) && !isAdminOrModerator(session)) {
+ throw new Error('Not authorized to delete this solution.');
}
await prisma.sharedSolution.delete({
diff --git a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx
index 8fc58264..3f6f8550 100644
--- a/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx
+++ b/apps/web/src/app/[locale]/challenge/[slug]/solutions/_components/solution-detail.tsx
@@ -137,7 +137,7 @@ export function SolutionDetails({ solution }: Props) {
) : null}
{/* Only author can see edit / delete button */}
- {isAuthor(session, solution.userId) ? (
+ {isAuthor(session, solution.userId) || isAdminOrModerator(session) ? (
<>
<Tooltip>
<TooltipTrigger asChild>