Merge remote-tracking branch 'upstream/pull/2239'
authorTom Hughes <tom@compton.nu>
Wed, 29 May 2019 16:41:08 +0000 (17:41 +0100)
committerTom Hughes <tom@compton.nu>
Wed, 29 May 2019 16:41:08 +0000 (17:41 +0100)
app/controllers/diary_entries_controller.rb
config/settings.yml
config/settings/test.yml
test/controllers/diary_entries_controller_test.rb

index f02f4224f5c458d0713c344dd94e0cbc433fd3fe..1e113e09f8df406a36473be4b5b281019af044ae 100644 (file)
@@ -180,6 +180,10 @@ class DiaryEntriesController < ApplicationController
     else
       @entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] })
 
+      # Items can't be flagged as deleted in the RSS format.
+      # For the general feeds, allow a delay before publishing, to help spam fighting
+      @entries = @entries.where("created_at < :time", :time => Settings.diary_feed_delay.hours.ago)
+
       if params[:language]
         @entries = @entries.where(:language_code => params[:language])
         @title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name)
@@ -191,7 +195,6 @@ class DiaryEntriesController < ApplicationController
         @link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol
       end
     end
-
     @entries = @entries.visible.includes(:user).order("created_at DESC").limit(20)
   end
 
index 6031f06547f91406e9b607a0613561ced31dfd37..51d3ed2c9e1f792949e1eb47bf8e2308063863a1 100644 (file)
@@ -57,6 +57,8 @@ nearby_users: 30
 nearby_radius: 50
 # Spam threshold
 spam_threshold: 50
+# Delay diary entries from appearing in the feed for this many hours
+diary_feed_delay: 0
 # Default legale (jurisdiction location) for contributor terms
 default_legale: GB
 # Use the built-in jobs queue for importing traces
index 022c9324633250247b2088d66b1d7853c973998f..e9a506c414fc1b4ce5a8676934e33456efa72399 100644 (file)
@@ -1,6 +1,8 @@
 # Trace directories for testing
 gpx_trace_dir: <%= Rails.root.join("test", "gpx", "traces") %>
 gpx_image_dir: <%= Rails.root.join("test", "gpx", "images") %>
+# Ignore the diary feed delay unless we're specifically testing it
+diary_feed_delay: 0
 # Geonames credentials for testing
 geonames_username: "dummy"
 # External authentication credentials for testing
index 88a67ef1214a36b28bd67565874be57bef41747f..71684c65e74366e8235010b6ba1504f479f6abee 100644 (file)
@@ -664,6 +664,18 @@ class DiaryEntriesControllerTest < ActionController::TestCase
     assert_match "<title>&lt;script&gt;</title>", response.body
   end
 
+  def test_feed_delay
+    create(:diary_entry, :created_at => 7.hours.ago)
+    create(:diary_entry, :created_at => 5.hours.ago)
+    get :rss, :params => { :format => :rss }
+    assert_select "rss>channel>item", :count => 2
+
+    with_diary_feed_delay(6) do
+      get :rss, :params => { :format => :rss }
+      assert_select "rss>channel>item", :count => 1
+    end
+  end
+
   def test_show
     user = create(:user)
     suspended_user = create(:user, :suspended)
@@ -897,4 +909,13 @@ class DiaryEntriesControllerTest < ActionController::TestCase
       assert_select "a[href=?]", "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}"
     end
   end
+
+  def with_diary_feed_delay(value)
+    diary_feed_delay = Settings.diary_feed_delay
+    Settings.diary_feed_delay = value
+
+    yield
+
+    Settings.diary_feed_delay = diary_feed_delay
+  end
 end