Merge pull request #3832 from evazion/feat-modqueue-metatags
Add status:<unmoderated|modqueue>, disapproval:<type> metatags
This commit is contained in:
@@ -128,6 +128,7 @@ Autocomplete.initialize_tag_autocomplete = function() {
|
|||||||
case "child":
|
case "child":
|
||||||
case "parent":
|
case "parent":
|
||||||
case "filetype":
|
case "filetype":
|
||||||
|
case "disapproval":
|
||||||
Autocomplete.static_metatag_source(term, resp, metatag);
|
Autocomplete.static_metatag_source(term, resp, metatag);
|
||||||
return;
|
return;
|
||||||
case "user":
|
case "user":
|
||||||
@@ -398,7 +399,7 @@ Autocomplete.static_metatags = {
|
|||||||
"custom"
|
"custom"
|
||||||
].concat(<%= TagCategory.short_name_list.map {|category| [category + "tags", category + "tags_asc"]}.flatten %>),
|
].concat(<%= TagCategory.short_name_list.map {|category| [category + "tags", category + "tags_asc"]}.flatten %>),
|
||||||
status: [
|
status: [
|
||||||
"any", "deleted", "active", "pending", "flagged", "banned"
|
"any", "deleted", "active", "pending", "flagged", "banned", "modqueue", "unmoderated"
|
||||||
],
|
],
|
||||||
rating: [
|
rating: [
|
||||||
"safe", "questionable", "explicit"
|
"safe", "questionable", "explicit"
|
||||||
@@ -415,6 +416,9 @@ Autocomplete.static_metatags = {
|
|||||||
filetype: [
|
filetype: [
|
||||||
"jpg", "png", "gif", "swf", "zip", "webm", "mp4"
|
"jpg", "png", "gif", "swf", "zip", "webm", "mp4"
|
||||||
],
|
],
|
||||||
|
disapproval: [
|
||||||
|
"any", "none", "disinterest", "poor_quality", "breaks_rules"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
|
|
||||||
Autocomplete.static_metatag_source = function(term, resp, metatag) {
|
Autocomplete.static_metatag_source = function(term, resp, metatag) {
|
||||||
|
|||||||
@@ -229,8 +229,12 @@ class AnonymousUser
|
|||||||
false
|
false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def post_disapprovals
|
||||||
|
PostDisapproval.none
|
||||||
|
end
|
||||||
|
|
||||||
def saved_searches
|
def saved_searches
|
||||||
SavedSearch.where(false)
|
SavedSearch.none
|
||||||
end
|
end
|
||||||
|
|
||||||
def has_saved_searches?
|
def has_saved_searches?
|
||||||
|
|||||||
@@ -131,18 +131,24 @@ class PostQueryBuilder
|
|||||||
relation = relation.where("posts.is_pending = TRUE")
|
relation = relation.where("posts.is_pending = TRUE")
|
||||||
elsif q[:status] == "flagged"
|
elsif q[:status] == "flagged"
|
||||||
relation = relation.where("posts.is_flagged = TRUE")
|
relation = relation.where("posts.is_flagged = TRUE")
|
||||||
|
elsif q[:status] == "modqueue"
|
||||||
|
relation = relation.where("posts.is_pending = TRUE OR posts.is_flagged = TRUE")
|
||||||
elsif q[:status] == "deleted"
|
elsif q[:status] == "deleted"
|
||||||
relation = relation.where("posts.is_deleted = TRUE")
|
relation = relation.where("posts.is_deleted = TRUE")
|
||||||
elsif q[:status] == "banned"
|
elsif q[:status] == "banned"
|
||||||
relation = relation.where("posts.is_banned = TRUE")
|
relation = relation.where("posts.is_banned = TRUE")
|
||||||
elsif q[:status] == "active"
|
elsif q[:status] == "active"
|
||||||
relation = relation.where("posts.is_pending = FALSE AND posts.is_deleted = FALSE AND posts.is_banned = FALSE AND posts.is_flagged = FALSE")
|
relation = relation.where("posts.is_pending = FALSE AND posts.is_deleted = FALSE AND posts.is_banned = FALSE AND posts.is_flagged = FALSE")
|
||||||
|
elsif q[:status] == "unmoderated"
|
||||||
|
relation = relation.merge(Post.pending_or_flagged.available_for_moderation)
|
||||||
elsif q[:status] == "all" || q[:status] == "any"
|
elsif q[:status] == "all" || q[:status] == "any"
|
||||||
# do nothing
|
# do nothing
|
||||||
elsif q[:status_neg] == "pending"
|
elsif q[:status_neg] == "pending"
|
||||||
relation = relation.where("posts.is_pending = FALSE")
|
relation = relation.where("posts.is_pending = FALSE")
|
||||||
elsif q[:status_neg] == "flagged"
|
elsif q[:status_neg] == "flagged"
|
||||||
relation = relation.where("posts.is_flagged = FALSE")
|
relation = relation.where("posts.is_flagged = FALSE")
|
||||||
|
elsif q[:status_neg] == "modqueue"
|
||||||
|
relation = relation.where("posts.is_pending = FALSE AND posts.is_flagged = FALSE")
|
||||||
elsif q[:status_neg] == "deleted"
|
elsif q[:status_neg] == "deleted"
|
||||||
relation = relation.where("posts.is_deleted = FALSE")
|
relation = relation.where("posts.is_deleted = FALSE")
|
||||||
elsif q[:status_neg] == "banned"
|
elsif q[:status_neg] == "banned"
|
||||||
@@ -222,6 +228,34 @@ class PostQueryBuilder
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if q[:disapproval]
|
||||||
|
q[:disapproval].each do |disapproval|
|
||||||
|
disapprovals = CurrentUser.user.post_disapprovals.select(:post_id)
|
||||||
|
|
||||||
|
if disapproval.in?(%w[none false])
|
||||||
|
relation = relation.where.not("posts.id": disapprovals)
|
||||||
|
elsif disapproval.in?(%w[any all true])
|
||||||
|
relation = relation.where("posts.id": disapprovals)
|
||||||
|
else
|
||||||
|
relation = relation.where("posts.id": disapprovals.where(reason: disapproval))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if q[:disapproval_neg]
|
||||||
|
q[:disapproval_neg].each do |disapproval|
|
||||||
|
disapprovals = CurrentUser.user.post_disapprovals.select(:post_id)
|
||||||
|
|
||||||
|
if disapproval.in?(%w[none false])
|
||||||
|
relation = relation.where("posts.id": disapprovals)
|
||||||
|
elsif disapproval.in?(%w[any all true])
|
||||||
|
relation = relation.where.not("posts.id": disapprovals)
|
||||||
|
else
|
||||||
|
relation = relation.where.not("posts.id": disapprovals.where(reason: disapproval))
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if q[:flagger_ids_neg]
|
if q[:flagger_ids_neg]
|
||||||
q[:flagger_ids_neg].each do |flagger_id|
|
q[:flagger_ids_neg].each do |flagger_id|
|
||||||
if CurrentUser.can_view_flagger?(flagger_id)
|
if CurrentUser.can_view_flagger?(flagger_id)
|
||||||
|
|||||||
@@ -1645,7 +1645,9 @@ class Post < ApplicationRecord
|
|||||||
where("uploader_id = ?", user_id)
|
where("uploader_id = ?", user_id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def available_for_moderation(hidden, user = CurrentUser.user)
|
def available_for_moderation(hidden = false, user = CurrentUser.user)
|
||||||
|
return none if user.is_anonymous?
|
||||||
|
|
||||||
approved_posts = user.post_approvals.select(:post_id)
|
approved_posts = user.post_approvals.select(:post_id)
|
||||||
disapproved_posts = user.post_disapprovals.select(:post_id)
|
disapproved_posts = user.post_disapprovals.select(:post_id)
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
class Tag < ApplicationRecord
|
class Tag < ApplicationRecord
|
||||||
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 300
|
COSINE_SIMILARITY_RELATED_TAG_THRESHOLD = 300
|
||||||
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer|" +
|
METATAGS = "-user|user|-approver|approver|commenter|comm|noter|noteupdater|artcomm|-pool|pool|ordpool|-favgroup|favgroup|-fav|fav|ordfav|md5|-rating|rating|-locked|locked|width|height|mpixels|ratio|score|favcount|filesize|source|-source|id|-id|date|age|order|limit|-status|status|tagcount|parent|-parent|child|pixiv_id|pixiv|search|upvote|downvote|filetype|-filetype|flagger|-flagger|appealer|-appealer|disapproval|-disapproval|" +
|
||||||
TagCategory.short_name_list.map {|x| "#{x}tags"}.join("|")
|
TagCategory.short_name_list.map {|x| "#{x}tags"}.join("|")
|
||||||
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
|
SUBQUERY_METATAGS = "commenter|comm|noter|noteupdater|artcomm|flagger|-flagger|appealer|-appealer"
|
||||||
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
has_one :wiki_page, :foreign_key => "title", :primary_key => "name"
|
||||||
@@ -577,6 +577,14 @@ class Tag < ApplicationRecord
|
|||||||
user_id = User.name_to_id(g2)
|
user_id = User.name_to_id(g2)
|
||||||
q[:artcomm_ids] << user_id unless user_id.blank?
|
q[:artcomm_ids] << user_id unless user_id.blank?
|
||||||
|
|
||||||
|
when "disapproval"
|
||||||
|
q[:disapproval] ||= []
|
||||||
|
q[:disapproval] << g2
|
||||||
|
|
||||||
|
when "-disapproval"
|
||||||
|
q[:disapproval_neg] ||= []
|
||||||
|
q[:disapproval_neg] << g2
|
||||||
|
|
||||||
when "-pool"
|
when "-pool"
|
||||||
if g2.downcase == "none"
|
if g2.downcase == "none"
|
||||||
q[:pool] = "any"
|
q[:pool] = "any"
|
||||||
|
|||||||
@@ -2130,6 +2130,7 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
banned = FactoryBot.create(:post, is_banned: true)
|
banned = FactoryBot.create(:post, is_banned: true)
|
||||||
all = [banned, deleted, flagged, pending]
|
all = [banned, deleted, flagged, pending]
|
||||||
|
|
||||||
|
assert_tag_match([flagged, pending], "status:modqueue")
|
||||||
assert_tag_match([pending], "status:pending")
|
assert_tag_match([pending], "status:pending")
|
||||||
assert_tag_match([flagged], "status:flagged")
|
assert_tag_match([flagged], "status:flagged")
|
||||||
assert_tag_match([deleted], "status:deleted")
|
assert_tag_match([deleted], "status:deleted")
|
||||||
@@ -2138,6 +2139,7 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match(all, "status:any")
|
assert_tag_match(all, "status:any")
|
||||||
assert_tag_match(all, "status:all")
|
assert_tag_match(all, "status:all")
|
||||||
|
|
||||||
|
assert_tag_match(all - [flagged, pending], "-status:modqueue")
|
||||||
assert_tag_match(all - [pending], "-status:pending")
|
assert_tag_match(all - [pending], "-status:pending")
|
||||||
assert_tag_match(all - [flagged], "-status:flagged")
|
assert_tag_match(all - [flagged], "-status:flagged")
|
||||||
assert_tag_match(all - [deleted], "-status:deleted")
|
assert_tag_match(all - [deleted], "-status:deleted")
|
||||||
@@ -2145,6 +2147,17 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match(all, "-status:active")
|
assert_tag_match(all, "-status:active")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return posts for the status:unmoderated metatag" do
|
||||||
|
flagged = FactoryBot.create(:post, is_flagged: true)
|
||||||
|
pending = FactoryBot.create(:post, is_pending: true)
|
||||||
|
disapproved = FactoryBot.create(:post, is_pending: true)
|
||||||
|
|
||||||
|
FactoryBot.create(:post_flag, post: flagged)
|
||||||
|
FactoryBot.create(:post_disapproval, post: disapproved, reason: "disinterest")
|
||||||
|
|
||||||
|
assert_tag_match([pending, flagged], "status:unmoderated")
|
||||||
|
end
|
||||||
|
|
||||||
should "respect the 'Deleted post filter' option when using the status:banned metatag" do
|
should "respect the 'Deleted post filter' option when using the status:banned metatag" do
|
||||||
deleted = FactoryBot.create(:post, is_deleted: true, is_banned: true)
|
deleted = FactoryBot.create(:post, is_deleted: true, is_banned: true)
|
||||||
undeleted = FactoryBot.create(:post, is_banned: true)
|
undeleted = FactoryBot.create(:post, is_banned: true)
|
||||||
@@ -2308,6 +2321,24 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return posts for a disapproval:<type> metatag" do
|
||||||
|
CurrentUser.scoped(FactoryBot.create(:mod_user)) do
|
||||||
|
pending = FactoryBot.create(:post, is_pending: true)
|
||||||
|
disapproved = FactoryBot.create(:post, is_pending: true)
|
||||||
|
disapproval = FactoryBot.create(:post_disapproval, post: disapproved, reason: "disinterest")
|
||||||
|
|
||||||
|
assert_tag_match([pending], "disapproval:none")
|
||||||
|
assert_tag_match([disapproved], "disapproval:any")
|
||||||
|
assert_tag_match([disapproved], "disapproval:disinterest")
|
||||||
|
assert_tag_match([], "disapproval:breaks_rules")
|
||||||
|
|
||||||
|
assert_tag_match([disapproved], "-disapproval:none")
|
||||||
|
assert_tag_match([pending], "-disapproval:any")
|
||||||
|
assert_tag_match([pending], "-disapproval:disinterest")
|
||||||
|
assert_tag_match([disapproved, pending], "-disapproval:breaks_rules")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "return posts ordered by a particular attribute" do
|
should "return posts ordered by a particular attribute" do
|
||||||
posts = (1..2).map do |n|
|
posts = (1..2).map do |n|
|
||||||
tags = ["tagme", "gentag1 gentag2 artist:arttag char:chartag copy:copytag"]
|
tags = ["tagme", "gentag1 gentag2 artist:arttag char:chartag copy:copytag"]
|
||||||
|
|||||||
Reference in New Issue
Block a user