Module: Kadmin::Concerns::AuthorizedUser

Extended by:
ActiveSupport::Concern
Included in:
ApplicationController
Defined in:
app/controllers/kadmin/concerns/authorized_user.rb

before_action collapse

View Helpers collapse

Helpers collapse

Instance Method Details

#authorizeObject

Add as a before_action whenever you wish to authorize a user for a particular resource. The app provided user model will perform authorization of the resource.

Examples:

before_action :authorize, except: [:index] # exclude index from authorization

See Also:



22
23
24
25
26
27
28
29
30
31
32
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 22

def authorize
  if Kadmin::Auth.config.enabled?
    if logged_in?
      unless authorized?
        redirect_to Kadmin::Engine.routes.url_helpers.auth_unauthorized_path
      end
    else
      redirect_to Kadmin::Engine.routes.url_helpers.(origin: request.path)
    end
  end
end

#authorized?Boolean

Returns true if the user is authorized in, false otherwise

Returns:

  • (Boolean)

    true if the user is authorized in, false otherwise

See Also:



60
61
62
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 60

def authorized?
  return authorized_user&.authorized?(request)
end

#authorized_userKadmin::Auth::User

Returns instance of the user identified by current_user

Returns:

See Also:



45
46
47
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 45

def authorized_user
  return Kadmin::Auth.users.get(current_user)
end

#current_userString

Returns the current user identifier. Historically called current_user

Returns:

  • (String)

    the current user identifier. Historically called current_user



39
40
41
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 39

def current_user
  session[Kadmin::AuthController::SESSION_KEY]
end

#logged_in?Boolean

Returns true if the user is logged in, false otherwise

Returns:

  • (Boolean)

    true if the user is logged in, false otherwise



54
55
56
# File 'app/controllers/kadmin/concerns/authorized_user.rb', line 54

def logged_in?
  return current_user.present?
end