Class: Kadmin::AuthConstraint

Inherits:
Object
  • Object
show all
Includes:
Concerns::AuthorizedUser
Defined in:
app/components/kadmin/auth_constraint.rb

Overview

Glue class so that authentication can be added as route constraints

Instance Method Summary collapse

Methods included from Concerns::AuthorizedUser

#authorize, #authorized?, #authorized_user, #current_user, #logged_in?

Instance Method Details

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


8
9
10
11
12
13
14
# File 'app/components/kadmin/auth_constraint.rb', line 8

def matches?(request)
  return true unless Kadmin::Auth.config.enabled?

  return with(request) do
    logged_in? && authorized?
  end
end

#requestObject



23
24
25
# File 'app/components/kadmin/auth_constraint.rb', line 23

def request
  return @request
end

#sessionObject



27
28
29
# File 'app/components/kadmin/auth_constraint.rb', line 27

def session
  return request.session
end

#with(request) ⇒ Object



16
17
18
19
20
21
# File 'app/components/kadmin/auth_constraint.rb', line 16

def with(request)
  @request = request
  return yield
ensure
  @request = nil
end