acts_as_authoritah 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,13 +1,111 @@
1
1
  = acts_as_authoritah
2
2
 
3
- In config/environment.rb add
4
- require 'acts_as_authoritah'
3
+ INSTALLATION
5
4
 
6
- ActsAsAuthoritah::AccessRights::FileNotFound - if acl file is not found in the specified location
5
+ gem install acts_as_authoritah
7
6
 
8
- include ActsAsAuthoritah in application.rb
7
+ Rails 2.*
8
+ Add in environemnt.rb
9
+ config.gem 'acts_as_authoritah'
9
10
 
10
- one file is mandatory - default.xls, or specify a :default =>
11
+ Rails 3.*
12
+ Add in Gemfile
13
+ gem 'acts_as_authoritah'
14
+
15
+ = A sample blogging app.
16
+
17
+ - Creating blog posts.
18
+ - Editing blog posts.
19
+ - Commenting on blog posts.
20
+
21
+ A blog post when first created will be in unpublished state. The post can be published later.
22
+
23
+ User Roles and capabilities.
24
+
25
+ - Author
26
+ He can create blog posts
27
+ He can edit posts
28
+ He can view blog posts
29
+ He cannot add comments
30
+ - Registered user (who has signed up and logged-in)
31
+ He can view blog posts
32
+ He can comment on blog posts
33
+ He cannot create blog posts
34
+ He cannot edit blog posts
35
+ - anonymous user
36
+ He can view blog posts
37
+ He cannot add comments
38
+ He cannot create blog posts
39
+ He cannot edit blog posts
40
+ - admin
41
+ unrestricted access to everything.
42
+
43
+
44
+ When post is unpublished
45
+
46
+ - Logged-in user (who has signed up)
47
+ He cannot comment on blog posts
48
+ He cannot view blog posts.
49
+
50
+
51
+ = Getting this done with ActsAsAuthoritah
52
+
53
+ 1. Create an excel sheet (or download a sample https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/default.xls)
54
+ and save it at config/acl/default.xls. When the post is unpublished, there are two rules which are different from the default set of rules.
55
+ We need to add these two rules alone in config/acl/unpublished.xls https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/unpublished.xls
56
+
57
+ 2. Add the following line to your User model (or to whichever is your equivalent of User model)
58
+
59
+ acts_as_authoritah :acl_folder => File.join(RAILS_ROOT,"config","acl")
60
+
61
+ 3. Add 'include ActsAsAuthoritah' in ApplicationController
62
+
63
+ 4. ActsAsAuthoritah needs a wrapper around your 'current_user' method (name may differ based on the authentication system you use), to make it return an empty User object when
64
+ user is not logged in.
65
+
66
+ A sample -
67
+
68
+ def present_user
69
+ current_user.to_s == "false" ? User.new : current_user
70
+ end
71
+
72
+ 5. In your User model, you need to define a 'usertype' method which should return the role of that user (same as in the first row of the spreadsheet).
73
+
74
+ A sample -
75
+
76
+ def usertype(args={})
77
+ return role.name if role
78
+ return "anonymous" if new_record?
79
+ return "registered"
80
+ end
81
+
82
+ Implementation of usertype method can vary, based on the role-system you are following. Just make sure it always returns role of the user (string), which should match with the roles
83
+ specified in the first row of the spreadsheet.
84
+
85
+
86
+ 6. in Post model
87
+
88
+ def status
89
+ published? ? nil : 'unpublished'
90
+ end
91
+
92
+ This will be used to let authoritah know when a post in in unpublished state, so that authoritah can override the default rules with those in unpublished.xls
93
+
94
+ 7. For access control of methods in PostController and CommentController, put these two files in lib/access_control/
95
+ https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/comment_controller_access.rb
96
+ https://github.com/bangthetable/acts_as_authoritah/blob/master/sample/post_controller_access.rb
97
+
98
+ 8. To make sure that links are shown only to appropriate users, add lines like these in in the views.
99
+
100
+ <% if present_user.can_post_a_comment?(:context => @post.status) %>
101
+ <%= link_to 'Add a comment', {:controller => 'comment', :action => 'new', :post_id => @post.id} %>
102
+ <% end%>
103
+
104
+ 9. Thats all - your application is access controlled by ActsAsAuthoritah now.
105
+
106
+ - You can grant/revoke access to different features to different roles just by editing the spreadsheets.
107
+ - You can add a new user-role by adding a column in the spreadsheets.
108
+ - If your application needs to have one more context (say, archived posts), you can do that by adding one more spreadsheet called archived.xls.
11
109
 
12
110
  == Note on Patches/Pull Requests
13
111
 
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{acts_as_authoritah}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["BangTheTable","Unnikrishnan KP"]
@@ -1,4 +1,5 @@
1
1
  require "active_record"
2
+ require "active_support"
2
3
  require "spreadsheet"
3
4
 
4
5
  $LOAD_PATH.unshift(File.dirname(__FILE__))
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require_relative 'test_helper'
2
2
 
3
3
  class ActsAsAuthoritahTest < Test::Unit::TestCase
4
4
  def test_responds_to_all_can_methods
data/test/test_helper.rb CHANGED
@@ -4,13 +4,13 @@ require 'factory_girl'
4
4
 
5
5
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
6
  $LOAD_PATH.unshift(File.dirname(__FILE__))
7
- require 'activerecord_test_connector'
8
7
  require 'acts_as_authoritah'
8
+ require 'activerecord_test_connector'
9
9
 
10
10
  ActiveRecordTestConnector.setup
11
11
 
12
12
  #load users factory
13
- require 'test/factories/users'
13
+ require_relative 'factories/users'
14
14
 
15
15
  class Test::Unit::TestCase
16
16
  protected
metadata CHANGED
@@ -1,13 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_authoritah
3
3
  version: !ruby/object:Gem::Version
4
- hash: 17
5
- prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 3
10
- version: 1.0.3
4
+ version: 1.0.4
11
5
  platform: ruby
12
6
  authors:
13
7
  - BangTheTable
@@ -21,18 +15,14 @@ default_executable:
21
15
  dependencies:
22
16
  - !ruby/object:Gem::Dependency
23
17
  name: spreadsheet
24
- prerelease: false
25
- requirement: &id001 !ruby/object:Gem::Requirement
26
- none: false
18
+ type: :runtime
19
+ version_requirement:
20
+ version_requirements: !ruby/object:Gem::Requirement
27
21
  requirements:
28
22
  - - ">="
29
23
  - !ruby/object:Gem::Version
30
- hash: 3
31
- segments:
32
- - 0
33
24
  version: "0"
34
- type: :runtime
35
- version_requirements: *id001
25
+ version:
36
26
  description: role based access rights for a user specified via spreadsheet
37
27
  email: devteam@bangthetable.com, unni.tallman@gmail.com
38
28
  executables: []
@@ -68,27 +58,21 @@ rdoc_options:
68
58
  require_paths:
69
59
  - lib
70
60
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
61
  requirements:
73
62
  - - ">="
74
63
  - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
77
- - 0
78
64
  version: "0"
65
+ version:
79
66
  required_rubygems_version: !ruby/object:Gem::Requirement
80
- none: false
81
67
  requirements:
82
68
  - - ">="
83
69
  - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
86
- - 0
87
70
  version: "0"
71
+ version:
88
72
  requirements: []
89
73
 
90
74
  rubyforge_project:
91
- rubygems_version: 1.5.2
75
+ rubygems_version: 1.3.5
92
76
  signing_key:
93
77
  specification_version: 3
94
78
  summary: role based access rights for a user specified via spreadsheet