Skip to content

Commit

Permalink
fix: allow admin to delete bleet post
Browse files Browse the repository at this point in the history
  • Loading branch information
casperiv0 committed Nov 18, 2023
1 parent e7f63fa commit 7180dac
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions apps/api/src/controllers/bleeter/bleeter-controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
type PlatformMulterFile,
MultipartFile,
} from "@tsed/common";
import { BadRequest, NotFound } from "@tsed/exceptions";
import { BadRequest, Forbidden, NotFound } from "@tsed/exceptions";
import { ContentType, Delete, Description, Put } from "@tsed/schema";
import { prisma } from "lib/data/prisma";
import { IsAuth } from "middlewares/auth/is-auth";
Expand All @@ -27,6 +27,7 @@ import { type BleeterPost, type BleeterProfile } from "@snailycad/types";
import { type Descendant, slateDataToString } from "@snailycad/utils/editor";
import { getAPIUrl } from "@snailycad/utils/api-url";
import { sendDiscordWebhook } from "~/lib/discord/webhooks";
import { defaultPermissions, hasPermission } from "@snailycad/permissions";

@UseBeforeEach(IsAuth)
@Controller("/bleeter")
Expand Down Expand Up @@ -204,10 +205,19 @@ export class BleeterController {
},
});

if (!post || post.userId !== user.id) {
const hasAdminPermissions = hasPermission({
userToCheck: user,
permissionsToCheck: defaultPermissions.allDefaultAdminPermissions,
});

if (!post) {
throw new NotFound("notFound");
}

if (post.userId !== user.id || !hasAdminPermissions) {
throw new Forbidden("notAllowedToDelete");
}

await prisma.bleeterPost.delete({
where: {
id: post.id,
Expand Down

0 comments on commit 7180dac

Please sign in to comment.