From c115a52ab695f2f6062d394930f628b87deef6ab Mon Sep 17 00:00:00 2001 From: Caio Almeida <117518+caiosba@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:45:23 -0300 Subject: [PATCH] Make sure that the URL shortening setting returns as "enabled" even when it's not explicitly enabled but there are active RSS newsletters (#2180) Make sure that the URL shortening setting returns as "enabled" even when it's not explicitly enabled but there are active RSS newsletters. Fixes: CV2-5998. --- app/models/team.rb | 4 ++++ lib/url_rewriter.rb | 1 + test/models/team_test.rb | 15 +++++++++++++++ 3 files changed, 20 insertions(+) diff --git a/app/models/team.rb b/app/models/team.rb index 18d0f45f52..f5519b8eea 100644 --- a/app/models/team.rb +++ b/app/models/team.rb @@ -596,6 +596,10 @@ def search_for_similar_articles(query, pm = nil) items end + def get_shorten_outgoing_urls + self.settings.to_h.with_indifferent_access[:shorten_outgoing_urls] || self.tipline_newsletters.where(content_type: 'rss', enabled: true).exists? + end + # private # # Please add private methods to app/models/concerns/team_private.rb diff --git a/lib/url_rewriter.rb b/lib/url_rewriter.rb index 8955a21be0..9f126378e7 100644 --- a/lib/url_rewriter.rb +++ b/lib/url_rewriter.rb @@ -22,6 +22,7 @@ def self.utmize(url, source) def self.shorten_and_utmize_urls(input_text, source = nil, owner = nil) text = input_text + return text if text.blank? # Encode URLs in Arabic which are not detected by the URL extraction methods text = text.gsub(/https?:\/\/[\S]+/) { |url| url =~ /\p{Arabic}/ ? Addressable::URI.escape(url) : url } if input_text =~ /\p{Arabic}/ entities = Twitter::TwitterText::Extractor.extract_urls_with_indices(text, extract_url_without_protocol: true) diff --git a/test/models/team_test.rb b/test/models/team_test.rb index 6635867cd8..c1b8509df9 100644 --- a/test/models/team_test.rb +++ b/test/models/team_test.rb @@ -1300,4 +1300,19 @@ def setup assert_equal 2, t.filtered_fact_checks(trashed: false).count assert_equal 1, t.filtered_fact_checks(trashed: true).count end + + test "should return that URL shortening is enabled if there are active RSS newsletters" do + t = create_team + assert !t.get_shorten_outgoing_urls + t.set_shorten_outgoing_urls = true + t.save! + assert t.get_shorten_outgoing_urls + t.set_shorten_outgoing_urls = false + t.save! + assert !t.get_shorten_outgoing_urls + tn = create_tipline_newsletter team: t, enabled: true, content_type: 'rss', rss_feed_url: random_url + assert t.get_shorten_outgoing_urls + tn.destroy! + assert !t.get_shorten_outgoing_urls + end end