Allow a configurable delay to keep diary entries from being published in feeds

This is to provide another tool to help spam fighting.

The configuration value is set to zero hours for new deploys in
order to be 'least surprising'. You can change the setting without
interfering with your test suite.
This commit is contained in:
Andy Allan 2019-05-29 16:56:15 +02:00
parent 21bf5d79d6
commit 6ed749e7eb
4 changed files with 29 additions and 1 deletions

View file

@ -166,6 +166,10 @@ class DiaryEntriesController < ApplicationController
else else
@entries = DiaryEntry.joins(:user).where(:users => { :status => %w[active confirmed] }) @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] if params[:language]
@entries = @entries.where(:language_code => params[:language]) @entries = @entries.where(:language_code => params[:language])
@title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name) @title = t("diary_entries.feed.language.title", :language_name => Language.find(params[:language]).english_name)
@ -177,7 +181,6 @@ class DiaryEntriesController < ApplicationController
@link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol @link = url_for :action => "index", :host => Settings.server_url, :protocol => Settings.server_protocol
end end
end end
@entries = @entries.visible.includes(:user).order("created_at DESC").limit(20) @entries = @entries.visible.includes(:user).order("created_at DESC").limit(20)
end end

View file

@ -57,6 +57,8 @@ nearby_users: 30
nearby_radius: 50 nearby_radius: 50
# Spam threshold # Spam threshold
spam_threshold: 50 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 (jurisdiction location) for contributor terms
default_legale: GB default_legale: GB
# Use the built-in jobs queue for importing traces # Use the built-in jobs queue for importing traces

View file

@ -1,6 +1,8 @@
# Trace directories for testing # Trace directories for testing
gpx_trace_dir: <%= Rails.root.join("test", "gpx", "traces") %> gpx_trace_dir: <%= Rails.root.join("test", "gpx", "traces") %>
gpx_image_dir: <%= Rails.root.join("test", "gpx", "images") %> 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 credentials for testing
geonames_username: "dummy" geonames_username: "dummy"
# External authentication credentials for testing # External authentication credentials for testing

View file

@ -664,6 +664,18 @@ class DiaryEntriesControllerTest < ActionController::TestCase
assert_match "<title>&lt;script&gt;</title>", response.body assert_match "<title>&lt;script&gt;</title>", response.body
end 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 def test_show
user = create(:user) user = create(:user)
suspended_user = create(:user, :suspended) 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}" assert_select "a[href=?]", "/user/#{ERB::Util.u(entry.user.display_name)}/diary/#{entry.id}"
end end
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 end