public
Description: Rails plugin for generating role- and association-based permission checks on controllers and ActiveRecord models.
Homepage:
Clone URL: git://github.com/blangenfeld/acts_as_checkpoint.git
100644 64 lines (48 sloc) 1.786 kb
1
2
3
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
ActsAsCheckpoint
================
 
This plugin provides a very simple syntax for setting up complex permissions.
 
Example for Controllers
=======================
 
Role-oriented approach:
 
  class YourController < ApplicationController
   acts_as_checkpoint :get_user_method => :current_user
   controller_allows :administrator, :to => [ :index, :show, :destroy ]
   controller_allows :registered_user, :to => [ :index, :show, :new, :edit, :create, :update ]
   controller_allows :anonymous_user, :to => [ :index, :show ]
  end
 
Action-oriented approach:
 
  class YourController < ApplicationController
   acts_as_checkpoint :get_user_method => :current_user
   controller_allows :index , :by => [ :administrator, :registered_user, :anonymous_user ]
   controller_allows :show , :by => [ :administrator, :registered_user ]
   controller_allows :new , :by => :registered_user
   controller_allows :edit , :by => :registered_user
   controller_allows :create , :by => :registered_user
   controller_allows :update , :by => :registered_user
   controller_allows :destroy, :by => :administrator
  end
 
The two approaches may be interspersed at will... just try not to get confused.
 
Example for Models
==================
 
  class Dog < ActiveRecord::Base
   belongs_to :owner
 
   acts_as_checkpoint
   model_may :eat, :drink, :lick
   model_allows :lick, :by => :self
   model_allows :pet, :by => :owner
  end
 
  class Human < ActiveRecord::Base
   has_many :dogs
 
   acts_as_checkpoint
   model_may :pet
   model_allows :lick, :by => :dogs
  end
 
  human = Human.new
  dog = Dog.new( :owner => human )
 
  human.can_pet?( dog )
  # => true
  dog.can_eat?( human )
  # => false
  dog.can_lick?( human )
  # => true
 
Copyright (c) 2008 Brian Langenfeld, released under the MIT license