posts: add "general" rating; rename "safe" rating to "sensitive".
* Add "general" rating. * Rename "safe" rating to "sensitive". * Change safe mode to include both rating:s and rating:g. * Treat rating:safe as a synonym for rating:sensitive. * Link "howto:rate" in the post edit form.
This commit is contained in:
@@ -63,7 +63,7 @@ class DiscordSlashCommand
|
||||
end
|
||||
|
||||
def is_censored?
|
||||
(post.rating != "s" && !is_nsfw_channel?) || !post.visible?(User.anonymous) || censored_tags.any? { |tag| tag.in?(post.tag_array) }
|
||||
(post.rating.in?(["q", "e"]) && !is_nsfw_channel?) || !post.visible?(User.anonymous) || censored_tags.any? { |tag| tag.in?(post.tag_array) }
|
||||
end
|
||||
|
||||
def is_nsfw_channel?
|
||||
|
||||
@@ -42,13 +42,13 @@ class DiscordSlashCommand
|
||||
return nil if tag.nil? || tag.empty?
|
||||
|
||||
if tag.artist?
|
||||
search = "#{tag.name} rating:safe"
|
||||
search = "#{tag.name} is:sfw"
|
||||
elsif tag.copyright?
|
||||
search = "#{tag.name} rating:safe everyone copytags:<5 -parody -crossover"
|
||||
search = "#{tag.name} is:sfw everyone copytags:<5 -parody -crossover"
|
||||
elsif tag.character?
|
||||
search = "#{tag.name} rating:safe solo chartags:<5"
|
||||
search = "#{tag.name} is:sfw solo chartags:<5"
|
||||
else # meta or general
|
||||
search = "#{tag.name} rating:safe -animated -6+girls -comic"
|
||||
search = "#{tag.name} is:sfw -animated -6+girls -comic"
|
||||
end
|
||||
|
||||
Post.system_tag_match(search).limit(500).sort_by(&:score).last
|
||||
|
||||
@@ -189,12 +189,12 @@ class PostQuery
|
||||
TagAlias.aliases_for(tag_names)
|
||||
end
|
||||
|
||||
# Implicit metatags are metatags added by the user's account settings. rating:s is implicit under safe mode.
|
||||
# Implicit metatags are metatags added by the user's account settings. rating:g,s is implicit under safe mode.
|
||||
def implicit_metatags
|
||||
return [] unless safe_mode?
|
||||
|
||||
tags = Danbooru.config.safe_mode_restricted_tags.map { |tag| -AST.tag(tag) }
|
||||
[AST.metatag("rating", "s"), *tags]
|
||||
[AST.metatag("rating", "g,s"), *tags]
|
||||
end
|
||||
|
||||
# XXX unify with PostSets::Post#show_deleted?
|
||||
|
||||
@@ -11,11 +11,18 @@ class Post < ApplicationRecord
|
||||
RESTRICTED_TAGS_REGEX = /(?:^| )(?:#{Danbooru.config.restricted_tags.join("|")})(?:$| )/o
|
||||
|
||||
RATINGS = {
|
||||
s: "Safe",
|
||||
g: "General",
|
||||
s: "Sensitive",
|
||||
q: "Questionable",
|
||||
e: "Explicit",
|
||||
}.with_indifferent_access
|
||||
|
||||
RATING_ALIASES = {
|
||||
safe: ["s"],
|
||||
nsfw: ["q", "e"],
|
||||
sfw: ["g", "s"],
|
||||
}.with_indifferent_access
|
||||
|
||||
deletable
|
||||
has_bit_flags %w[has_embedded_notes _unused_has_cropped is_taken_down]
|
||||
|
||||
@@ -1064,16 +1071,14 @@ class Post < ApplicationRecord
|
||||
where(has_children: true)
|
||||
when "child"
|
||||
where.not(parent: nil)
|
||||
when "sfw"
|
||||
where.not(rating: ["q", "e"])
|
||||
when "nsfw"
|
||||
where(rating: ["q", "e"])
|
||||
when *AutocompleteService::POST_STATUSES
|
||||
status_matches(value, current_user)
|
||||
when *MediaAsset::FILE_TYPES
|
||||
attribute_matches(value, :file_ext, :enum)
|
||||
when *Post::RATINGS.values.map(&:downcase)
|
||||
rating_matches(value)
|
||||
when *Post::RATING_ALIASES.keys
|
||||
where(rating: Post::RATING_ALIASES.fetch(value.downcase))
|
||||
else
|
||||
none
|
||||
end
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<video:publication_date><%= post.created_at.iso8601 %></video:publication_date>
|
||||
<video:title><%= "Post ##{post.id}" %></video:title>
|
||||
<video:description><%= post.tag_string %></video:description>
|
||||
<video:family_friendly><%= post.rating == "s" ? "yes" : "no" %></video:family_friendly>
|
||||
<video:family_friendly><%= post.rating == "g" ? "yes" : "no" %></video:family_friendly>
|
||||
</video:video>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
<%= f.input :old_source, as: :hidden, input_html: { value: post.source } %>
|
||||
<%= f.input :old_rating, as: :hidden, input_html: { value: post.rating } %>
|
||||
|
||||
<%= f.input :rating, collection: Post::RATINGS.invert.reverse_each.to_h, as: :radio_buttons, boolean_style: :inline %>
|
||||
<%= f.input :rating, label: "Rating (#{link_to_wiki "?", "howto:rate"})".html_safe, collection: Post::RATINGS.invert.reverse_each.to_h, as: :radio_buttons, boolean_style: :inline %>
|
||||
|
||||
<fieldset class="inline-fieldset post_has_embedded_notes_fieldset">
|
||||
<label>Notes</label>
|
||||
|
||||
@@ -46,7 +46,7 @@
|
||||
<%= hidden_field_tag :upload_media_asset_id, upload_media_asset.id %>
|
||||
|
||||
<%= f.input :source, as: :string, input_html: { value: post.source } %>
|
||||
<%= f.input :rating, collection: Post::RATINGS.invert.reverse_each.to_h, as: :radio_buttons, selected: post.rating %>
|
||||
<%= f.input :rating, label: "Rating (#{link_to_wiki "?", "howto:rate"})".html_safe, collection: Post::RATINGS.invert.reverse_each.to_h, as: :radio_buttons, selected: post.rating %>
|
||||
<%= f.input :parent_id, label: "Parent ID", as: :string, input_html: { value: post.parent_id } %>
|
||||
|
||||
<div class="input upload_artist_commentary_container">
|
||||
|
||||
@@ -31,8 +31,8 @@ class AutocompleteControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_autocomplete_equals(["azur_lane"], "~azur", "tag_query")
|
||||
assert_autocomplete_equals(["azur_lane"], "AZUR", "tag_query")
|
||||
|
||||
assert_autocomplete_equals(["rating:safe"], "rating:s", "tag_query")
|
||||
assert_autocomplete_equals(["rating:safe"], "-rating:s", "tag_query")
|
||||
assert_autocomplete_equals(["rating:sensitive"], "rating:s", "tag_query")
|
||||
assert_autocomplete_equals(["rating:sensitive"], "-rating:s", "tag_query")
|
||||
end
|
||||
|
||||
should "work for a missing type" do
|
||||
|
||||
@@ -162,7 +162,8 @@ class AutocompleteServiceTest < ActiveSupport::TestCase
|
||||
assert_autocomplete_equals(["parent:active"], "parent:act", :tag_query)
|
||||
assert_autocomplete_equals(["child:active"], "child:act", :tag_query)
|
||||
|
||||
assert_autocomplete_equals(["rating:safe"], "rating:s", :tag_query)
|
||||
assert_autocomplete_equals(["rating:general"], "rating:g", :tag_query)
|
||||
assert_autocomplete_equals(["rating:sensitive"], "rating:s", :tag_query)
|
||||
assert_autocomplete_equals(["rating:questionable"], "rating:q", :tag_query)
|
||||
assert_autocomplete_equals(["rating:explicit"], "rating:e", :tag_query)
|
||||
|
||||
@@ -190,7 +191,8 @@ class AutocompleteServiceTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "match static metatags case-insensitively" do
|
||||
assert_autocomplete_equals(["rating:safe"], "rating:S", :tag_query)
|
||||
assert_autocomplete_equals(["rating:general"], "rating:G", :tag_query)
|
||||
assert_autocomplete_equals(["rating:sensitive"], "rating:S", :tag_query)
|
||||
assert_autocomplete_equals(["rating:questionable"], "rating:Q", :tag_query)
|
||||
assert_autocomplete_equals(["rating:explicit"], "rating:E", :tag_query)
|
||||
end
|
||||
|
||||
@@ -753,15 +753,18 @@ class PostQueryBuilderTest < ActiveSupport::TestCase
|
||||
end
|
||||
|
||||
should "return posts for the is:<rating> metatag" do
|
||||
g = create(:post, rating: "g")
|
||||
s = create(:post, rating: "s")
|
||||
q = create(:post, rating: "q")
|
||||
e = create(:post, rating: "e")
|
||||
all = [e, q, s]
|
||||
all = [e, q, s, g]
|
||||
|
||||
assert_tag_match([g], "is:general")
|
||||
assert_tag_match([s], "is:safe")
|
||||
assert_tag_match([s], "is:sensitive")
|
||||
assert_tag_match([q], "is:questionable")
|
||||
assert_tag_match([e], "is:explicit")
|
||||
assert_tag_match([s], "is:sfw")
|
||||
assert_tag_match([s, g], "is:sfw")
|
||||
assert_tag_match([e, q], "is:nsfw")
|
||||
end
|
||||
|
||||
|
||||
@@ -733,8 +733,35 @@ class PostTest < ActiveSupport::TestCase
|
||||
context "that is valid" do
|
||||
should "update the rating" do
|
||||
@post.update(tag_string: "aaa rating:e")
|
||||
@post.reload
|
||||
assert_equal("e", @post.rating)
|
||||
assert_equal("e", @post.reload.rating)
|
||||
|
||||
@post.update(tag_string: "aaa rating:q")
|
||||
assert_equal("q", @post.reload.rating)
|
||||
|
||||
@post.update(tag_string: "aaa rating:s")
|
||||
assert_equal("s", @post.reload.rating)
|
||||
|
||||
@post.update(tag_string: "aaa rating:g")
|
||||
assert_equal("g", @post.reload.rating)
|
||||
end
|
||||
|
||||
should "update the rating for a long name" do
|
||||
@post.update(tag_string: "aaa rating:explicit")
|
||||
assert_equal("e", @post.reload.rating)
|
||||
|
||||
@post.update(tag_string: "aaa rating:questionable")
|
||||
assert_equal("q", @post.reload.rating)
|
||||
|
||||
@post.update(tag_string: "aaa rating:sensitive")
|
||||
assert_equal("s", @post.reload.rating)
|
||||
|
||||
@post.update(tag_string: "aaa rating:general")
|
||||
assert_equal("g", @post.reload.rating)
|
||||
end
|
||||
|
||||
should "update the rating for rating:safe" do
|
||||
@post.update(tag_string: "aaa rating:safe")
|
||||
assert_equal("s", @post.reload.rating)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1623,8 +1650,8 @@ class PostTest < ActiveSupport::TestCase
|
||||
end
|
||||
end
|
||||
|
||||
should "allow values s, q, e" do
|
||||
["s", "q", "e"].each do |rating|
|
||||
should "allow values g, s, q, e" do
|
||||
["g", "s", "q", "e"].each do |rating|
|
||||
subject.rating = rating
|
||||
assert(subject.valid?)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user