Sha256: 9f69bdf396271a17ffa78b8303193dc8d46ec3bbb0342b460001171607034a7b

Contents?: true

Size: 322 Bytes

Versions: 39

Compression:

Stored size: 322 Bytes

Contents

module PandaCms
  class AdminConstraint
    def initialize(&block)
      @block = block
    end

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

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

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
panda_cms-0.6.3 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.6.2 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.6.1 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.6.0 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.10 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.9 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.8 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.7 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.6 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.5 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.4 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.3 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.2 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.1 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.5.0 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.3.15 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.3.14 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.3.13 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.3.12 app/constraints/panda_cms/admin_constraint.rb
panda_cms-0.3.11 app/constraints/panda_cms/admin_constraint.rb