From bedd3769b93bc21f81d2542882f5ea2a41c1ad89 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Wed, 13 May 2026 23:39:20 -0300 Subject: [PATCH] feat: Adds setting to disable post reactions --- app/controllers/authors_controller.rb | 5 +++-- app/controllers/posts_controller.rb | 17 +++++++++----- app/controllers/reactions_controller.rb | 9 ++++++++ app/mailers/authors_mailer.rb | 2 +- app/mailers/subscription_mailer.rb | 17 +++++++++----- app/views/authors/settings.html.erb | 1 + .../components/authors/settings/General.jsx | 13 ++++++++++- client/app/components/posts/Show.jsx | 22 +++++++++++-------- .../subscription_mailer/NewPost.jsx | 20 ++++++++++------- client/app/types/author.js | 1 + ...20000_add_reactions_disabled_to_authors.rb | 5 +++++ db/schema.rb | 3 ++- 12 files changed, 81 insertions(+), 34 deletions(-) create mode 100644 db/migrate/20260513120000_add_reactions_disabled_to_authors.rb diff --git a/app/controllers/authors_controller.rb b/app/controllers/authors_controller.rb index c6b7e8a1..ba06b3e9 100644 --- a/app/controllers/authors_controller.rb +++ b/app/controllers/authors_controller.rb @@ -290,7 +290,7 @@ def extension end reactions_string = post&.reactions_string - if reactions_string + if reactions_string && !@author.reactions_disabled actions.unshift( label: reactions_string, url: "#{post.author_relative_url}?reactions", @@ -333,6 +333,7 @@ def update @author.hide_from_homepage = a_params[:hide_from_homepage] @author.guestbook_disabled = a_params[:guestbook_disabled] @author.newsletter_disabled = a_params[:newsletter_disabled] + @author.reactions_disabled = a_params[:reactions_disabled] @author.cover_style = a_params[:cover_style] @author.blog_layout_style = a_params[:blog_layout_style] @author.custom_theme_enabled = a_params[:custom_theme_enabled] @@ -417,7 +418,7 @@ def delete_all_data def a_params params.require(:author).permit(:username, :display_name, :bio, :link, :email, :secret, :twitter, :meta_image_url, :guestbook_disabled, :header_image_url, :hide_from_homepage, - :newsletter_disabled, :cover_style, :blog_layout_style, :custom_theme_enabled) + :newsletter_disabled, :reactions_disabled, :cover_style, :blog_layout_style, :custom_theme_enabled) end end diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 08e522bd..17a0554d 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -59,12 +59,17 @@ def show @styles = @post.author.css if @post.author.custom_theme_enabled @is_accessory_page = false - @reaction_links = Reaction::REACTIONS.map do |reaction| - { - reaction: reaction, - url: "#{@post.author.get_host}/authors/#{@post.author.id}/posts/#{@post.id}/reactions/new?reaction=#{reaction}" - } - end + @reaction_links = + if @post.author.reactions_disabled + [] + else + Reaction::REACTIONS.map do |reaction| + { + reaction: reaction, + url: "#{@post.author.get_host}/authors/#{@post.author.id}/posts/#{@post.id}/reactions/new?reaction=#{reaction}" + } + end + end end def index diff --git a/app/controllers/reactions_controller.rb b/app/controllers/reactions_controller.rb index 04fcd284..b92c20ce 100644 --- a/app/controllers/reactions_controller.rb +++ b/app/controllers/reactions_controller.rb @@ -2,6 +2,7 @@ class ReactionsController < ApplicationController include CaptchaHelper before_action :find_post + before_action :ensure_reactions_enabled def create_via_email creation_token = params[:creation_token] @@ -38,4 +39,12 @@ def create render json: { error: captcha_verification['error'] } end end + + private + + def ensure_reactions_enabled + return unless @post&.author&.reactions_disabled + + not_found + end end diff --git a/app/mailers/authors_mailer.rb b/app/mailers/authors_mailer.rb index 0ceecedf..34d25000 100644 --- a/app/mailers/authors_mailer.rb +++ b/app/mailers/authors_mailer.rb @@ -38,7 +38,7 @@ def new_reaction(reaction_id) @reaction = Reaction.find(reaction_id) @post = @reaction.post @author = @post.author - return if @post.author.email_verified == false + return if @author.email_verified == false || @author.reactions_disabled mail( to: @author.email, diff --git a/app/mailers/subscription_mailer.rb b/app/mailers/subscription_mailer.rb index 5db19795..44c24299 100644 --- a/app/mailers/subscription_mailer.rb +++ b/app/mailers/subscription_mailer.rb @@ -12,12 +12,17 @@ def new_post(post, subscriber) subscription = subscriber.subscription_for_author(post.author) reaction_creation_token = subscriber.reaction_creation_token(post) - @reaction_links = Reaction::REACTIONS.map do |reaction| - { - reaction: reaction, - url: "#{post.author.get_host}/authors/#{post.author.id}/posts/#{post.id}/reactions/create-via-email?reaction=#{reaction}&creation_token=#{reaction_creation_token}&subscriber_id=#{subscriber.id}" - } - end + @reaction_links = + if post.author.reactions_disabled + [] + else + Reaction::REACTIONS.map do |reaction| + { + reaction: reaction, + url: "#{post.author.get_host}/authors/#{post.author.id}/posts/#{post.id}/reactions/create-via-email?reaction=#{reaction}&creation_token=#{reaction_creation_token}&subscriber_id=#{subscriber.id}" + } + end + end @unsubscribe_url = "#{@post.author.get_host}/subscriptions/#{subscription.id}/unsubscribe?t=#{subscription.token}" if subscription.frequency == 'daily' diff --git a/app/views/authors/settings.html.erb b/app/views/authors/settings.html.erb index e20417c5..03db0c7d 100644 --- a/app/views/authors/settings.html.erb +++ b/app/views/authors/settings.html.erb @@ -15,6 +15,7 @@ :header_image_url, :guestbook_disabled, :newsletter_disabled, + :reactions_disabled, :hide_from_homepage, :secret, :cover_style, diff --git a/client/app/components/authors/settings/General.jsx b/client/app/components/authors/settings/General.jsx index 8597d320..f51be38e 100644 --- a/client/app/components/authors/settings/General.jsx +++ b/client/app/components/authors/settings/General.jsx @@ -17,6 +17,7 @@ const fieldTypes = { HEADER_IMAGE_URL: "header_image_url", GUESTBOOK_DISABLED: "guestbook_disabled", NEWSLETTER_DISABLED: "newsletter_disabled", + REACTIONS_DISABLED: "reactions_disabled", HIDE_FROM_HOMEPAGE: "hide_from_homepage", }; @@ -35,6 +36,7 @@ const General = ({ header_image_url, guestbook_disabled, newsletter_disabled, + reactions_disabled, hide_from_homepage, } = author; @@ -49,6 +51,7 @@ const General = ({ header_image_url: header_image_url || "", guestbook_disabled, newsletter_disabled, + reactions_disabled, hide_from_homepage, }); @@ -122,7 +125,9 @@ const General = ({ editAuthor(fieldTypes.USERNAME, e.target.value)} /> @@ -248,6 +253,12 @@ const General = ({ checked={editedAuthor.newsletter_disabled} label="Disable email subscription and newsletter" /> + editAuthor(fieldTypes.REACTIONS_DISABLED, checked)} + checked={editedAuthor.reactions_disabled} + label="Disable post reactions" + /> editAuthor(fieldTypes.HIDE_FROM_HOMEPAGE, checked)} diff --git a/client/app/components/posts/Show.jsx b/client/app/components/posts/Show.jsx index e8f7ba39..7926209f 100644 --- a/client/app/components/posts/Show.jsx +++ b/client/app/components/posts/Show.jsx @@ -19,15 +19,19 @@ const Show = ({ {!post.unlisted && (
-
-
React to this post
- {reactionLinks.map((link) => ( - - {link.reaction} - - ))} -
-
+ {reactionLinks.length > 0 && ( + <> +
+
React to this post
+ {reactionLinks.map((link) => ( + + {link.reaction} + + ))} +
+
+ + )} {!post.author.newsletter_disabled && (