From 0ebc25a1c85f953a87067ed9b773b59ac8be8bf0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=98=99=E2=97=A6=20The=20Tablet=20=E2=9D=80=20GamerGirla?= =?UTF-8?q?ndCo=20=E2=97=A6=E2=9D=A7?= Date: Mon, 11 Dec 2023 21:20:06 -0500 Subject: [PATCH] refactor(server/utils): allow an `IDraft` to be passed to permission checker --- lib/server/middlewareButNotReally/storyPrivileges.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/server/middlewareButNotReally/storyPrivileges.ts b/lib/server/middlewareButNotReally/storyPrivileges.ts index 7ba7d50..75dcfef 100644 --- a/lib/server/middlewareButNotReally/storyPrivileges.ts +++ b/lib/server/middlewareButNotReally/storyPrivileges.ts @@ -1,6 +1,7 @@ import type { H3Event, EventHandlerRequest } from "h3"; import { IStory } from "~/models/stories"; import isLoggedIn from "~/lib/server/middlewareButNotReally/isLoggedIn"; +import { IDraft } from "~/models/stories/draft"; export function canDelete(event: H3Event, story: IStory) { isLoggedIn(event); return ( @@ -8,7 +9,10 @@ export function canDelete(event: H3Event, story: IStory) { story.author._id === event.context.currentUser?._id ); } -export function canModify(event: H3Event, story: IStory) { +export function canModify( + event: H3Event, + story: IStory | IDraft, +) { isLoggedIn(event); return ( event.context.currentUser?._id === story.author._id ||