authoritah 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/authoritah.rb +5 -12
- data/spec/authoritah_spec.rb +22 -5
- data/spec/railsenv/config/environment.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- metadata +36 -17
data/lib/authoritah.rb
CHANGED
@@ -12,6 +12,8 @@ module Authoritah
|
|
12
12
|
base.send(:include, InstanceMethods)
|
13
13
|
|
14
14
|
base.before_filter :check_permissions
|
15
|
+
base.class_inheritable_accessor :controller_permissions
|
16
|
+
base.controller_permissions = PermissionSet.new
|
15
17
|
end
|
16
18
|
|
17
19
|
module ClassMethods
|
@@ -37,8 +39,7 @@ module Authoritah
|
|
37
39
|
role_method = options.to_a.first[0]
|
38
40
|
role_predicate = options.to_a.first[1]
|
39
41
|
|
40
|
-
controller_permissions
|
41
|
-
controller_permissions[controller_name.to_sym] << {
|
42
|
+
controller_permissions << {
|
42
43
|
:type => perm_type,
|
43
44
|
:role_method => role_method,
|
44
45
|
:role_predicate => role_predicate,
|
@@ -47,22 +48,14 @@ module Authoritah
|
|
47
48
|
}
|
48
49
|
end
|
49
50
|
|
50
|
-
def this_controllers_permissions
|
51
|
-
controller_permissions[controller_name.to_sym]
|
52
|
-
end
|
53
|
-
|
54
51
|
protected
|
55
52
|
|
56
53
|
def check_role_selectors(options)
|
57
54
|
raise Authoritah::Controller::OptionsError.new("Too many role selectors") if options.size > 1
|
58
55
|
end
|
59
56
|
|
60
|
-
def controller_permissions
|
61
|
-
@@controller_permissions ||= {}
|
62
|
-
end
|
63
|
-
|
64
57
|
def clear_permissions
|
65
|
-
|
58
|
+
self.controller_permissions = PermissionSet.new
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
@@ -79,7 +72,7 @@ module Authoritah
|
|
79
72
|
end
|
80
73
|
|
81
74
|
def permitted?(action)
|
82
|
-
return true unless permissions = self.
|
75
|
+
return true unless permissions = self.controller_permissions
|
83
76
|
permissions.permits?(self, action)
|
84
77
|
end
|
85
78
|
end
|
data/spec/authoritah_spec.rb
CHANGED
@@ -5,6 +5,8 @@ describe Authoritah::Controller do
|
|
5
5
|
before(:each) do
|
6
6
|
ActionController::Base.send(:include, Authoritah::Controller)
|
7
7
|
ActionController::Base.send(:clear_permissions)
|
8
|
+
TestAuthorizerController.send(:clear_permissions)
|
9
|
+
SpecialisedTestAuthorizerController.send(:clear_permissions)
|
8
10
|
end
|
9
11
|
|
10
12
|
describe "adding methods to controllers" do
|
@@ -30,7 +32,7 @@ describe Authoritah::Controller do
|
|
30
32
|
describe "a basic permits wildcard rule with no predicate" do
|
31
33
|
before(:each) do
|
32
34
|
TestAuthorizerController.permits(:current_user)
|
33
|
-
@permissions = TestAuthorizerController.send(:controller_permissions)
|
35
|
+
@permissions = TestAuthorizerController.send(:controller_permissions)
|
34
36
|
end
|
35
37
|
it "should have one permission" do @permissions.size.should == 1 end
|
36
38
|
it "should use current_user to retrieve the 'role object'" do @permissions.first[:role_method].should == :current_user end
|
@@ -41,9 +43,11 @@ describe Authoritah::Controller do
|
|
41
43
|
describe "a basic permits wildcard rule" do
|
42
44
|
before(:each) do
|
43
45
|
TestAuthorizerController.permits(:current_user => :logged_in?)
|
44
|
-
@permissions = TestAuthorizerController.send(:controller_permissions)
|
46
|
+
@permissions = TestAuthorizerController.send(:controller_permissions)
|
47
|
+
end
|
48
|
+
it "should have one permission" do
|
49
|
+
@permissions.size.should == 1
|
45
50
|
end
|
46
|
-
it "should have one permission" do @permissions.size.should == 1 end
|
47
51
|
it "should use current_user to retrieve the 'role object'" do @permissions.first[:role_method].should == :current_user end
|
48
52
|
it "should use logged_in? as the predicate to call on the 'role object'" do @permissions.first[:role_predicate].should == :logged_in? end
|
49
53
|
it "should not specify the actions" do @permissions.first[:actions].should == [:all] end
|
@@ -52,7 +56,7 @@ describe Authoritah::Controller do
|
|
52
56
|
describe "a basic permits rule on a single action" do
|
53
57
|
before(:each) do
|
54
58
|
TestAuthorizerController.permits(:current_user => :logged_in?, :to => :show)
|
55
|
-
@permissions = TestAuthorizerController.send(:controller_permissions)
|
59
|
+
@permissions = TestAuthorizerController.send(:controller_permissions)
|
56
60
|
end
|
57
61
|
it "should have one permission" do @permissions.size.should == 1 end
|
58
62
|
it "should use current_user to retrieve the 'role object'" do @permissions.first[:role_method].should == :current_user end
|
@@ -63,7 +67,7 @@ describe Authoritah::Controller do
|
|
63
67
|
describe "a basic rule on many actions" do
|
64
68
|
before(:each) do
|
65
69
|
TestAuthorizerController.permits(:current_user => :logged_in?, :to => [:show, :create, :update])
|
66
|
-
@permissions = TestAuthorizerController.send(:controller_permissions)
|
70
|
+
@permissions = TestAuthorizerController.send(:controller_permissions)
|
67
71
|
end
|
68
72
|
it "should specify the actions" do @permissions.first[:actions].should == [:show, :create, :update] end
|
69
73
|
end
|
@@ -74,12 +78,25 @@ describe TestAuthorizerController, :type => :controller do
|
|
74
78
|
before(:each) do
|
75
79
|
TestAuthorizerController.send(:include, Authoritah::Controller)
|
76
80
|
TestAuthorizerController.send(:clear_permissions)
|
81
|
+
SpecialisedTestAuthorizerController.send(:include, Authoritah::Controller)
|
82
|
+
SpecialisedTestAuthorizerController.send(:clear_permissions)
|
77
83
|
end
|
78
84
|
|
79
85
|
context "with no permissions set " do
|
80
86
|
it "should render the index" do get :index; response.should render_template('index') end
|
81
87
|
end
|
82
88
|
|
89
|
+
it "should inherit rules in a subclass" do
|
90
|
+
class ParentController < ActionController::Base
|
91
|
+
include Authoritah::Controller
|
92
|
+
permits :current_user
|
93
|
+
end
|
94
|
+
class ChildController < ParentController
|
95
|
+
end
|
96
|
+
ChildController.controller_permissions.size.should == 1
|
97
|
+
ChildController.controller_permissions.first[:role_method].should == :current_user
|
98
|
+
end
|
99
|
+
|
83
100
|
describe "specifying permit rules" do
|
84
101
|
context "with a wildcard permission (no predicate)" do
|
85
102
|
before(:each) do
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# Be sure to restart your server when you modify this file
|
2
2
|
|
3
3
|
# Specifies gem version of Rails to use when vendor/rails is not present
|
4
|
-
RAILS_GEM_VERSION = '2.3.
|
4
|
+
RAILS_GEM_VERSION = '2.3.5' unless defined? RAILS_GEM_VERSION
|
5
5
|
|
6
6
|
# Bootstrap the Rails environment, frameworks, and default configuration
|
7
7
|
require File.join(File.dirname(__FILE__), 'boot')
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: authoritah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Steven Mohapi-Banks
|
@@ -9,39 +14,51 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-03-04 00:00:00 +00:00
|
13
18
|
default_executable:
|
14
19
|
dependencies:
|
15
20
|
- !ruby/object:Gem::Dependency
|
16
21
|
name: rspec
|
17
|
-
|
18
|
-
|
19
|
-
version_requirements: !ruby/object:Gem::Requirement
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
20
24
|
requirements:
|
21
25
|
- - ">="
|
22
26
|
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 1
|
29
|
+
- 2
|
30
|
+
- 9
|
23
31
|
version: 1.2.9
|
24
|
-
|
32
|
+
type: :development
|
33
|
+
version_requirements: *id001
|
25
34
|
- !ruby/object:Gem::Dependency
|
26
35
|
name: rspec-rails
|
27
|
-
|
28
|
-
|
29
|
-
version_requirements: !ruby/object:Gem::Requirement
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
38
|
requirements:
|
31
39
|
- - ">="
|
32
40
|
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 1
|
43
|
+
- 2
|
44
|
+
- 9
|
33
45
|
version: 1.2.9
|
34
|
-
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id002
|
35
48
|
- !ruby/object:Gem::Dependency
|
36
49
|
name: mocha
|
37
|
-
|
38
|
-
|
39
|
-
version_requirements: !ruby/object:Gem::Requirement
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
40
52
|
requirements:
|
41
53
|
- - ">="
|
42
54
|
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 0
|
57
|
+
- 9
|
58
|
+
- 8
|
43
59
|
version: 0.9.8
|
44
|
-
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
45
62
|
description: A description of a really simple authorization plugin for Rails.
|
46
63
|
email: steven.mohapibanks@me.com
|
47
64
|
executables: []
|
@@ -69,18 +86,20 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
86
|
requirements:
|
70
87
|
- - ">="
|
71
88
|
- !ruby/object:Gem::Version
|
89
|
+
segments:
|
90
|
+
- 0
|
72
91
|
version: "0"
|
73
|
-
version:
|
74
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
93
|
requirements:
|
76
94
|
- - ">="
|
77
95
|
- !ruby/object:Gem::Version
|
96
|
+
segments:
|
97
|
+
- 0
|
78
98
|
version: "0"
|
79
|
-
version:
|
80
99
|
requirements: []
|
81
100
|
|
82
101
|
rubyforge_project:
|
83
|
-
rubygems_version: 1.3.
|
102
|
+
rubygems_version: 1.3.6
|
84
103
|
signing_key:
|
85
104
|
specification_version: 3
|
86
105
|
summary: A really simple authorization plugin for Rails.
|