From 6b1689e1dfb9b1fcf03806cb35dc32430c719a26 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 5 Sep 2020 21:16:25 +0000 Subject: [PATCH] [Repeat][Favourite] Only display action buttons if logged in (instead of forcing login) --- plugins/Favourite/Favourite.php | 10 ++++++++-- plugins/Repeat/Repeat.php | 11 ++++++++--- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/plugins/Favourite/Favourite.php b/plugins/Favourite/Favourite.php index 96357ad89f..b2e03e9b33 100644 --- a/plugins/Favourite/Favourite.php +++ b/plugins/Favourite/Favourite.php @@ -34,7 +34,13 @@ class Favourite extends Module { public function onAddNoteActions(Request $request, Note $note, array &$actions) { - $opts = ['note_id' => $note->getId(), 'gsactor_id' => Common::ensureLoggedIn()->getActor()->getId()]; + $user = Common::user(); + // Only show buttons if a user is logged in + if ($user == null) { + return Event::next; + } + + $opts = ['note_id' => $note->getId(), 'gsactor_id' => $user->getId()]; $is_set = DB::find('favourite', $opts) != null; $form = Form::create([ ['is_set', HiddenType::class, ['data' => $is_set ? '1' : '0']], @@ -62,7 +68,7 @@ class Favourite extends Module } } - $actions['post_fav'] = $form->createView(); + $actions[] = $form->createView(); return Event::next; } } diff --git a/plugins/Repeat/Repeat.php b/plugins/Repeat/Repeat.php index d403f33a56..a3f055eacc 100644 --- a/plugins/Repeat/Repeat.php +++ b/plugins/Repeat/Repeat.php @@ -24,6 +24,7 @@ use App\Core\Event; use App\Core\Form; use App\Core\Module; use App\Entity\Note; +use App\Util\Common; use Symfony\Component\Form\Extension\Core\Type\HiddenType; use Symfony\Component\Form\Extension\Core\Type\SubmitType; use Symfony\Component\HttpFoundation\Request; @@ -32,6 +33,12 @@ class Repeat extends Module { public function onAddNoteActions(Request $request, Note $note, array &$actions) { + $user = Common::user(); + // Only show buttons if a user is logged in + if ($user == null) { + return Event::next; + } + $to_repeat = DB::find('note', ['id' => $note->getId()]); $is_set = false; $form = Form::create([ @@ -47,9 +54,7 @@ class Repeat extends Module if ($data['note_id'] == $to_repeat && $form->isValid()) { // Loose comparison if (!$data['is_set']) { - var_dump($note); - die(); - DB::persist(Note::create(['repeat_of' => $note->getId(), 'content' => $note->getContent(), 'is_local' => true])); + DB::persist(Note::create(['gsactor_id' => $user->getId(), 'repeat_of' => $note->getId(), 'content' => $note->getContent(), 'is_local' => true])); DB::flush(); } else { DB::remove($to_repeat);