The future parameter uses "has_scope".

Plus no more than 3000 events can be lister at most.
remotes/origin/master
echarp 4 years ago
parent 0ad35f1fb7
commit 76f0a33145
  1. 25
      app/controllers/events_controller.rb

@ -3,6 +3,7 @@
class EventsController < ApplicationController
has_scope :region, :locality, :tag, :daylimit, :year
has_scope :near, type: :hash, using: %i[location distance]
has_scope :future, type: :boolean, default: true, only: [:index], if: :future?
before_action :set_events, only: :index
before_action :set_event, except: %i[index new preview_create create]
@ -14,9 +15,9 @@ class EventsController < ApplicationController
def index
respond_to do |format|
format.html
format.ics { @events = @events.future }
format.json { @events = @events.future }
format.rss { @events = filter_for_rss }
format.ics
format.json
format.rss
format.xml
end
end
@ -83,7 +84,9 @@ class EventsController < ApplicationController
private
def set_events
@events = apply_scopes Event.moderated
# The 3000 limit is purely arbitrary...
@events = apply_scopes Event.moderated.order('id desc')
.limit(params[:format] == 'rss' ? 20 : 3000)
end
# Use callbacks to share common setup or constraints between actions
@ -110,14 +113,6 @@ class EventsController < ApplicationController
:locality, :url, :contact, :submitter, :tag_list
end
def filter_for_rss
if params[:future] == 'false'
@events.order 'id desc'
else
@events.future.order('id desc').limit 20
end
end
def locked
redirect_to edit_event_url(@event, secret: @event.secret),
alert: t('staleObjectError')
@ -128,4 +123,10 @@ class EventsController < ApplicationController
redirect_to :root, alert: t(:forbidden, scope: %i[events edit]) \
unless params[:secret] == @event.secret
end
# Should the future scope be applied?
# Only on non html pages...
def future?
params[:format].present? && params[:format] != 'html'
end
end

Loading…
Cancel
Save