simple-authorisation 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- simple-authorisation (0.0.2)
4
+ simple-authorisation (0.0.3)
5
5
  sinatra (~> 1.2.6)
6
6
 
7
7
  GEM
@@ -1,17 +1,38 @@
1
1
  module Simple
2
2
  module Authorisation
3
+ def self.post(name, options)
4
+ options[:method] = :post
5
+ self.route(name, options)
6
+ end
7
+
8
+ def self.get(name, options)
9
+ options[:method] = :get
10
+ self.route(name, options)
11
+ end
12
+
3
13
  def self.route(name, options)
4
14
  @@routes ||= {}
5
- @@routes[name] = options
15
+ @@routes[name] = {} unless @@routes.has_key?(name)
16
+
17
+ route_settings = @@routes[name]
18
+ route_settings[options.delete(:method) || :default] = options
6
19
  end
7
20
 
8
21
  def self.is_allowed?(route_name, options)
9
22
  matching_route = (@@routes.keys.sort.reverse.select{|route | route_name.start_with?(route) }).first
10
- route_rules = @@routes[matching_route]
11
- raise "no rules found for #{route_name}" if route_rules.nil?
23
+
24
+ route_settings = @@routes[matching_route]
25
+ raise "no settings found for #{route_name}" if route_settings.nil?
26
+
27
+ method = options.fetch(:method, :default)
28
+ route_rules = route_settings[method] || route_settings[:default]
29
+ raise "no rules found for #{route_name} method #{method}" if route_rules.nil?
30
+
12
31
  allow = route_rules.fetch(:allow, [])
13
32
  deny = route_rules.fetch(:deny, [])
14
33
  user = options.fetch(:user, nil)
34
+
35
+
15
36
  anonymous_user_class = options.fetch(:anonymous_user_class, NilClass)
16
37
 
17
38
  return true if allow.index('?')
@@ -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.2'
6
+ s.version = '0.0.3'
7
7
  s.authors = ["Derek Ekins"]
8
8
  s.description = 'Handles authorisation only'
9
9
  s.summary = "simple-authorisation-#{s.version}"
@@ -33,5 +33,13 @@ module Simple
33
33
  Simple::Authorisation.route '/test', :deny=> ['?']
34
34
  Simple::Authorisation.is_allowed?('/test/page/low', :user => nil).should be_true
35
35
  end
36
+
37
+ it "should apply rules just to a particular method" do
38
+ Simple::Authorisation.post '/test', :deny => ['?']
39
+ Simple::Authorisation.get '/test', :allow => ['?']
40
+
41
+ Simple::Authorisation.is_allowed?('/test', :method => :post, :user => nil).should be_false
42
+ Simple::Authorisation.is_allowed?('/test', :method => :get, :user => nil).should be_true
43
+ end
36
44
  end
37
45
  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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-07-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sinatra
16
- requirement: &10991520 !ruby/object:Gem::Requirement
16
+ requirement: &11063860 !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: *10991520
24
+ version_requirements: *11063860
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &10991020 !ruby/object:Gem::Requirement
27
+ requirement: &11063380 !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: *10991020
35
+ version_requirements: *11063380
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &10990560 !ruby/object:Gem::Requirement
38
+ requirement: &11060200 !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: *10990560
46
+ version_requirements: *11060200
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: sinatra
49
- requirement: &10990100 !ruby/object:Gem::Requirement
49
+ requirement: &11059740 !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: *10990100
57
+ version_requirements: *11059740
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rack-test
60
- requirement: &10989600 !ruby/object:Gem::Requirement
60
+ requirement: &11059280 !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: *10989600
68
+ version_requirements: *11059280
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.2
120
+ summary: simple-authorisation-0.0.3
121
121
  test_files:
122
122
  - spec/simple-authorisation/authorisation_spec.rb
123
123
  - spec/simple-authorisation/sinatra_integration_spec.rb