Merge pull request #4530 from BrokenEagle/parent-child-status-search
Add ability to search on status of parent/child
This commit is contained in:
@@ -9,6 +9,7 @@ Autocomplete.ORDER_METATAGS = <%= PostQueryBuilder::ORDER_METATAGS.to_json.html_
|
|||||||
Autocomplete.DISAPPROVAL_REASONS = <%= PostDisapproval::REASONS.to_json.html_safe %>;
|
Autocomplete.DISAPPROVAL_REASONS = <%= PostDisapproval::REASONS.to_json.html_safe %>;
|
||||||
/* eslint-enable */
|
/* eslint-enable */
|
||||||
|
|
||||||
|
Autocomplete.MISC_STATUSES = ["deleted", "active", "pending", "flagged", "banned", "modqueue", "unmoderated"];
|
||||||
Autocomplete.TAG_PREFIXES = "-|~|" + Object.keys(Autocomplete.TAG_CATEGORIES).map(category => category + ":").join("|");
|
Autocomplete.TAG_PREFIXES = "-|~|" + Object.keys(Autocomplete.TAG_CATEGORIES).map(category => category + ":").join("|");
|
||||||
Autocomplete.METATAGS_REGEX = Autocomplete.METATAGS.concat(Object.keys(Autocomplete.TAG_CATEGORIES)).join("|");
|
Autocomplete.METATAGS_REGEX = Autocomplete.METATAGS.concat(Object.keys(Autocomplete.TAG_CATEGORIES)).join("|");
|
||||||
Autocomplete.TERM_REGEX = new RegExp(`([-~]*)(?:(${Autocomplete.METATAGS_REGEX}):)?(\\S*)$`, "i");
|
Autocomplete.TERM_REGEX = new RegExp(`([-~]*)(?:(${Autocomplete.METATAGS_REGEX}):)?(\\S*)$`, "i");
|
||||||
@@ -268,9 +269,7 @@ Autocomplete.render_item = function(list, item) {
|
|||||||
|
|
||||||
Autocomplete.static_metatags = {
|
Autocomplete.static_metatags = {
|
||||||
order: Autocomplete.ORDER_METATAGS,
|
order: Autocomplete.ORDER_METATAGS,
|
||||||
status: [
|
status: ["any"].concat(Autocomplete.MISC_STATUSES),
|
||||||
"any", "deleted", "active", "pending", "flagged", "banned", "modqueue", "unmoderated"
|
|
||||||
],
|
|
||||||
rating: [
|
rating: [
|
||||||
"safe", "questionable", "explicit"
|
"safe", "questionable", "explicit"
|
||||||
],
|
],
|
||||||
@@ -280,12 +279,8 @@ Autocomplete.static_metatags = {
|
|||||||
embedded: [
|
embedded: [
|
||||||
"true", "false"
|
"true", "false"
|
||||||
],
|
],
|
||||||
child: [
|
child: ["any", "none"].concat(Autocomplete.MISC_STATUSES),
|
||||||
"any", "none"
|
parent: ["any", "none"].concat(Autocomplete.MISC_STATUSES),
|
||||||
],
|
|
||||||
parent: [
|
|
||||||
"any", "none"
|
|
||||||
],
|
|
||||||
filetype: [
|
filetype: [
|
||||||
"jpg", "png", "gif", "swf", "zip", "webm", "mp4"
|
"jpg", "png", "gif", "swf", "zip", "webm", "mp4"
|
||||||
],
|
],
|
||||||
|
|||||||
@@ -307,6 +307,8 @@ class PostQueryBuilder
|
|||||||
Post.where(parent: nil)
|
Post.where(parent: nil)
|
||||||
when "any"
|
when "any"
|
||||||
Post.where.not(parent: nil)
|
Post.where.not(parent: nil)
|
||||||
|
when /pending|flagged|modqueue|deleted|banned|active|unmoderated/
|
||||||
|
Post.where.not(parent: nil).where(parent: status_matches(parent))
|
||||||
when /\A\d+\z/
|
when /\A\d+\z/
|
||||||
Post.where(id: parent).or(Post.where(parent: parent))
|
Post.where(id: parent).or(Post.where(parent: parent))
|
||||||
else
|
else
|
||||||
@@ -320,6 +322,8 @@ class PostQueryBuilder
|
|||||||
Post.where(has_children: false)
|
Post.where(has_children: false)
|
||||||
when "any"
|
when "any"
|
||||||
Post.where(has_children: true)
|
Post.where(has_children: true)
|
||||||
|
when /pending|flagged|modqueue|deleted|banned|active|unmoderated/
|
||||||
|
Post.where(has_children: true).where(children: status_matches(child))
|
||||||
else
|
else
|
||||||
Post.none
|
Post.none
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -277,6 +277,19 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
|||||||
assert_tag_match([child, parent], "-child:garbage")
|
assert_tag_match([child, parent], "-child:garbage")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "return posts when using the status of the parent/child" do
|
||||||
|
parent_of_deleted = create(:post)
|
||||||
|
deleted = create(:post, is_deleted: true, tag_string: "parent:#{parent_of_deleted.id}")
|
||||||
|
child_of_deleted = create(:post, tag_string: "parent:#{deleted.id}")
|
||||||
|
all = [child_of_deleted, deleted, parent_of_deleted]
|
||||||
|
|
||||||
|
assert_tag_match([child_of_deleted], "parent:deleted")
|
||||||
|
assert_tag_match(all - [child_of_deleted], "-parent:deleted")
|
||||||
|
|
||||||
|
assert_tag_match([parent_of_deleted], "child:deleted")
|
||||||
|
assert_tag_match(all - [parent_of_deleted], "-child:deleted")
|
||||||
|
end
|
||||||
|
|
||||||
should "return posts for the favgroup:<name> metatag" do
|
should "return posts for the favgroup:<name> metatag" do
|
||||||
post1 = create(:post)
|
post1 = create(:post)
|
||||||
post2 = create(:post)
|
post2 = create(:post)
|
||||||
|
|||||||
Reference in New Issue
Block a user