Skip to content

Commit

Permalink
Make sure that the URL shortening setting returns as "enabled" even w…
Browse files Browse the repository at this point in the history
…hen 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.
  • Loading branch information
caiosba authored Jan 16, 2025
1 parent 4a09b88 commit c115a52
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions app/models/team.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/url_rewriter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions test/models/team_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit c115a52

Please sign in to comment.