diff --git a/app/javascript/src/javascripts/autocomplete.js.erb b/app/javascript/src/javascripts/autocomplete.js.erb index d92caa6b4..cb7ef0c3d 100644 --- a/app/javascript/src/javascripts/autocomplete.js.erb +++ b/app/javascript/src/javascripts/autocomplete.js.erb @@ -399,7 +399,7 @@ Autocomplete.static_metatags = { "custom" ].concat(<%= TagCategory.short_name_list.map {|category| [category + "tags", category + "tags_asc"]}.flatten %>), status: [ - "any", "deleted", "active", "pending", "flagged", "banned" + "any", "deleted", "active", "pending", "flagged", "banned", "modqueue", "unmoderated" ], rating: [ "safe", "questionable", "explicit" diff --git a/app/logical/post_query_builder.rb b/app/logical/post_query_builder.rb index c040a9baa..fa3f78bd9 100644 --- a/app/logical/post_query_builder.rb +++ b/app/logical/post_query_builder.rb @@ -131,18 +131,24 @@ class PostQueryBuilder relation = relation.where("posts.is_pending = TRUE") elsif q[:status] == "flagged" 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" relation = relation.where("posts.is_deleted = TRUE") elsif q[:status] == "banned" relation = relation.where("posts.is_banned = TRUE") 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") + elsif q[:status] == "unmoderated" + relation = relation.merge(Post.pending_or_flagged.available_for_moderation) elsif q[:status] == "all" || q[:status] == "any" # do nothing elsif q[:status_neg] == "pending" relation = relation.where("posts.is_pending = FALSE") elsif q[:status_neg] == "flagged" 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" relation = relation.where("posts.is_deleted = FALSE") elsif q[:status_neg] == "banned" diff --git a/app/models/post.rb b/app/models/post.rb index 100562244..766beeef6 100644 --- a/app/models/post.rb +++ b/app/models/post.rb @@ -1645,7 +1645,9 @@ class Post < ApplicationRecord where("uploader_id = ?", user_id) 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) disapproved_posts = user.post_disapprovals.select(:post_id) diff --git a/test/unit/post_test.rb b/test/unit/post_test.rb index 732679b4f..73a5c5a08 100644 --- a/test/unit/post_test.rb +++ b/test/unit/post_test.rb @@ -2130,6 +2130,7 @@ class PostTest < ActiveSupport::TestCase banned = FactoryBot.create(:post, is_banned: true) all = [banned, deleted, flagged, pending] + assert_tag_match([flagged, pending], "status:modqueue") assert_tag_match([pending], "status:pending") assert_tag_match([flagged], "status:flagged") 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:all") + assert_tag_match(all - [flagged, pending], "-status:modqueue") assert_tag_match(all - [pending], "-status:pending") assert_tag_match(all - [flagged], "-status:flagged") assert_tag_match(all - [deleted], "-status:deleted") @@ -2145,6 +2147,17 @@ class PostTest < ActiveSupport::TestCase assert_tag_match(all, "-status:active") 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 deleted = FactoryBot.create(:post, is_deleted: true, is_banned: true) undeleted = FactoryBot.create(:post, is_banned: true)