before_filter :fetch_body
- if STATUS == :database_readonly or STATUS == :database_offline
- def self.cache_sweeper(*sweepers)
- end
- end
-
def authorize_web
if session[:user]
@user = User.where(:id => session[:user]).where("status IN ('active', 'confirmed', 'suspended')").first
render :action => "timeout"
end
- ##
- # extend caches_action to include the parameters, locale and logged in
- # status in all cache keys
- def self.caches_action(*actions)
- options = actions.extract_options!
- cache_path = options[:cache_path] || Hash.new
-
- options[:unless] = case options[:unless]
- when NilClass then Array.new
- when Array then options[:unless]
- else unlessp = [ options[:unless] ]
- end
-
- options[:unless].push(Proc.new do |controller|
- controller.params.include?(:page)
- end)
-
- options[:cache_path] = Proc.new do |controller|
- cache_path.merge(controller.params).merge(:host => SERVER_URL, :locale => I18n.locale)
- end
-
- actions.push(options)
-
- super *actions
- end
-
- ##
- # extend expire_action to expire all variants
- def expire_action(options = {})
- I18n.available_locales.each do |locale|
- super options.merge(:host => SERVER_URL, :locale => locale)
- end
- end
-
##
# is the requestor logged in?
def logged_in?
before_filter :check_database_writable, :only => [:new, :edit]
before_filter :require_administrator, :only => [:hide, :hidecomment]
-# caches_action :list, :layout => false, :unless => :user_specific_list?
- caches_action :rss, :layout => true
-# caches_action :view, :layout => false
- cache_sweeper :diary_sweeper, :only => [:new, :edit, :comment, :hide, :hidecomment]
-
def new
@title = t 'diary_entry.new.title'
before_filter :offline_redirect, :only => [:create, :edit, :delete, :data, :api_create, :api_delete, :api_data]
around_filter :api_call_handle_error, :only => [:api_create, :api_read, :api_update, :api_delete, :api_data]
-# caches_action :list, :unless => :logged_in?, :layout => false
-# caches_action :view, :layout => false
- caches_action :georss, :layout => true
- cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create, :api_update, :api_delete]
- cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create, :api_update, :api_delete]
-
# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
def list
before_filter :lookup_user_by_id, :only => [:api_read]
before_filter :lookup_user_by_name, :only => [:set_status, :delete]
- cache_sweeper :user_sweeper, :only => [:account, :set_status, :delete]
-
def terms
@legale = params[:legale] || OSM.IPToCountry(request.remote_ip) || DEFAULT_LEGALE
@text = OSM.legal_text_for_country(@legale)
+++ /dev/null
-class DiarySweeper < ActionController::Caching::Sweeper
- observe DiaryComment, DiaryEntry
-
- def after_create(record)
- expire_cache_for(record)
- end
-
- def after_update(record)
- expire_cache_for(record)
- end
-
- def after_destroy(record)
- expire_cache_for(record)
- end
-
-private
-
- def expire_cache_for(record)
- case
- when record.is_a?(DiaryEntry) then entry = record
- when record.is_a?(DiaryComment) then entry = record.diary_entry
- end
-
- expire_action(:controller => 'diary_entry', :action => 'view', :display_name => entry.user.display_name, :id => entry.id)
-
- expire_action(:controller => 'diary_entry', :action => 'list', :language => nil, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'list', :language => entry.language_code, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'list', :language => nil, :display_name => entry.user.display_name)
-
- expire_action(:controller => 'diary_entry', :action => 'rss', :format => :rss, :language => nil, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'rss', :format => :rss, :language => entry.language_code, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'rss', :format => :rss, :language => nil, :display_name => entry.user.display_name)
-
- if record.is_a?(DiaryEntry)
- expire_fragment(:controller => 'diary_entry', :action => 'view', :display_name => entry.user.display_name, :id => entry.id, :part => "location")
- end
- end
-end
+++ /dev/null
-class TraceSweeper < ActionController::Caching::Sweeper
- observe Trace
-
- def after_create(record)
- expire_cache_for(record)
- end
-
- def after_update(record)
- expire_cache_for(record)
- end
-
- def after_destroy(record)
- expire_cache_for(record)
- end
-
-private
-
- def expire_cache_for(record)
- expire_action(:controller => 'trace', :action => 'view', :display_name => record.user.display_name, :id => record.id)
-
- expire_action(:controller => 'trace', :action => 'list', :display_name => nil, :tag => nil)
- expire_action(:controller => 'trace', :action => 'list', :display_name => record.user.display_name, :tag => nil)
-
- expire_action(:controller => 'trace', :action => 'georss', :display_name => nil, :tag => nil)
- expire_action(:controller => 'trace', :action => 'georss', :display_name => record.user.display_name, :tag => nil)
- end
-end
+++ /dev/null
-class TracetagSweeper < ActionController::Caching::Sweeper
- observe Tracetag
-
- def after_create(record)
- expire_cache_for(record)
- end
-
- def after_update(record)
- expire_cache_for(record)
- end
-
- def after_destroy(record)
- expire_cache_for(record)
- end
-
-private
-
- def expire_cache_for(record)
- expire_action(:controller => 'trace', :action => 'list', :display_name => nil, :tag => record.tag)
- expire_action(:controller => 'trace', :action => 'list', :display_name => record.trace.user.display_name, :tag => record.tag)
-
- expire_action(:controller => 'trace', :action => 'georss', :display_name => nil, :tag => record.tag)
- expire_action(:controller => 'trace', :action => 'georss', :display_name => record.trace.user.display_name, :tag => record.tag)
- end
-end
+++ /dev/null
-class UserSweeper < ActionController::Caching::Sweeper
- observe User
-
- def before_update(record)
- expire_cache_for(User.find(record.id), record)
- end
-
- def before_destroy(record)
- expire_cache_for(record, nil)
- end
-
-private
-
- def expire_cache_for(old_record, new_record)
- if old_record and
- (new_record.nil? or
- old_record.visible? != new_record.visible? or
- old_record.display_name != new_record.display_name or
- old_record.image.fingerprint != new_record.image.fingerprint)
- old_record.diary_entries.each do |entry|
- expire_action(:controller => 'diary_entry', :action => 'view', :display_name => old_record.display_name, :id => entry.id)
- expire_action(:controller => 'diary_entry', :action => 'list', :language => entry.language_code, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'rss', :format => :rss, :language => entry.language_code, :display_name => nil)
- end
-
- old_record.diary_comments.each do |comment|
- expire_action(:controller => 'diary_entry', :action => 'view', :display_name => comment.diary_entry.user.display_name, :id => comment.diary_entry.id)
- end
-
- expire_action(:controller => 'diary_entry', :action => 'list', :language => nil, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'list', :language => nil, :display_name => old_record.display_name)
-
- expire_action(:controller => 'diary_entry', :action => 'rss', :format => :rss, :language => nil, :display_name => nil)
- expire_action(:controller => 'diary_entry', :action => 'rss', :format => :rss, :language => nil, :display_name => old_record.display_name)
-
- old_record.traces.each do |trace|
- expire_action(:controller => 'trace', :action => 'view', :display_name => old_record.display_name, :id => trace.id)
-
- trace.tags.each do |tag|
- expire_action(:controller => 'trace', :action => 'list', :display_name => nil, :tag => tag.tag)
- expire_action(:controller => 'trace', :action => 'list', :display_name => old_record.display_name, :tag => tag.tag)
-
- expire_action(:controller => 'trace', :action => 'georss', :display_name => nil, :tag => tag.tag)
- expire_action(:controller => 'trace', :action => 'georss', :display_name => old_record.display_name, :tag => tag.tag)
- end
- end
-
- expire_action(:controller => 'trace', :action => 'list', :display_name => nil, :tag => nil)
- expire_action(:controller => 'trace', :action => 'list', :display_name => old_record.display_name, :tag => nil)
-
- expire_action(:controller => 'trace', :action => 'georss', :display_name => nil, :tag => nil)
- expire_action(:controller => 'trace', :action => 'georss', :display_name => old_record.display_name, :tag => nil)
- end
- end
-end