From fa9df9962ebb3865936947829ea6317abd356e39 Mon Sep 17 00:00:00 2001 From: Eliseu Amaro Date: Thu, 13 Jan 2022 17:47:47 +0000 Subject: [PATCH] [COMPONENTS][Conversation] Route 'conversation_mute' now has the corresponding conversation view embedded, user is also redirected properly [PLUGINS][Favourite] Fixed typo --- .../Conversation/Controller/Conversation.php | 22 +++++++++++++++++-- components/Conversation/Conversation.php | 15 ++++++++++++- .../templates/conversation/mute.html.twig | 20 +++++++++++++++-- plugins/Favourite/Controller/Favourite.php | 2 +- .../default_theme/css/widgets/buttons.css | 7 ++++++ .../default_theme/css/widgets/sections.css | 4 +++- 6 files changed, 63 insertions(+), 7 deletions(-) diff --git a/components/Conversation/Controller/Conversation.php b/components/Conversation/Controller/Conversation.php index dc050a8ff2..0764530f94 100644 --- a/components/Conversation/Controller/Conversation.php +++ b/components/Conversation/Controller/Conversation.php @@ -31,6 +31,8 @@ use App\Core\Cache; use App\Core\DB\DB; use App\Core\Form; use function App\Core\I18n\_m; +use App\Core\Log; +use App\Core\Router\Router; use App\Entity\Note; use App\Util\Common; use App\Util\Exception\ClientException; @@ -101,7 +103,7 @@ class Conversation extends FeedController $user = Common::ensureLoggedIn(); $is_muted = ConversationMute::isMuted($conversation_id, $user); $form = Form::create([ - ['mute_conversation', SubmitType::class, ['label' => $is_muted ? _m('Unmute conversation') : _m('Mute conversation')]], + ['mute_conversation', SubmitType::class, ['label' => $is_muted ? _m('Unmute') : _m('Mute'), 'attr' => ['class' => '']]], ]); $form->handleRequest($request); @@ -113,11 +115,27 @@ class Conversation extends FeedController } DB::flush(); Cache::delete(ConversationMute::cacheKeys($conversation_id, $user->getId())['mute']); - throw new RedirectException(); + + // Redirect user to where they came from + // Prevent open redirect + if (!\is_null($from = $this->string('from'))) { + if (Router::isAbsolute($from)) { + Log::warning("Actor {$user->getId()} attempted to mute conversation {$conversation_id} and then get redirected to another host, or the URL was invalid ({$from})"); + throw new ClientException(_m('Can not redirect to outside the website from here'), 400); // 400 Bad request (deceptive) + } else { + // TODO anchor on element id + throw new RedirectException(url: $from); + } + } else { + // If we don't have a URL to return to, go to the instance root + throw new RedirectException('root'); + } } return [ '_template' => 'conversation/mute.html.twig', + 'notes' => $this->query(query: "note-conversation:{$conversation_id}")['notes'] ?? [], + 'is_muted' => $is_muted, 'form' => $form->createView(), ]; } diff --git a/components/Conversation/Conversation.php b/components/Conversation/Conversation.php index e41a47d4cd..c56c3f6e76 100644 --- a/components/Conversation/Conversation.php +++ b/components/Conversation/Conversation.php @@ -226,10 +226,23 @@ class Conversation extends Component return Event::next; } + $from = $request->query->has('from') + ? $request->query->get('from') + : $request->getPathInfo(); + + $mute_extra_action_url = Router::url( + 'conversation_mute', + [ + 'conversation_id' => $note->getConversationId(), + 'from' => $from . '#note-anchor-' . $note->getId(), + ], + Router::ABSOLUTE_PATH, + ); + $actions[] = [ 'title' => ConversationMute::isMuted($note, $user) ? _m('Unmute conversation') : _m('Mute conversation'), 'classes' => '', - 'url' => Router::url('conversation_mute', ['conversation_id' => $note->getConversationId()]), + 'url' => $mute_extra_action_url, ]; return Event::next; diff --git a/components/Conversation/templates/conversation/mute.html.twig b/components/Conversation/templates/conversation/mute.html.twig index d8eda52b9f..c39700735c 100644 --- a/components/Conversation/templates/conversation/mute.html.twig +++ b/components/Conversation/templates/conversation/mute.html.twig @@ -1,5 +1,21 @@ -{% extends 'base.html.twig' %} +{% extends 'collection/notes.html.twig' %} {% block body %} - {{ form(form) }} +
+ {% if is_muted %} + + + {{ form(form) }} + + {% else %} + + + {{ form(form) }} + + {% endif %} + +
+ + {{ parent() }} +
{% endblock body %} diff --git a/plugins/Favourite/Controller/Favourite.php b/plugins/Favourite/Controller/Favourite.php index c5e534145f..75f16ad100 100644 --- a/plugins/Favourite/Controller/Favourite.php +++ b/plugins/Favourite/Controller/Favourite.php @@ -82,7 +82,7 @@ class Favourite extends FeedController // Prevent open redirect if (!\is_null($from = $this->string('from'))) { if (Router::isAbsolute($from)) { - Log::warning("Actor {$actor_id} attempted to reply to a note and then get redirected to another host, or the URL was invalid ({$from})"); + Log::warning("Actor {$actor_id} attempted to favourite a note and then get redirected to another host, or the URL was invalid ({$from})"); throw new ClientException(_m('Can not redirect to outside the website from here'), 400); // 400 Bad request (deceptive) } else { // TODO anchor on element id diff --git a/public/assets/default_theme/css/widgets/buttons.css b/public/assets/default_theme/css/widgets/buttons.css index 4b0db1df48..4ee722c1a9 100644 --- a/public/assets/default_theme/css/widgets/buttons.css +++ b/public/assets/default_theme/css/widgets/buttons.css @@ -30,6 +30,7 @@ input[type=radio] { input[type=radio]:checked { background: var(--background-hard); + box-shadow: inset 0 0 0 2px var(--accent) !important; } input[type=file] { @@ -99,6 +100,12 @@ button { margin-top: var(--s); } +.alert button { + cursor: pointer !important; + margin-top: unset !important; + border-color: tomato !important; +} + button, label { font-family: 'Poppins', sans-serif; diff --git a/public/assets/default_theme/css/widgets/sections.css b/public/assets/default_theme/css/widgets/sections.css index 2a9dd6ac74..83ecc3208c 100644 --- a/public/assets/default_theme/css/widgets/sections.css +++ b/public/assets/default_theme/css/widgets/sections.css @@ -276,7 +276,9 @@ textarea.form-row-widget { .alert-danger, .form-error, .form-row-widget-error { - display: inline-block; + display: inline-flex; + align-items: center; + justify-content: space-between; font-style: italic; border: solid 2px #ff6347; background-color: #FF634733;