post disapprovals: refactor disapproval reasons.
* Factor out reasons into a constant * Change column default and eliminate unused `legacy` reason.
This commit is contained in:
@@ -6,6 +6,7 @@ let Autocomplete = {};
|
||||
Autocomplete.METATAGS = <%= PostQueryBuilder::METATAGS.to_json.html_safe %>;
|
||||
Autocomplete.TAG_CATEGORIES = <%= TagCategory.mapping.to_json.html_safe %>;
|
||||
Autocomplete.ORDER_METATAGS = <%= PostQueryBuilder::ORDER_METATAGS.to_json.html_safe %>;
|
||||
Autocomplete.DISAPPROVAL_REASONS = <%= PostDisapproval::REASONS.to_json.html_safe %>;
|
||||
/* eslint-enable */
|
||||
|
||||
Autocomplete.TAG_PREFIXES = "-|~|" + Object.keys(Autocomplete.TAG_CATEGORIES).map(category => category + ":").join("|");
|
||||
@@ -286,9 +287,7 @@ Autocomplete.static_metatags = {
|
||||
filetype: [
|
||||
"jpg", "png", "gif", "swf", "zip", "webm", "mp4"
|
||||
],
|
||||
disapproved: [
|
||||
"disinterest", "poor_quality", "breaks_rules"
|
||||
]
|
||||
disapproved: Autocomplete.DISAPPROVAL_REASONS
|
||||
}
|
||||
|
||||
Autocomplete.static_metatag_source = function(term, metatag) {
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
class PostDisapproval < ApplicationRecord
|
||||
DELETION_THRESHOLD = 1.month
|
||||
REASONS = %w[breaks_rules poor_quality disinterest]
|
||||
|
||||
belongs_to :post
|
||||
belongs_to :user
|
||||
validates_uniqueness_of :post_id, :scope => [:user_id], :message => "have already hidden this post"
|
||||
validates_inclusion_of :reason, :in => %w(legacy breaks_rules poor_quality disinterest)
|
||||
validates_inclusion_of :reason, in: REASONS
|
||||
|
||||
scope :with_message, -> { where.not(message: nil) }
|
||||
scope :without_message, -> { where(message: nil) }
|
||||
scope :breaks_rules, -> {where(:reason => "breaks_rules")}
|
||||
scope :poor_quality, -> {where(:reason => "poor_quality")}
|
||||
scope :disinterest, -> {where(:reason => ["disinterest", "legacy"])}
|
||||
scope :disinterest, -> {where(:reason => "disinterest")}
|
||||
|
||||
def self.prune!
|
||||
PostDisapproval.where("post_id in (select _.post_id from post_disapprovals _ where _.created_at < ?)", DELETION_THRESHOLD.ago).delete_all
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
|
||||
<%= edit_form_for(PostDisapproval.new, url: post_disapprovals_path, remote: true, html: { id: "detailed-rejection-form" }) do |f| %>
|
||||
<%= f.hidden_field :post_id, value: "x" %>
|
||||
<%= f.input :reason, collection: [["Breaks Rules", "breaks_rules"], ["Poor Quality", "poor_quality"], ["No interest", "disinterest"]] %>
|
||||
<%= f.input :reason, collection: PostDisapproval::REASONS.map { |x| [x.humanize, x] } %>
|
||||
<%= f.input :message, as: :string %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<%= f.input :post_id, label: "Post ID", input_html: { value: params[:search][:post_id] } %>
|
||||
<%= f.input :post_tags_match, label: "Tags", input_html: { value: params[:search][:post_tags_match], data: { autocomplete: "tag-query" } } %>
|
||||
<%= f.input :message_matches, label: "Message", input_html: { value: params[:search][:message_matches] } %>
|
||||
<%= f.input :reason, label: "Reason", collection: %w[breaks_rules disinterest poor_quality].map { |x| [x.humanize, x] }, include_blank: true, selected: params[:search][:reason] %>
|
||||
<%= f.input :reason, label: "Reason", collection: PostDisapproval::REASONS.map { |x| [x.humanize, x] }, include_blank: true, selected: params[:search][:reason] %>
|
||||
<%= f.input :has_message, label: "Has Message?", collection: %w[Yes No], include_blank: true, selected: params[:search][:has_message] %>
|
||||
<%= f.input :order, collection: [["ID", "id_desc"], ["Post ID", "post_id_desc"]], selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
class ChangeReasonDefaultOnPostDisapprovals < ActiveRecord::Migration[6.0]
|
||||
def change
|
||||
change_column_null :post_disapprovals, :reason, false
|
||||
change_column_default :post_disapprovals, :reason, from: "legacy", to: nil
|
||||
end
|
||||
end
|
||||
@@ -2644,7 +2644,7 @@ CREATE TABLE public.post_disapprovals (
|
||||
post_id integer NOT NULL,
|
||||
created_at timestamp without time zone,
|
||||
updated_at timestamp without time zone,
|
||||
reason character varying DEFAULT 'legacy'::character varying,
|
||||
reason character varying NOT NULL,
|
||||
message text
|
||||
);
|
||||
|
||||
@@ -7364,6 +7364,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
||||
('20200309043653'),
|
||||
('20200318224633'),
|
||||
('20200325073456'),
|
||||
('20200325074859');
|
||||
('20200325074859'),
|
||||
('20200403210353');
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ FactoryBot.define do
|
||||
factory(:post_disapproval) do
|
||||
user
|
||||
post
|
||||
reason { %w(breaks_rules poor_quality disinterest).sample }
|
||||
reason { PostDisapproval::REASONS.sample }
|
||||
message { FFaker::Lorem.sentence }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -45,8 +45,8 @@ class AutocompleteTest < ApplicationSystemTestCase
|
||||
assert_metatag_autocomplete_equals(%w[rating note status], "locked")
|
||||
assert_metatag_autocomplete_equals(%w[safe questionable explicit], "rating")
|
||||
assert_metatag_autocomplete_equals(%w[gif jpg mp4 png swf webm zip], "filetype")
|
||||
assert_metatag_autocomplete_equals(%w[any none disinterest poor_quality breaks_rules], "disapproval")
|
||||
assert_metatag_autocomplete_equals(%w[active any banned deleted flagged modqueue pending unmoderated], "status")
|
||||
assert_metatag_autocomplete_equals(PostDisapproval::REASONS, "disapproval")
|
||||
end
|
||||
|
||||
should "work for username metatags" do
|
||||
|
||||
@@ -26,7 +26,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
|
||||
context "made by alice" do
|
||||
setup do
|
||||
@disapproval = PostDisapproval.create(:user => @alice, :post => @post_1)
|
||||
@disapproval = create(:post_disapproval, user: @alice, post: @post_1)
|
||||
end
|
||||
|
||||
context "when the current user is alice" do
|
||||
@@ -57,9 +57,7 @@ class PostDisapprovalTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@post = FactoryBot.create(:post)
|
||||
@user = FactoryBot.create(:user)
|
||||
travel_to(2.months.ago) do
|
||||
@disapproval = PostDisapproval.create(:user => @user, :post => @post)
|
||||
end
|
||||
@disapproval = create(:post_disapproval, user: @user, post: @post, created_at: 2.months.ago)
|
||||
end
|
||||
|
||||
should "be pruned" do
|
||||
|
||||
Reference in New Issue
Block a user