Class: AccessPolicy

Inherits:
Object
  • Object
show all
Includes:
AccessGranted::Policy
Defined in:
lib/generators/templates/access_policy.rb

Instance Attribute Summary

Attributes included from AccessGranted::Policy

#cache, #roles, #user

Instance Method Summary collapse

Methods included from AccessGranted::Policy

#authorize!, #can?, #cannot?, #check_permission, #initialize, #role

Instance Method Details

#configureObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/generators/templates/access_policy.rb', line 4

def configure
  # Example policy for AccessGranted.
  # For more details check the README at
  #
  # https://github.com/chaps-io/access-granted/blob/master/README.md
  #
  # Roles inherit from less important roles, so:
  # - :admin has permissions defined in :member, :guest and himself
  # - :member has permissions from :guest and himself
  # - :guest has only its own permissions since it's the first role.
  #
  # The most important role should be at the top.
  # In this case an administrator.
  #
  # role :admin, proc { |user| user.admin? } do
  #   can :destroy, User
  # end

  # More privileged role, applies to registered users.
  #
  # role :member, proc { |user| user.registered? } do
  #   can :create, Post
  #   can :create, Comment
  #   can [:update, :destroy], Post do |post, user|
  #     post.author == user
  #   end
  # end

  # The base role with no additional conditions.
  # Applies to every user.
  #
  # role :guest do
  #  can :read, Post
  #  can :read, Comment
  # end
end