From 5a6300f473b8be0e90a16e2b5992299b0ea1ddff Mon Sep 17 00:00:00 2001 From: winter Date: Mon, 27 Jan 2025 19:45:39 +0000 Subject: context menus and note deletion --- routes/note_fragment.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'routes/note_fragment.php') diff --git a/routes/note_fragment.php b/routes/note_fragment.php index 74e987e..5c6326d 100644 --- a/routes/note_fragment.php +++ b/routes/note_fragment.php @@ -1,6 +1,7 @@ mount('/fragment/note/:id', function (array $args) { + if ($_SERVER['REQUEST_METHOD'] != 'DELETE') { + throw new RuntimeException('method not implemented'); + } + // assuming we're deleting the note + $user = UserAccount::requireByCurrentSession(); + $note = Note::find($args['id']); + if ($note->author != $user->actor && !$user->isAdmin) { + throw new Forbidden('you may not delete that note!'); + } + + $note->markDeleted(); + // no need to return any template because it's just gone +}); + Router::getInstance()->mount('/fragment/note/:id/:action', function (array $args) { $user = UserAccount::requireByCurrentSession(); $action = $args['action']; -- cgit v1.3