README.markdown in permissive-0.0.0 vs README.markdown in permissive-0.0.1
- old
+ new
@@ -11,11 +11,11 @@
1. Get yourself some code. You can install as a gem:
`gem install permissive`
or as a plugin:
-
+
`script/plugin install git://github.com/flipsasser/permissive.git`
2. Generate a migration so you can get some sweet table action:
`script/generate permissive_migration`
@@ -28,24 +28,24 @@
First, define a few permissions constants. We'll define them in `Rails.root/config/initializers/permissive.rb`. The best practice is to name them in a verb format that follows this pattern: "Object can `DO_PERMISSION_NAME`".
Permission constants need to be int values counting up from zero. We use ints because Permissive uses bit masking to keep permissions data compact and performant.
module Permissive::Permissions
- MANAGE_GAMES = 0
- CONTROL_RIDES = 1
- PUNCH = 2
+ MANAGE_GAMES = 0
+ CONTROL_RIDES = 1
+ PUNCH = 2
end
And that's all it takes to configure permissions! Now that we have them, let's grant them to a model or two:
class Employee < ActiveRecord::Base
- acts_as_permissive
- validates_presence_of :first_name, :last_name
+ acts_as_permissive
+ validates_presence_of :first_name, :last_name
end
class Company < ActiveRecord::Base
- validates_presence_of :name
+ validates_presence_of :name
end
Easy-peasy, right? Let's try granting a few permissions:
@james = Employee.create(:first_name => 'James', :last_name => 'Brennan')
@@ -96,11 +96,11 @@
-
Permissive supports scoping at the class-configuration level, which adds relationships to permitted objects:
class Employee < ActiveRecord::Base
- acts_as_permissive :scope => :company
+ acts_as_permissive :scope => :company
end
@frigo.permissive_companies #=> [Company 1, Company 2]
Replacing Permissions
@@ -114,14 +114,14 @@
-
There's a number of things I want to add to the permissive settings. At the moment, Permissive currently support scoping at the class level, BUT all it really does is add a `has_many` relationship. `@employee.can!(:do_anything)` will still work, as will `@employee.can!(:do_something, :on => @something_that_isnt_a_company)`. That's pretty confusing to me. Adding more granular permissions might be cooler:
class Employee < ActiveRecord::Base
- has_permissions do
- on :companies
- on :employees
- end
+ has_permissions do
+ on :companies
+ on :employees
+ end
end
which might yield something like
@employee.permissive_companies
@@ -152,14 +152,14 @@
<%= check_box_tag("employee[permissions][]", Permissive::Permissions::CONTROL_RIDES, @employee.can_control_rides?) %> Control rides
.. and in the controller:
def update
- @employee.can!(params[:employees].delete(:permissions), :revert => true)
- respond_to do |format|
- ...
- end
+ @employee.can!(params[:employees].delete(:permissions), :revert => true)
+ respond_to do |format|
+ ...
+ end
end
Finally, I'd like to use the `grant_mask` support that exists on the Permissive::Permission model to control what people can or cannot allow others to do. This would necessitate one of two things - first, a quick way of iterating over a person's granting permissions, e.g.:
<% current_user.grant_permissions.each do |permission| %>
@@ -167,13 +167,13 @@
<% end %>
and second, write-time checking of grantor permissions. Something like this, maybe:
def update
- current_user.grant(params[:employees][:permissions], :to => @employee)
+ current_user.grant(params[:employees][:permissions], :to => @employee)
end
which would allow the Permissive::Permission model to make sure whatever `current_user` is granting to @employee, they're **allowed** to grant to @employee.
And that's it! Like all of my projects, I extracted it from some live development - which means it, too, is still in development. So please feel free to contribute!
-Copyright (c) 2009 Flip Sasser, released under the MIT license
+Copyright (c) 2009 Flip Sasser & Simon Parsons, released under the MIT license
\ No newline at end of file