aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes/note_fragment.php
diff options
context:
space:
mode:
authorwinter2025-01-27 19:45:39 +0000
committerwinter2025-01-27 19:45:39 +0000
commit5a6300f473b8be0e90a16e2b5992299b0ea1ddff (patch)
tree844d3422a1c9575a4cecd56f32c1c7eba0358efd /routes/note_fragment.php
parent9d59fd65b70b5b7588e4786f52f9cff1c3807426 (diff)
context menus and note deletion
Diffstat (limited to 'routes/note_fragment.php')
-rw-r--r--routes/note_fragment.php16
1 files changed, 16 insertions, 0 deletions
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 @@
<?php
use Digitigrade\HttpResponseStatus\BadRequest;
+use Digitigrade\HttpResponseStatus\Forbidden;
use Digitigrade\Model\Actor;
use Digitigrade\Model\Interaction;
use Digitigrade\Model\InteractionKind;
@@ -9,6 +10,21 @@ use Digitigrade\Model\NotePrivacyScope;
use Digitigrade\Model\UserAccount;
use Digitigrade\Router;
+Router::getInstance()->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'];