diff --git a/app/javascript/src/javascripts/autocomplete.js.erb b/app/javascript/src/javascripts/autocomplete.js.erb index c207da5fc..b57939ce8 100644 --- a/app/javascript/src/javascripts/autocomplete.js.erb +++ b/app/javascript/src/javascripts/autocomplete.js.erb @@ -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) { diff --git a/app/models/post_disapproval.rb b/app/models/post_disapproval.rb index 24a711923..5557a1b87 100644 --- a/app/models/post_disapproval.rb +++ b/app/models/post_disapproval.rb @@ -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 diff --git a/app/views/post_disapprovals/_detailed_rejection_dialog.html.erb b/app/views/post_disapprovals/_detailed_rejection_dialog.html.erb index 59fa8e9c1..a72e1e5ed 100644 --- a/app/views/post_disapprovals/_detailed_rejection_dialog.html.erb +++ b/app/views/post_disapprovals/_detailed_rejection_dialog.html.erb @@ -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 %> diff --git a/app/views/post_disapprovals/index.html.erb b/app/views/post_disapprovals/index.html.erb index f3f836caf..84087cd22 100644 --- a/app/views/post_disapprovals/index.html.erb +++ b/app/views/post_disapprovals/index.html.erb @@ -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" %> diff --git a/db/migrate/20200403210353_change_reason_default_on_post_disapprovals.rb b/db/migrate/20200403210353_change_reason_default_on_post_disapprovals.rb new file mode 100644 index 000000000..bec85d44e --- /dev/null +++ b/db/migrate/20200403210353_change_reason_default_on_post_disapprovals.rb @@ -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 diff --git a/db/structure.sql b/db/structure.sql index b5d3db372..bbcbade6c 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -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'); diff --git a/test/factories/post_disapproval.rb b/test/factories/post_disapproval.rb index 38b1ae024..55052a2b5 100644 --- a/test/factories/post_disapproval.rb +++ b/test/factories/post_disapproval.rb @@ -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 diff --git a/test/system/autocomplete_test.rb b/test/system/autocomplete_test.rb index 311ad9103..63769a1c3 100644 --- a/test/system/autocomplete_test.rb +++ b/test/system/autocomplete_test.rb @@ -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 diff --git a/test/unit/post_disapproval_test.rb b/test/unit/post_disapproval_test.rb index 7aaa5b8aa..2431b4fa6 100644 --- a/test/unit/post_disapproval_test.rb +++ b/test/unit/post_disapproval_test.rb @@ -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