mirror of
https://github.com/internetee/registry.git
synced 2025-06-06 12:47:29 +02:00
Refactor Devise integration
- Use scoped users - Use the named route helpers instead of hardcoded paths
This commit is contained in:
parent
c31f507c25
commit
9684c8e59f
52 changed files with 313 additions and 280 deletions
|
@ -12,63 +12,15 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
|
||||
rescue_from CanCan::AccessDenied do |exception|
|
||||
redirect_to current_root_url, alert: exception.message
|
||||
redirect_to root_url, alert: exception.message
|
||||
end
|
||||
|
||||
helper_method :registrant_request?, :registrar_request?, :admin_request?, :current_root_url
|
||||
helper_method :available_languages
|
||||
|
||||
def registrant_request?
|
||||
request.path.match(/^\/registrant/)
|
||||
end
|
||||
|
||||
def registrar_request?
|
||||
request.path.match(/^\/registrar/)
|
||||
end
|
||||
|
||||
def admin_request?
|
||||
request.path.match(/^\/admin/)
|
||||
end
|
||||
|
||||
def current_root_url
|
||||
if registrar_request?
|
||||
registrar_root_url
|
||||
elsif registrant_request?
|
||||
registrant_login_url
|
||||
elsif admin_request?
|
||||
admin_root_url
|
||||
end
|
||||
end
|
||||
|
||||
def after_sign_in_path_for(_resource)
|
||||
rt = session[:user_return_to].to_s.presence
|
||||
login_paths = [admin_login_path, registrar_login_path, '/login']
|
||||
return rt if rt && !login_paths.include?(rt)
|
||||
current_root_url
|
||||
end
|
||||
|
||||
def after_sign_out_path_for(_resource)
|
||||
if registrar_request?
|
||||
registrar_login_url
|
||||
elsif registrant_request?
|
||||
registrant_login_url
|
||||
elsif admin_request?
|
||||
admin_login_url
|
||||
end
|
||||
end
|
||||
|
||||
def info_for_paper_trail
|
||||
{ uuid: request.uuid }
|
||||
end
|
||||
|
||||
def user_for_paper_trail
|
||||
user_log_str(current_user)
|
||||
end
|
||||
|
||||
def user_log_str(user)
|
||||
user.nil? ? 'public' : user.id_role_username
|
||||
end
|
||||
|
||||
def comma_support_for(parent_key, key)
|
||||
return if params[parent_key].blank?
|
||||
return if params[parent_key][key].blank?
|
||||
|
@ -80,4 +32,8 @@ class ApplicationController < ActionController::Base
|
|||
def available_languages
|
||||
{ en: 'English', et: 'Estonian' }.invert
|
||||
end
|
||||
end
|
||||
|
||||
def user_for_paper_trail
|
||||
current_user.present? ? current_user.id_role_username : 'public'
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue