[Posts] Change comment locked to disabled

Instead of just preventing new comments hide everything completly.
This commit is contained in:
Earlopain 2022-05-16 15:53:39 +02:00
parent 2f5b55a0bc
commit 93cd28c0e1
No known key found for this signature in database
GPG Key ID: 6CFB948E15246897
12 changed files with 46 additions and 55 deletions

View File

@ -173,7 +173,7 @@ class PostsController < ApplicationController
]
permitted_params += %i[is_rating_locked] if CurrentUser.is_privileged?
permitted_params += %i[is_note_locked bg_color] if CurrentUser.is_janitor?
permitted_params += %i[is_status_locked is_comment_locked locked_tags hide_from_anonymous hide_from_search_engines] if CurrentUser.is_admin?
permitted_params += %i[is_status_locked is_comment_disabled locked_tags hide_from_anonymous hide_from_search_engines] if CurrentUser.is_admin?
params.require(:post).permit(permitted_params)
end

View File

@ -5,7 +5,7 @@ class Comment < ApplicationRecord
belongs_to_updater
validate :validate_post_exists, on: :create
validate :validate_creator_is_not_limited, on: :create
validate :post_not_comment_locked, on: :create
validate :post_not_comment_disabled, on: :create
validates :body, presence: { message: "has no content" }
validates :body, length: { minimum: 1, maximum: Danbooru.config.comment_max_size }
@ -137,8 +137,8 @@ class Comment < ApplicationRecord
true
end
def post_not_comment_locked
errors.add(:base, "Post is comment locked") if Post.find_by(id: post_id)&.is_comment_locked && !CurrentUser.is_admin?
def post_not_comment_disabled
errors.add(:base, "Post has comments disabled") if Post.find_by(id: post_id)&.is_comment_disabled
end
def update_last_commented_at_on_create

View File

@ -1651,8 +1651,8 @@ class Post < ApplicationRecord
action = is_note_locked? ? :note_locked : :note_unlocked
PostEvent.add(id, CurrentUser.user, action)
end
if saved_change_to_is_comment_locked?
action = is_comment_locked? ? :comment_locked : :comment_unlocked
if saved_change_to_is_comment_disabled?
action = is_comment_disabled? ? :comment_disabled : :comment_enabled
PostEvent.add(id, CurrentUser.user, action)
end
end

View File

@ -15,8 +15,8 @@ class PostEvent < ApplicationRecord
status_unlocked: 11,
note_locked: 12,
note_unlocked: 13,
comment_locked: 18,
comment_unlocked: 19,
comment_disabled: 18,
comment_enabled: 19,
replacement_accepted: 14,
replacement_rejected: 15,
replacement_deleted: 16,

View File

@ -99,7 +99,7 @@ class PostSerializer < ActiveModel::Serializer
note_locked: nullable_to_truthy(object.is_note_locked),
status_locked: nullable_to_truthy(object.is_status_locked),
rating_locked: nullable_to_truthy(object.is_rating_locked),
comment_locked: nullable_to_truthy(object.is_comment_locked),
comment_disabled: nullable_to_truthy(object.is_comment_disabled),
deleted: object.is_deleted
}
end

View File

