Class: PandaCms::AdminConstraint

Inherits:
Object
  • Object
show all
Defined in:
app/constraints/panda_cms/admin_constraint.rb

Instance Method Summary collapse

Constructor Details

#initialize(&block) ⇒ AdminConstraint

Returns a new instance of AdminConstraint.



3
4
5
# File 'app/constraints/panda_cms/admin_constraint.rb', line 3

def initialize(&block)
  @block = block
end

Instance Method Details

#current_user(request) ⇒ Object



12
13
14
# File 'app/constraints/panda_cms/admin_constraint.rb', line 12

def current_user(request)
  User.find_by(id: request.session[:user_id])
end

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'app/constraints/panda_cms/admin_constraint.rb', line 7

def matches?(request)
  user = current_user(request)
  user.present? && user.admin? && @block&.call(user)
end