aboutsummaryrefslogtreecommitdiffhomepage
path: root/routes
diff options
context:
space:
mode:
Diffstat (limited to 'routes')
-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'];