diff options
| author | winter | 2025-01-16 18:33:18 +0000 |
|---|---|---|
| committer | winter | 2025-01-16 18:33:18 +0000 |
| commit | 8de5608976dc8a73a400267601acb4c8e127de5a (patch) | |
| tree | a907dd4c4e55e331979cd9ce14852592af2654a0 /routes/note.php | |
| parent | e3a0248c3b1762abf5138fbd1b8228601006d44d (diff) | |
note privacy and summary stuff
Diffstat (limited to 'routes/note.php')
| -rw-r--r-- | routes/note.php | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/routes/note.php b/routes/note.php index 8a6c9da..f1d6650 100644 --- a/routes/note.php +++ b/routes/note.php @@ -1,8 +1,12 @@ <?php +use Digitigrade\HttpResponseStatus\Forbidden; use Digitigrade\HttpResponseStatus\NotFound; use Digitigrade\HttpResponseStatus\TemporaryRedirect; +use Digitigrade\Model\Instance; use Digitigrade\Model\Note; +use Digitigrade\Model\NotePrivacyScope; +use Digitigrade\Model\UserAccount; use Digitigrade\Router; Router::getInstance()->mount('/note/:id', function (array $args) { @@ -16,6 +20,14 @@ Router::getInstance()->mount('/note/:id', function (array $args) { if (isset($_SERVER['HTTP_ACCEPT']) && str_contains($_SERVER['HTTP_ACCEPT'], 'text/html')) { throw new TemporaryRedirect('/@/' . $note->author->handle . "/note/$note->id"); } + // if it's not public we need to check whether the requesting instance is allowed to see it + if ($note->privacy->scope != NotePrivacyScope::PUBLIC ) { + $instance = Instance::requireByRequestHeaders(); + $allowed = $note->getRelevantServers(); + if (!in_array($instance, $allowed)) { + throw new Forbidden(); + } + } json_response($note); }); @@ -28,5 +40,12 @@ Router::getInstance()->mount('/@/:handle/note/:id', function (array $args) { if ($args['handle'] != $note->author->getFullHandle()) { throw new TemporaryRedirect('/@/' . $note->author->getFullHandle() . "/note/$note->id"); } + // check the current user is allowed to see it + if ($note->privacy->scope != NotePrivacyScope::PUBLIC ) { + $user = UserAccount::requireByCurrentSession(); + if (!in_array($user->actor, $note->getRelevantActors())) { + throw new Forbidden(); + } + } render_template('thread_page', ['note' => $note]); }); |