@ -1,38 +1,38 @@
<div class="comments-for-post" data-post-id="<%= post.id %>">
<div class="row notices">
<% if post.comments.hidden(CurrentUser.user).count > 0 || (params[:controller] == "comments" && post.comments.count > 6) %>
<span class="info" id="threshold-comments-notice-for-<%= post.id %>">
<%= link_to "Show all comments", comments_path(:post_id => post.id), 'data-pid': post.id, class: 'show-all-comments-for-post-link' %>
</span>
<% end %>
</div>
<% if post.is_comment_disabled %>
Comment section has been disabled.
<% end %>
<% if !post.is_comment_disabled || CurrentUser.is_admin? %>
<div class="row notices">
<% if post.comments.hidden(CurrentUser.user).count > 0 || (params[:controller] == "comments" && post.comments.count > 6) %>
<span class="info" id="threshold-comments-notice-for-<%= post.id %>">
<%= link_to "Show all comments", comments_path(:post_id => post.id), 'data-pid': post.id, class: 'show-all-comments-for-post-link' %>
</span>
<% end %>
</div>
<div class="list-of-comments">
<% if comments.empty? %>
<% if post.last_commented_at.present? %>
<p>There are no visible comments.</p>
<div class="list-of-comments">
<% if comments.empty? %>
<% if post.last_commented_at.present? %>
<p>There are no visible comments.</p>
<% else %>
<p>There are no comments.</p>
<% end %>
<% else %>
<p>There are no comments.</p>
<%= render partial: "comments/partials/show/comment", collection: comments, locals: { post: post } %>
<% end %>
<% else %>
<%= render partial: "comments/partials/show/comment", collection: comments, locals: { post: post } %>
<% end %>
</div>
</div>
<% if CurrentUser.is_member? %>
<div class="new-comment">
<% if post.is_comment_locked %>
Comments are locked.
<% end %>
<% if !post.is_comment_locked || CurrentUser.is_admin? %>
<% if CurrentUser.is_member? %>
<div class="new-comment">
<% if !CurrentUser.is_anonymous? && !CurrentUser.user.is_janitor? %>
<h2>Before commenting, read the <%= link_to "how to comment guide", wiki_pages_path(:search => {:title => "howto:comment"}) %>.</h2>
<% end %>
<p><%= link_to "Post comment", new_comment_path(comment: { post_id: post.id }), :class => "expand-comment-response" %></p>
<%= render "comments/form", comment: post.comments.new, hidden: true %>
<% end %>
</div>
<% else %>
<h5 id="respond-link"><%= link_to "Login to respond &raquo;".html_safe, new_session_path %></h5>
</div>
<% else %>
<h5 id="respond-link"><%= link_to "Login to respond &raquo;".html_safe, new_session_path %></h5>
<% end %>
<% end %>
</div>

View File

@ -31,7 +31,7 @@
<% end %>
<div class="content-menu">
<menu>
<% if !post&.is_comment_locked && !comment.is_sticky %>
<% if post && !comment.is_sticky %>
<li><%= tag.a "Reply", href: '#', class: "reply-link comment-reply-link" %></li>
<% end %>
<% if comment.editable_by?(CurrentUser.user) %>

View File

@ -87,8 +87,6 @@
<% if CurrentUser.is_admin? %>
<%= f.check_box :is_status_locked %>
<%= f.label :is_status_locked, "Status" %>
<%= f.check_box :is_comment_locked %>
<%= f.label :is_comment_locked, "New Comments"%>
<% end %>
</fieldset>
</div>
@ -109,6 +107,8 @@
<%= f.label :hide_from_anonymous, "Hide from Anon" %>
<%= f.check_box :hide_from_search_engines %>
<%= f.label :hide_from_search_engines, "Hide from search engines" %>
<%= f.check_box :is_comment_disabled %>
<%= f.label :is_comment_disabled, "Disable comments"%>
</fieldset>
</div>
<% end %>

View File

@ -1,7 +1,7 @@
class PostCommentLocked < ActiveRecord::Migration[6.1]
def change
Post.without_timeout do
add_column :posts, :is_comment_locked, :boolean, null: false, default: false
add_column :posts, :is_comment_disabled, :boolean, null: false, default: false
end
end
end

View File

@ -1700,7 +1700,7 @@ CREATE TABLE public.posts (
bg_color character varying,
generated_samples character varying[],
duration numeric,
is_comment_locked boolean DEFAULT false NOT NULL
is_comment_disabled boolean DEFAULT false NOT NULL
);
@ -4748,4 +4748,3 @@ INSERT INTO "schema_migrations" (version) VALUES
('20220219202441'),
('20220316162257'),
('20220516103329');

View File

@ -255,21 +255,13 @@ class CommentTest < ActiveSupport::TestCase
context "on a comment locked post" do
setup do
@post = create(:post, is_comment_locked: true)
@post = create(:post, is_comment_disabled: true)
end
should "prevent new comments" do
comment = FactoryBot.build(:comment, post: @post)
comment.save
assert_equal(["Post is comment locked"], comment.errors.full_messages)
end
should "still allow comments from admins" do
as create(:admin_user) do
@comment = FactoryBot.build(:comment, post: @post)
@comment.save
end
assert @comment.errors.empty?
assert_equal(["Post has comments disabled"], comment.errors.full_messages)
end
end
end

View File

@ -70,13 +70,13 @@ class PostEventTest < ActiveSupport::TestCase
@post.save
end
assert_post_events_created(@admin, :comment_locked) do
@post.is_comment_locked = true
assert_post_events_created(@admin, :comment_disabled) do
@post.is_comment_disabled = true
@post.save
end
assert_post_events_created(@admin, :comment_unlocked) do
@post.is_comment_locked = false
assert_post_events_created(@admin, :comment_enabled) do
@post.is_comment_disabled = false
@post.save
end