Fix #4957: Autotag non-web_source.
Autotag non-web_source on posts that have a non-http:// or https:// URL. Add a fix script to backfill old posts. Syntactically invalid URLs are still considered web sources. For example, `https://google,com` technically isn't a valid URL, but it's not considered a non-web source.
This commit is contained in:
@@ -404,7 +404,7 @@ class Post < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def add_automatic_tags(tags)
|
def add_automatic_tags(tags)
|
||||||
tags -= %w[incredibly_absurdres absurdres highres lowres flash video ugoira animated_gif animated_png exif_rotation non-repeating_animation]
|
tags -= %w[incredibly_absurdres absurdres highres lowres flash video ugoira animated_gif animated_png exif_rotation non-repeating_animation non-web_source]
|
||||||
|
|
||||||
if tags.size >= 30
|
if tags.size >= 30
|
||||||
tags -= ["tagme"]
|
tags -= ["tagme"]
|
||||||
@@ -443,6 +443,10 @@ class Post < ApplicationRecord
|
|||||||
tags << "ugoira"
|
tags << "ugoira"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if source.present? && source !~ %r{\Ahttps?://}i
|
||||||
|
tags << "non-web_source"
|
||||||
|
end
|
||||||
|
|
||||||
# Allow only Flash files to be manually tagged as `animated`; GIFs, PNGs, videos, and ugoiras are automatically tagged.
|
# Allow only Flash files to be manually tagged as `animated`; GIFs, PNGs, videos, and ugoiras are automatically tagged.
|
||||||
tags -= ["animated"] unless is_flash?
|
tags -= ["animated"] unless is_flash?
|
||||||
tags << "animated" if media_asset.is_animated?
|
tags << "animated" if media_asset.is_animated?
|
||||||
|
|||||||
25
script/fixes/089_add_non-web_source_tag.rb
Executable file
25
script/fixes/089_add_non-web_source_tag.rb
Executable file
@@ -0,0 +1,25 @@
|
|||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require_relative "base"
|
||||||
|
|
||||||
|
CurrentUser.scoped(User.system) do
|
||||||
|
Post.system_tag_match("-source:none -source:http://* -source:https://* -non-web_source").find_each do |post|
|
||||||
|
puts "post ##{post.id}: adding non-web_source"
|
||||||
|
post.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
Post.system_tag_match("source:none non-web_source").find_each do |post|
|
||||||
|
puts "post ##{post.id}: removing non-web_source"
|
||||||
|
post.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
Post.system_tag_match("source:http://* non-web_source").find_each do |post|
|
||||||
|
puts "post ##{post.id}: removing non-web_source"
|
||||||
|
post.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
Post.system_tag_match("source:https://* non-web_source").find_each do |post|
|
||||||
|
puts "post ##{post.id}: removing non-web_source"
|
||||||
|
post.save!
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -1046,6 +1046,30 @@ class PostTest < ActiveSupport::TestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
context "a post with a non-web source" do
|
||||||
|
should "automatically add the non-web_source tag" do
|
||||||
|
@post.update!(source: "this was once revealed to me in a dream")
|
||||||
|
@post.save!
|
||||||
|
assert_equal("non-web_source tag1 tag2", @post.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a post with a blank source" do
|
||||||
|
should "remove the non-web_source tag" do
|
||||||
|
@post.update!(source: "", tag_string: "non-web_source")
|
||||||
|
@post.save!
|
||||||
|
assert_equal("tagme", @post.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
context "a post with a https:// source" do
|
||||||
|
should "remove the non-web_source tag" do
|
||||||
|
@post.update!(source: "https://www.google.com", tag_string: "non-web_source")
|
||||||
|
@post.save!
|
||||||
|
assert_equal("tagme", @post.tag_string)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
should "have an array representation of its tags" do
|
should "have an array representation of its tags" do
|
||||||
post = FactoryBot.create(:post)
|
post = FactoryBot.create(:post)
|
||||||
post.reload
|
post.reload
|
||||||
|
|||||||
Reference in New Issue
Block a user