module EgovUtils::UserUtils::ApplicationControllerPatch
Public Instance Methods
current_user()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 28 def current_user User.current || user_setup end
editable_attributes(model, action=:update)
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 65 def editable_attributes(model, action=:update) EgovUtils::ModelPermissions.build(model, current_ability).editable_attributes(action) end
editable_attributes_for(entity, action=:update)
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 69 def editable_attributes_for(entity, action=:update) EgovUtils::ModelPermissions.build(entity.type, current_ability).editable_attributes_for(entity, action) end
internal_network?()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 24 def internal_network? request.host.ends_with? 'servis.justice.cz' end
mailer_host()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 32 def mailer_host request.protocol + request.host_with_port end
redirect_back(fallback_location:, **args)
click to toggle source
Calls superclass method
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 43 def redirect_back(fallback_location:, **args) if params[:back_url] redirect_to URI.parse(params[:back_url]) else super end end
render_404(exception = nil)
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 57 def render_404(exception = nil) respond_to do |format| format.json { head :not_found, content_type: 'text/html' } format.html { render template: "errors/error_404", error: exception.try('message'), status: 404 } format.js { head :not_found, content_type: 'text/html' } end end
render_modal_js(**options)
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 51 def render_modal_js(**options) @partial_scope = options[:scope] || params[:controller] @action = options[:action] || params[:action] render 'common/modal_action' end
user_setup()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 36 def user_setup # Find the current user User.current = find_current_user || find_kerberos_user || User.anonymous logger.info(" Current user: " + (User.current.logged? ? "#{User.current.login} (id=#{User.current.id})(roles=#{User.current.all_role_names.join(',')})" : "anonymous")) if logger User.current end
Protected Instance Methods
check_password_change()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 143 def check_password_change if current_user.logged? && current_user.must_change_password? respond_to do |format| format.html { flash[:error] = t(:error_password_expired) redirect_to egov_utils.edit_password_path(current_user) } format.json { render json: { error: t(:error_password_expired) }, status: :unauthorized } end end end
find_current_user()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 74 def find_current_user # existing session find_session_user if session[:user_id] end
find_kerberos_user()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 79 def find_kerberos_user return nil unless internal_network? && EgovUtils::AuthSource.kerberos_providers.any? && request.env['HTTP_REMOTE_USER'].present? username = request.env['HTTP_REMOTE_USER'].split('@')[0] logger.info(" Trying kerberos: #{username} from (#{request.env['HTTP_REMOTE_USER']})") if logger attrs = EgovUtils::AuthSource.find_kerberos_user(username) if attrs user = User.active.find_by(login: attrs[:login]) logger.info(" Found kerberos user: #{attrs[:login]} and it is in database") if logger && user logged_user = user user end end
find_session_user()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 93 def find_session_user User.active.find(session[:user_id]) rescue ActiveRecord::RecordNotFound => e nil end
logged_user=(user)
click to toggle source
Sets the logged in user
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 100 def logged_user=(user) reset_session if user && user.is_a?(EgovUtils::User) && user.active? User.current = user start_user_session(user) else User.current = User.anonymous end end
require_login()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 114 def require_login if require_login? && !current_user.logged? # Extract only the basic url parameters on non-GET requests if request.get? url = request.original_url else url = url_for(:controller => params[:controller], :action => params[:action], :id => params[:id], only_path: true) end respond_to do |format| format.html { if request.xhr? head :unauthorized else redirect_to egov_utils.login_path(:back_url => url) end } format.any(:atom, :pdf, :csv) { redirect_to egov_utils.login_path(:back_url => url) } format.xml { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="'+t(:app_abbrev)+'"' } format.js { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="'+t(:app_abbrev)+'"' } format.json { head :unauthorized, 'WWW-Authenticate' => 'Basic realm="'+t(:app_abbrev)+'"' } format.any { head :unauthorized } end return false end true end
require_login?()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 155 def require_login? false end
start_user_session(user)
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 110 def start_user_session(user) session[:user_id] = user.id end
Private Instance Methods
set_locale()
click to toggle source
# File lib/egov_utils/user_utils/application_controller_patch.rb, line 160 def set_locale I18n.default_locale = :cs end