The name `safe_html_with_links` was confusing and could make you think it takes care of making the HTML safe. So I've renamed it in a way that makes it a bit more intuitive that it expects its input to be already sanitized. I've changed `text_with_links` as well so now the two method names complement each other.
28 lines
862 B
Ruby
28 lines
862 B
Ruby
namespace :proposals do
|
|
|
|
desc "Move external_url to description"
|
|
task move_external_url_to_description: :environment do
|
|
include ActionView::Helpers::SanitizeHelper
|
|
include TextWithLinksHelper
|
|
|
|
models = [Proposal, Legislation::Proposal]
|
|
|
|
models.each do |model|
|
|
print "Move external_url to description for #{model}s"
|
|
model.find_each do |resource|
|
|
if resource.external_url.present?
|
|
Globalize.with_locale(I18n.default_locale) do
|
|
new_description = "#{resource.description} <p>#{sanitize_and_auto_link(resource.external_url)}</p>"
|
|
resource.description = new_description
|
|
resource.external_url = ""
|
|
resource.updated_at = Time.current
|
|
resource.save(validate: false)
|
|
print "."
|
|
end
|
|
end
|
|
end
|
|
puts " ✅ "
|
|
end
|
|
end
|
|
end
|