README.md in rolypoly-0.2.0 vs README.md in rolypoly-1.0.0
- old
+ new
@@ -17,13 +17,68 @@
```bash
$> bundle
```
-## Usage
+## Custom Usage
```ruby
+role_checker = Rolypoly.define_gatekeepers do
+ allow(:super_duper_admin).to_all
+ allow(:super_admin).on(:organization).to_all
+ allow(:admin).on(:team).to_access(:show, :update)
+end
+
+role_checker_options = {
+ organization: ['Organization', team.organization_id],
+ team: team
+}
+
+role_checker.allow?(role_objects, :destroy, role_checker_options)
+role_checker.allow?(role_objects, :destroy, role_checker_options)
+```
+
+## Policy Usage
+
+```ruby
+class TeamPolicy < Struct.new(:user, :team)
+
+ include Rolypoly::RoleDSL
+
+ allow(:super_duper_admin).to_all
+ allow(:super_admin).on(:organization).to_all
+ allow(:admin).on(:team).to_access(:show, :update)
+
+ def show?
+ allow?(:show)
+ end
+
+ def update?
+ allow?(:update)
+ end
+
+ def destroy?
+ allow?(:destroy)
+ end
+
+ def current_user_roles
+ current_user.role_assignments
+ end
+
+ def rolypoly_resource_map
+ {
+ organization: ['Organization', team.organization_id]
+ team: team
+ }
+ end
+
+end
+```
+
+## Controller Usage
+
+```ruby
class ApplicationController < ActionController::Base
def current_user_roles
current_user.roles
end
@@ -96,24 +151,24 @@
# Allow roles with a resource
`allow_with_resource` acts similarly to `allow` but executes a resource check on the `SomeCustomerRoleObject` to access the endpoint.
This requires a method to be defined on `SomeCustomRoleObject` that checks if the resource is valid for that role.
-The `role_resource` needs to be defined on the controller to pass the resource that the role will be validated against.
-If `role_resource` is not defined it will be defaulted to an empty hash `{}`.
+The `rolypoly_resource_map` needs to be defined on the controller to pass the resources that the role will be validated against.
+If `rolypoly_resource_map` is not defined it will be defaulted to an empty hash `{}`.
```ruby
class SomeCustomRoleObject
def resource?(resource)
self.resources.includes?(resource)
end
end
class ProfilesController < ApplicationController
- allow_with_resource(:admin).to_access(:index)
- allow_with_resource(:owner).to_access(:edit)
+ allow(:admin).on(:organization).to_access(:index)
+ allow(:owner).on(:profile).to_access(:edit)
publicize(:show)
def index
current_roles # => [#<SomeCustomRoleObject to_role_string: "admin", resource?: true >]
end
@@ -128,11 +183,14 @@
private def current_user_roles
current_user.roles # => [#<SomeCustomRoleObject to_role_string: "admin", resource?: true>, #<SomeCustomRoleObject to_role_string: "scorekeeper", resource?: false>]
end
- private def role_resource
- { resource: params[:resource_id] }
+ private def rolypoly_resource_map
+ {
+ organization: ['Organization', tournament.org_id]
+ tournament: tournament
+ }
end
end
```
## Contributing