Module: EgovUtils::UserUtils::ApplicationControllerPatch

Extended by:
ActiveSupport::Concern
Defined in:
lib/egov_utils/user_utils/application_controller_patch.rb

Instance Method Summary collapse

Instance Method Details

#current_userObject



28
29
30
# 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) ⇒ Object



65
66
67
# 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) ⇒ Object



69
70
71
# 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?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/egov_utils/user_utils/application_controller_patch.rb', line 24

def internal_network?
  request.host.ends_with? 'servis.justice.cz'
end

#mailer_hostObject



32
33
34
# 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) ⇒ Object



43
44
45
46
47
48
49
# 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) ⇒ Object



57
58
59
60
61
62
63
# 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) ⇒ Object



51
52
53
54
55
# 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_setupObject



36
37
38
39
40
41
# 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.} (id=#{User.current.id})(roles=#{User.current.all_role_names.join(',')})" : "anonymous")) if logger
  User.current
end