2013-01-07 09:04:09 +01:00
|
|
|
class ApplicationController < ActionController::Base
|
2016-05-18 20:17:35 +05:30
|
|
|
before_filter :set_paper_trail_whodunnit
|
2013-01-07 09:04:09 +01:00
|
|
|
include ApplicationHelper
|
2016-03-10 14:25:38 +05:30
|
|
|
add_flash_types :error
|
2015-12-08 16:05:29 +01:00
|
|
|
protect_from_forgery with: :exception
|
2013-06-27 16:58:20 +02:00
|
|
|
before_filter :get_conferences
|
2013-08-25 13:40:44 +03:00
|
|
|
before_filter :store_location
|
2014-08-12 11:51:59 +03:00
|
|
|
# Ensure every controller authorizes resource or skips authorization (skip_authorization_check)
|
|
|
|
|
check_authorization unless: :devise_controller?
|
2013-08-25 13:40:44 +03:00
|
|
|
|
|
|
|
|
def store_location
|
2014-11-04 17:42:47 +01:00
|
|
|
# store last url - this is needed for post-login redirect to whatever the user last visited.
|
|
|
|
|
return unless request.get?
|
|
|
|
|
if (request.path != '/accounts/sign_in' &&
|
|
|
|
|
request.path != '/accounts/sign_up' &&
|
|
|
|
|
request.path != '/accounts/password/new' &&
|
|
|
|
|
request.path != '/accounts/password/edit' &&
|
|
|
|
|
request.path != '/accounts/confirmation' &&
|
|
|
|
|
request.path != '/accounts/sign_out' &&
|
|
|
|
|
request.path != '/users/ichain_registration/ichain_sign_up' &&
|
|
|
|
|
!request.path.starts_with?(Devise.ichain_base_url) &&
|
|
|
|
|
!request.xhr?) # don't store ajax calls
|
|
|
|
|
session[:return_to] = request.fullpath
|
|
|
|
|
end
|
2013-08-25 13:40:44 +03:00
|
|
|
end
|
|
|
|
|
|
2014-11-04 17:42:47 +01:00
|
|
|
def after_sign_in_path_for(_resource)
|
2014-08-12 11:51:59 +03:00
|
|
|
if (can? :view, Conference) &&
|
2014-05-23 17:05:19 +02:00
|
|
|
(!session[:return_to] ||
|
|
|
|
|
session[:return_to] &&
|
|
|
|
|
session[:return_to] == root_path)
|
2016-09-14 22:42:04 -04:00
|
|
|
admin_conferences_path
|
2014-03-24 12:45:04 +01:00
|
|
|
else
|
2014-11-04 17:42:47 +01:00
|
|
|
session[:return_to] || root_path
|
2014-03-24 12:45:04 +01:00
|
|
|
end
|
2013-08-25 13:40:44 +03:00
|
|
|
end
|
2013-06-27 16:58:20 +02:00
|
|
|
|
|
|
|
|
def get_conferences
|
2017-02-01 20:47:35 +05:30
|
|
|
@conferences = Conference.all
|
2013-06-27 16:58:20 +02:00
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
|
2014-08-12 11:51:59 +03:00
|
|
|
def current_ability
|
|
|
|
|
@current_ability ||= Ability.new(current_user)
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
rescue_from CanCan::AccessDenied do |exception|
|
2015-03-12 23:53:57 +01:00
|
|
|
Rails.logger.debug "Access denied on #{exception.action} #{exception.subject.inspect}"
|
2015-04-23 11:50:22 +02:00
|
|
|
message = exception.message
|
2016-08-06 00:57:07 +02:00
|
|
|
message << ' Maybe you need to sign in?' unless current_user
|
2015-04-23 11:50:22 +02:00
|
|
|
redirect_to root_path, alert: message
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|
2014-06-17 00:47:49 +05:30
|
|
|
|
2014-11-04 17:42:47 +01:00
|
|
|
rescue_from IChainRecordNotFound do
|
|
|
|
|
Rails.logger.debug('IChain Record was not Unique!')
|
|
|
|
|
sign_out(current_user)
|
2016-03-10 14:25:38 +05:30
|
|
|
redirect_to root_path,
|
|
|
|
|
error: 'Your E-Mail adress is already registered at OSEM. Please contact the admin if you want to attach your openSUSE Account to OSEM!'
|
2014-11-04 17:42:47 +01:00
|
|
|
end
|
|
|
|
|
|
2014-11-06 16:17:11 +01:00
|
|
|
rescue_from UserDisabled do
|
|
|
|
|
Rails.logger.debug('User is disabled!')
|
|
|
|
|
sign_out(current_user)
|
|
|
|
|
mail = User.admin.first ? User.admin.first.email : 'the admin!'
|
2016-03-10 14:25:38 +05:30
|
|
|
redirect_to User.ichain_logout_url, error: "This User is disabled. Please contact #{mail}!"
|
2014-11-06 16:17:11 +01:00
|
|
|
end
|
|
|
|
|
|
2014-06-17 00:47:49 +05:30
|
|
|
def not_found
|
|
|
|
|
raise ActionController::RoutingError.new('Not Found')
|
|
|
|
|
end
|
2013-01-07 09:04:09 +01:00
|
|
|
end
|