Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Able to access protected controller actions #36

Closed
hippobyte opened this issue Feb 18, 2017 · 2 comments
Closed

Able to access protected controller actions #36

hippobyte opened this issue Feb 18, 2017 · 2 comments

Comments

@hippobyte
Copy link

hippobyte commented Feb 18, 2017

This means that you define what the user can do, which results in clean, readable policies regardless of application complexity. You don't have to worry about juggling cans and cannots in a very convoluted way!

Based on the README, my understanding is that access to controller actions should raise an error if not specified in access_policy.rb. That doesn't seem to be the case in my example. I am setting current_user when User has not logged in yet and assigning a role = 'locked'.

Based on access_policy.rb, a user with a role of 'locked' should only be able to read from one specific action, however, in my example the user is allowed to perform any action, it appears that the application_policy is not being applied to this new user, not sure why.

Yes, I am specifying authorize! in each controller action.

application_controller.rb

def current_user
  super || User.new
end

user.rb

after_initialize :set_default_role, :if => :new_record?

def set_default_role   
  self.role ||= 'locked'
end

access_policy.rb

class AccessPolicy
  include AccessGranted::Policy

  def configure

    role :superhero do
      can :manage, Company
      can :index, Company
      can :manage, Event
    end

    role :admin do
      can :manage, User
      can :manage, App
      can :manage, Event
    end

    role :member do
      can :index, App
      can :index, User
      can :index, Event
    end

    role :locked do
      can :read, @page
    end

  end
end
@hippobyte
Copy link
Author

My mistake, I didn't include the matcher.

role :locked, { role: 'locked' } do
  can :read, @page
end

@pokonski
Copy link
Contributor

Glad you got it sorted 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants