Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions app/controllers/authors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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
17 changes: 11 additions & 6 deletions app/controllers/posts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions app/controllers/reactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/mailers/authors_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 11 additions & 6 deletions app/mailers/subscription_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
1 change: 1 addition & 0 deletions app/views/authors/settings.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
:header_image_url,
:guestbook_disabled,
:newsletter_disabled,
:reactions_disabled,
:hide_from_homepage,
:secret,
:cover_style,
Expand Down
13 changes: 12 additions & 1 deletion client/app/components/authors/settings/General.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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",
};

Expand All @@ -35,6 +36,7 @@ const General = ({
header_image_url,
guestbook_disabled,
newsletter_disabled,
reactions_disabled,
hide_from_homepage,
} = author;

Expand All @@ -49,6 +51,7 @@ const General = ({
header_image_url: header_image_url || "",
guestbook_disabled,
newsletter_disabled,
reactions_disabled,
hide_from_homepage,
});

Expand Down Expand Up @@ -122,7 +125,9 @@ const General = ({
</label>
<input
id="author-username"
className={`text-field ${fieldHasErrorMessages(fieldTypes.USERNAME) ? "text-field--error" : ""}`}
className={`text-field ${
fieldHasErrorMessages(fieldTypes.USERNAME) ? "text-field--error" : ""
}`}
value={editedAuthor.username}
onChange={(e) => editAuthor(fieldTypes.USERNAME, e.target.value)}
/>
Expand Down Expand Up @@ -248,6 +253,12 @@ const General = ({
checked={editedAuthor.newsletter_disabled}
label="Disable email subscription and newsletter"
/>
<Checkbox
id="author-reactions-disabled"
onClick={(checked) => editAuthor(fieldTypes.REACTIONS_DISABLED, checked)}
checked={editedAuthor.reactions_disabled}
label="Disable post reactions"
/>
<Checkbox
id="author-hide-from-homepage"
onClick={(checked) => editAuthor(fieldTypes.HIDE_FROM_HOMEPAGE, checked)}
Expand Down
22 changes: 13 additions & 9 deletions client/app/components/posts/Show.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,19 @@ const Show = ({
<Post post={post} isMainPost reactionLinks={reactionLinks} />
{!post.unlisted && (
<div>
<div className="reaction-links">
<div className="header h4">React to this post</div>
{reactionLinks.map((link) => (
<a key={link.url} className="reaction-link" href={link.url}>
{link.reaction}
</a>
))}
</div>
<hr />
{reactionLinks.length > 0 && (
<>
<div className="reaction-links">
<div className="header h4">React to this post</div>
{reactionLinks.map((link) => (
<a key={link.url} className="reaction-link" href={link.url}>
{link.reaction}
</a>
))}
</div>
<hr />
</>
)}
{!post.author.newsletter_disabled && (
<div id="subscription-form">
<label htmlFor="email" className="h4">
Expand Down
20 changes: 12 additions & 8 deletions client/app/components/subscription_mailer/NewPost.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,18 @@ const NewPost = ({ hiddenText, post, renderedText, weeklyUrl, unsubscribeUrl, re
</p>
)}

<p>Share your anonymous reaction to this post with the author—it would mean a lot to them!</p>
<div className="reaction-links">
{reactionLinks.map((link) => (
<a className="reaction-link" href={link.url}>
{link.reaction}
</a>
))}
</div>
{reactionLinks.length > 0 && (
<>
<p>Share your anonymous reaction to this post with the author—it would mean a lot to them!</p>
<div className="reaction-links">
{reactionLinks.map((link) => (
<a className="reaction-link" href={link.url}>
{link.reaction}
</a>
))}
</div>
</>
)}

<div className="links-footer" style={{ marginBottom: "20px" }}>
{weeklyUrl && <a href={weeklyUrl}>Receive Weekly Updates Instead</a>}
Expand Down
1 change: 1 addition & 0 deletions client/app/types/author.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const type = PropTypes.shape({
link: PropTypes.string,
meta_image_url: PropTypes.string,
newsletter_disabled: PropTypes.bool.isRequired,
reactions_disabled: PropTypes.bool.isRequired,
secret: PropTypes.string.isRequired,
twitter: PropTypes.string,
username: PropTypes.string.isRequired,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddReactionsDisabledToAuthors < ActiveRecord::Migration[5.2]
def change
add_column :authors, :reactions_disabled, :boolean, default: false
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 2023_02_24_140201) do
ActiveRecord::Schema.define(version: 2026_05_13_120000) do

create_table "authors", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb3", force: :cascade do |t|
t.string "secret", collation: "latin1_swedish_ci"
Expand All @@ -37,6 +37,7 @@
t.string "cover_style", default: "full", collation: "latin1_swedish_ci"
t.string "blog_layout_style", default: "vertical", collation: "latin1_swedish_ci"
t.boolean "custom_theme_enabled", default: false
t.boolean "reactions_disabled", default: false
t.index ["hide_from_homepage"], name: "index_authors_on_hide_from_homepage"
t.index ["homepage_activity"], name: "index_authors_on_homepage_activity"
end
Expand Down