simple-authorisation 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
@@ -39,9 +39,12 @@ module Simple
|
|
39
39
|
|
40
40
|
anonymous_user_class = options.fetch(:anonymous_user_class, NilClass)
|
41
41
|
|
42
|
-
return true
|
43
|
-
return false
|
44
|
-
return true
|
42
|
+
return true if allow.index('?')
|
43
|
+
return false if deny.index('?') and user.is_a? anonymous_user_class
|
44
|
+
return true if allow.index('*') and not user.is_a? anonymous_user_class
|
45
|
+
allow.each do | allowed |
|
46
|
+
return true if user.actions.include?(allowed)
|
47
|
+
end if user.respond_to? :actions
|
45
48
|
|
46
49
|
false
|
47
50
|
end
|
@@ -10,7 +10,11 @@ module Sinatra
|
|
10
10
|
app.before do
|
11
11
|
route_name = request.path
|
12
12
|
user = send(options.authorisation_current_user)
|
13
|
-
unless Simple::Authorisation.is_allowed?(
|
13
|
+
unless Simple::Authorisation.is_allowed?(
|
14
|
+
route_name,
|
15
|
+
:user => user,
|
16
|
+
:anonymous_user_class => options.authorisation_anonymous_user_class,
|
17
|
+
:method => request.request_method.downcase.to_sym)
|
14
18
|
session[:return_to] = request.fullpath unless request.fullpath.include?('favicon.ico')
|
15
19
|
redirect options.authorisation_login
|
16
20
|
return false
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |s|
|
5
5
|
s.name = 'simple-authorisation'
|
6
|
-
s.version = '0.0.
|
6
|
+
s.version = '0.0.5'
|
7
7
|
s.authors = ["Derek Ekins"]
|
8
8
|
s.description = 'Handles authorisation only'
|
9
9
|
s.summary = "simple-authorisation-#{s.version}"
|
@@ -54,5 +54,28 @@ module Simple
|
|
54
54
|
it "should raise an exception when checking is_allowed for a route with no rules" do
|
55
55
|
lambda {Simple::Authorisation.is_allowed?('/test', :method => :get, :user => nil)}.should raise_error(Simple::Authorisation::NoSettingsForRoute)
|
56
56
|
end
|
57
|
+
|
58
|
+
it "should be pass if we ask the user object if the user is allowed to perform the action when they are" do
|
59
|
+
user = Object.new
|
60
|
+
user.stub!(:actions).and_return(['test-action'])
|
61
|
+
|
62
|
+
Simple::Authorisation.route '/test', :allow => ['test-action']
|
63
|
+
Simple::Authorisation.is_allowed?('/test', :method => :get, :user => user).should be_true
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should be fail if we ask the user object if the user is allowed to perform the action and they are not" do
|
67
|
+
user = Object.new
|
68
|
+
user.stub!(:actions).and_return(['wrong-action'])
|
69
|
+
|
70
|
+
Simple::Authorisation.route '/test', :allow => ['test-action']
|
71
|
+
Simple::Authorisation.is_allowed?('/test', :method => :get, :user => user).should be_false
|
72
|
+
end
|
73
|
+
|
74
|
+
it "should not call the actions method if it does not exist" do
|
75
|
+
user = Object.new
|
76
|
+
|
77
|
+
Simple::Authorisation.route '/test', :allow => ['test-action']
|
78
|
+
lambda{ Simple::Authorisation.is_allowed?('/test', :method => :get, :user => user)}.should_not raise_error
|
79
|
+
end
|
57
80
|
end
|
58
81
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple-authorisation
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-08-03 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sinatra
|
16
|
-
requirement: &
|
16
|
+
requirement: &11355540 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 1.2.6
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *11355540
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
requirement: &
|
27
|
+
requirement: &11355060 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 0.9.2
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *11355060
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rspec
|
38
|
-
requirement: &
|
38
|
+
requirement: &11354600 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 2.6.0
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *11354600
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: sinatra
|
49
|
-
requirement: &
|
49
|
+
requirement: &11354140 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ! '>='
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.2.6
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *11354140
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: rack-test
|
60
|
-
requirement: &
|
60
|
+
requirement: &11353680 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: 0.6.0
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *11353680
|
69
69
|
description: Handles authorisation only
|
70
70
|
email: derek@spathi.com
|
71
71
|
executables: []
|
@@ -117,7 +117,7 @@ rubyforge_project:
|
|
117
117
|
rubygems_version: 1.8.6
|
118
118
|
signing_key:
|
119
119
|
specification_version: 3
|
120
|
-
summary: simple-authorisation-0.0.
|
120
|
+
summary: simple-authorisation-0.0.5
|
121
121
|
test_files:
|
122
122
|
- spec/simple-authorisation/authorisation_spec.rb
|
123
123
|
- spec/simple-authorisation/sinatra_integration_spec.rb
|