action-guard 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/action-guard.gemspec +3 -3
- data/lib/action-guard/base.rb +2 -2
- data/lib/action-guard/rules.rb +4 -0
- data/spec/action-guard_spec.rb +33 -0
- metadata +5 -5
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/action-guard.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "action-guard"
|
8
|
-
s.version = "1.
|
8
|
+
s.version = "1.2.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Rob Westgeest"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-10-01"
|
13
13
|
s.description = "authorisation module of actions based on url-paths for usage in Rails and possibly other ruby based web frameworks"
|
14
14
|
s.email = "rob.westgeest@qwan.it"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
s.rdoc_options = ["--charset=UTF-8"]
|
44
44
|
s.require_paths = ["lib"]
|
45
45
|
s.rubygems_version = "1.8.24"
|
46
|
-
s.summary = "Action guard-1.
|
46
|
+
s.summary = "Action guard-1.2.0"
|
47
47
|
|
48
48
|
if s.respond_to? :specification_version then
|
49
49
|
s.specification_version = 3
|
data/lib/action-guard/base.rb
CHANGED
@@ -33,8 +33,8 @@ module ActionGuard
|
|
33
33
|
rules[path_matcher] = LevelRule.new(from_role_value, to_role_value, self, &block)
|
34
34
|
end
|
35
35
|
|
36
|
-
def allow_rule(path_matcher)
|
37
|
-
rules[path_matcher] = AllowRule.new
|
36
|
+
def allow_rule(path_matcher, &block)
|
37
|
+
rules[path_matcher] = AllowRule.new(&block)
|
38
38
|
end
|
39
39
|
|
40
40
|
def refuse_rule(path_matcher)
|
data/lib/action-guard/rules.rb
CHANGED
@@ -27,7 +27,11 @@ module ActionGuard
|
|
27
27
|
end
|
28
28
|
|
29
29
|
class AllowRule
|
30
|
+
def initialize(&block)
|
31
|
+
@additional_rule = block
|
32
|
+
end
|
30
33
|
def allows?(person, request_params)
|
34
|
+
return @additional_rule.call(person, request_params) unless @additional_rule.nil?
|
31
35
|
true
|
32
36
|
end
|
33
37
|
end
|
data/spec/action-guard_spec.rb
CHANGED
@@ -129,6 +129,39 @@ describe ActionGuard do
|
|
129
129
|
end
|
130
130
|
end
|
131
131
|
|
132
|
+
describe "on an allowance rule with a block" do
|
133
|
+
let!(:mock_block_body) { mock }
|
134
|
+
|
135
|
+
before do
|
136
|
+
guard.allow_rule('some_controller#some_action') do |*args|
|
137
|
+
mock_block_body.block_called(*args)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
it "calls block" do
|
142
|
+
account = account_with_role(:worker)
|
143
|
+
mock_block_body.should_receive(:block_called).with(account, request_params_for('some_controller#some_action'))
|
144
|
+
guard.authorized?(account, a_request_for( 'some_controller#some_action'))
|
145
|
+
end
|
146
|
+
|
147
|
+
it "disallows when block returns false" do
|
148
|
+
account = account_with_role(:worker)
|
149
|
+
|
150
|
+
mock_block_body.stub(:block_called).and_return false
|
151
|
+
|
152
|
+
guard.authorized?(account, a_request_for('some_controller#some_action')).should be_false
|
153
|
+
end
|
154
|
+
|
155
|
+
it "allows when block returns true" do
|
156
|
+
account = account_with_role(:worker)
|
157
|
+
|
158
|
+
mock_block_body.stub(:block_called).and_return true
|
159
|
+
|
160
|
+
guard.authorized?(account, a_request_for('some_controller#some_action')).should be_true
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
164
|
+
|
132
165
|
describe "on an exact rule" do
|
133
166
|
before do
|
134
167
|
guard.exact_role_rule 'home', :admin
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: action-guard
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
-
-
|
8
|
+
- 2
|
9
9
|
- 0
|
10
|
-
version: 1.
|
10
|
+
version: 1.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Rob Westgeest
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2012-
|
18
|
+
date: 2012-10-01 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
prerelease: false
|
@@ -173,6 +173,6 @@ rubyforge_project:
|
|
173
173
|
rubygems_version: 1.8.24
|
174
174
|
signing_key:
|
175
175
|
specification_version: 3
|
176
|
-
summary: Action guard-1.
|
176
|
+
summary: Action guard-1.2.0
|
177
177
|
test_files: []
|
178
178
|
|