post disapprovals: refactor disapproval reasons.

* Factor out reasons into a constant
* Change column default and eliminate unused `legacy` reason.
This commit is contained in:
evazion
2020-04-03 15:57:29 -05:00
parent 3e792019e5
commit fde42022c0
9 changed files with 20 additions and 15 deletions

View File

@@ -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) {

View File

@@ -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

View File

@@ -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>

View File

@@ -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" %>