aegis 2.5.1 → 2.5.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/VERSION +1 -1
- data/aegis.gemspec +7 -5
- data/lib/aegis/has_role.rb +8 -11
- data/lib/aegis/loader.rb +1 -1
- data/lib/aegis/permissions.rb +6 -5
- data/lib/aegis/util.rb +12 -0
- data/spec/aegis/has_role_spec.rb +6 -0
- data/spec/aegis/permissions_spec.rb +3 -3
- data/spec/spec_helper.rb +4 -0
- data/spec/support/spec_candy.rb +20 -0
- metadata +7 -5
- data/Gemfile.lock +0 -48
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.5.
|
1
|
+
2.5.2
|
data/aegis.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{aegis}
|
8
|
-
s.version = "2.5.
|
8
|
+
s.version = "2.5.2"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Henning Koch", "Tobias Kraze"]
|
12
|
-
s.date = %q{2010-11-
|
12
|
+
s.date = %q{2010-11-06}
|
13
13
|
s.description = %q{Aegis is an authorization solution for Ruby on Rails that supports roles and a RESTish, resource-style declaration of permission rules.}
|
14
14
|
s.email = %q{henning.koch@makandra.de}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -18,7 +18,6 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.files = [
|
19
19
|
".gitignore",
|
20
20
|
"Gemfile",
|
21
|
-
"Gemfile.lock",
|
22
21
|
"MIT-LICENSE",
|
23
22
|
"README.rdoc",
|
24
23
|
"Rakefile",
|
@@ -39,6 +38,7 @@ Gem::Specification.new do |s|
|
|
39
38
|
"lib/aegis/sieve.rb",
|
40
39
|
"lib/aegis/spec.rb",
|
41
40
|
"lib/aegis/spec/matchers.rb",
|
41
|
+
"lib/aegis/util.rb",
|
42
42
|
"spec/aegis/controller_spec.rb",
|
43
43
|
"spec/aegis/has_role_spec.rb",
|
44
44
|
"spec/aegis/loader_spec.rb",
|
@@ -69,7 +69,8 @@ Gem::Specification.new do |s|
|
|
69
69
|
"spec/controllers/reviews_controller_spec.rb",
|
70
70
|
"spec/rcov.opts",
|
71
71
|
"spec/spec.opts",
|
72
|
-
"spec/spec_helper.rb"
|
72
|
+
"spec/spec_helper.rb",
|
73
|
+
"spec/support/spec_candy.rb"
|
73
74
|
]
|
74
75
|
s.homepage = %q{http://github.com/makandra/aegis}
|
75
76
|
s.post_install_message = %q{Upgrade notice:
|
@@ -106,7 +107,8 @@ Also see http://wiki.github.com/makandra/aegis/controller-integration
|
|
106
107
|
"spec/aegis/permissions_spec.rb",
|
107
108
|
"spec/aegis/sieve_spec.rb",
|
108
109
|
"spec/aegis/spec/matchers_spec.rb",
|
109
|
-
"spec/aegis/controller_spec.rb"
|
110
|
+
"spec/aegis/controller_spec.rb",
|
111
|
+
"spec/support/spec_candy.rb"
|
110
112
|
]
|
111
113
|
|
112
114
|
if s.respond_to? :specification_version then
|
data/lib/aegis/has_role.rb
CHANGED
@@ -29,8 +29,7 @@ module Aegis
|
|
29
29
|
role_names.include?(role_name.to_s)
|
30
30
|
end
|
31
31
|
|
32
|
-
|
33
|
-
prototype.send :define_method, :validates_role do |*validate_options|
|
32
|
+
Aegis::Util.define_class_method(self, :validates_role) do |*validate_options|
|
34
33
|
validate_options = validate_options[0] || {}
|
35
34
|
|
36
35
|
send :define_method, :validate_role do
|
@@ -66,9 +65,11 @@ module Aegis
|
|
66
65
|
send :define_method, :method_missing_with_aegis_permissions do |symb, *args|
|
67
66
|
method_name = symb.to_s
|
68
67
|
if method_name =~ may_pattern
|
69
|
-
action_path = $1
|
70
|
-
|
71
|
-
|
68
|
+
action_path, severity = $1, $2
|
69
|
+
Aegis::Util.define_class_method(self, method_name) do |*method_args|
|
70
|
+
permissions.call.send("may#{severity}", self, action_path, *method_args)
|
71
|
+
end
|
72
|
+
send(method_name, *args)
|
72
73
|
else
|
73
74
|
method_missing_without_aegis_permissions(symb, *args)
|
74
75
|
end
|
@@ -77,12 +78,8 @@ module Aegis
|
|
77
78
|
alias_method_chain :method_missing, :aegis_permissions
|
78
79
|
|
79
80
|
send :define_method, :respond_to_with_aegis_permissions? do |symb, *args|
|
80
|
-
|
81
|
-
|
82
|
-
else
|
83
|
-
include_private = args.first.nil? ? false : args.first
|
84
|
-
respond_to_without_aegis_permissions?(symb, include_private)
|
85
|
-
end
|
81
|
+
include_private = args.first.nil? ? false : args.first
|
82
|
+
respond_to_without_aegis_permissions?(symb, include_private) || (symb.to_s =~ may_pattern)
|
86
83
|
end
|
87
84
|
|
88
85
|
alias_method_chain :respond_to?, :aegis_permissions
|
data/lib/aegis/loader.rb
CHANGED
data/lib/aegis/permissions.rb
CHANGED
@@ -75,16 +75,17 @@ module Aegis
|
|
75
75
|
compile
|
76
76
|
action = nil
|
77
77
|
action_name = action_name.to_s
|
78
|
-
guess_action_paths(resource_name, action_name, map)
|
78
|
+
possible_paths = guess_action_paths(resource_name, action_name, map)
|
79
|
+
possible_paths.detect do |path|
|
79
80
|
action = find_action_by_path(path, false)
|
80
81
|
end
|
81
|
-
handle_missing_action(action)
|
82
|
+
handle_missing_action(action, possible_paths.first)
|
82
83
|
end
|
83
84
|
|
84
85
|
def find_action_by_path(path, handle_missing = true)
|
85
86
|
compile
|
86
87
|
action = @actions_by_path[path.to_s]
|
87
|
-
action = handle_missing_action(action) if handle_missing
|
88
|
+
action = handle_missing_action(action, path) if handle_missing
|
88
89
|
action
|
89
90
|
end
|
90
91
|
|
@@ -117,12 +118,12 @@ module Aegis
|
|
117
118
|
end
|
118
119
|
end
|
119
120
|
|
120
|
-
def handle_missing_action(possibly_missing_action)
|
121
|
+
def handle_missing_action(possibly_missing_action, path)
|
121
122
|
possibly_missing_action ||= case @missing_action_strategy
|
122
123
|
when :default_permission then Aegis::Action.undefined
|
123
124
|
when :allow then Aegis::Action.allow_to_all
|
124
125
|
when :deny then Aegis::Action.deny_to_all
|
125
|
-
when :error then raise Aegis::MissingAction, "
|
126
|
+
when :error then raise Aegis::MissingAction, "Missing action: #{path}"
|
126
127
|
end
|
127
128
|
end
|
128
129
|
|
data/lib/aegis/util.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module Aegis
|
2
|
+
class Util
|
3
|
+
class << self
|
4
|
+
|
5
|
+
def define_class_method(object, method, &body)
|
6
|
+
prototype = object.respond_to?(:singleton_class) ? object.singleton_class : object.metaclass
|
7
|
+
prototype.send(:define_method, method, &body)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/spec/aegis/has_role_spec.rb
CHANGED
@@ -151,6 +151,12 @@ describe Aegis::HasRole do
|
|
151
151
|
lambda { user.nonexisting_method }.should raise_error(NoMethodError)
|
152
152
|
end
|
153
153
|
|
154
|
+
it 'should define a missing Aegis method so that method is used directly from there on' do
|
155
|
+
user = @user_class.new
|
156
|
+
user.should_receive_and_execute(:method_missing).once
|
157
|
+
2.times { user.may_do_action? }
|
158
|
+
end
|
159
|
+
|
154
160
|
end
|
155
161
|
|
156
162
|
describe 'respond_to?' do
|
@@ -632,12 +632,12 @@ describe Aegis::Permissions do
|
|
632
632
|
@permissions.may?(@admin, 'missing_action').should be_false
|
633
633
|
end
|
634
634
|
|
635
|
-
it "should raise an error if the strategy is :error" do
|
635
|
+
it "should raise an error naming the missing action if the strategy is :error" do
|
636
636
|
@permissions.class_eval do
|
637
637
|
missing_action_means :error
|
638
638
|
end
|
639
|
-
lambda { @permissions.may?(@user, 'missing_action') }.should raise_error(Aegis::MissingAction)
|
640
|
-
lambda { @permissions.may?(@admin, 'missing_action') }.should raise_error(Aegis::MissingAction)
|
639
|
+
lambda { @permissions.may?(@user, 'missing_action') }.should raise_error(Aegis::MissingAction, 'Missing action: missing_action')
|
640
|
+
lambda { @permissions.may?(@admin, 'missing_action') }.should raise_error(Aegis::MissingAction, 'Missing action: missing_action')
|
641
641
|
end
|
642
642
|
|
643
643
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,3 +18,7 @@ Spec::Runner.configure do |config|
|
|
18
18
|
config.use_transactional_fixtures = true
|
19
19
|
config.use_instantiated_fixtures = false
|
20
20
|
end
|
21
|
+
|
22
|
+
# Requires supporting files with custom matchers and macros, etc,
|
23
|
+
# in ./support/ and its subdirectories.
|
24
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),'support','**','*.rb'))].each {|f| require f}
|
@@ -0,0 +1,20 @@
|
|
1
|
+
# Abbreviated from http://makandra.com/notes/627-the-definitive-spec_candy-rb-rspec-helper
|
2
|
+
|
3
|
+
Object.class_eval do
|
4
|
+
|
5
|
+
# a should receive that executes the expected method as usual. does not work with and_return
|
6
|
+
def should_receive_and_execute(method)
|
7
|
+
method_called = "_#{method}_called"
|
8
|
+
|
9
|
+
prototype = respond_to?(:singleton_class) ? singleton_class : metaclass
|
10
|
+
prototype.class_eval do
|
11
|
+
define_method method do |*args|
|
12
|
+
send(method_called, *args)
|
13
|
+
super
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
should_receive(method_called)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: aegis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 2
|
8
8
|
- 5
|
9
|
-
-
|
10
|
-
version: 2.5.
|
9
|
+
- 2
|
10
|
+
version: 2.5.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Henning Koch
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-11-
|
19
|
+
date: 2010-11-06 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies: []
|
22
22
|
|
@@ -31,7 +31,6 @@ extra_rdoc_files:
|
|
31
31
|
files:
|
32
32
|
- .gitignore
|
33
33
|
- Gemfile
|
34
|
-
- Gemfile.lock
|
35
34
|
- MIT-LICENSE
|
36
35
|
- README.rdoc
|
37
36
|
- Rakefile
|
@@ -52,6 +51,7 @@ files:
|
|
52
51
|
- lib/aegis/sieve.rb
|
53
52
|
- lib/aegis/spec.rb
|
54
53
|
- lib/aegis/spec/matchers.rb
|
54
|
+
- lib/aegis/util.rb
|
55
55
|
- spec/aegis/controller_spec.rb
|
56
56
|
- spec/aegis/has_role_spec.rb
|
57
57
|
- spec/aegis/loader_spec.rb
|
@@ -83,6 +83,7 @@ files:
|
|
83
83
|
- spec/rcov.opts
|
84
84
|
- spec/spec.opts
|
85
85
|
- spec/spec_helper.rb
|
86
|
+
- spec/support/spec_candy.rb
|
86
87
|
has_rdoc: true
|
87
88
|
homepage: http://github.com/makandra/aegis
|
88
89
|
licenses: []
|
@@ -148,3 +149,4 @@ test_files:
|
|
148
149
|
- spec/aegis/sieve_spec.rb
|
149
150
|
- spec/aegis/spec/matchers_spec.rb
|
150
151
|
- spec/aegis/controller_spec.rb
|
152
|
+
- spec/support/spec_candy.rb
|
data/Gemfile.lock
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
aegis (2.5.0)
|
5
|
-
|
6
|
-
GEM
|
7
|
-
remote: http://rubygems.org/
|
8
|
-
specs:
|
9
|
-
actionmailer (2.3.8)
|
10
|
-
actionpack (= 2.3.8)
|
11
|
-
actionpack (2.3.8)
|
12
|
-
activesupport (= 2.3.8)
|
13
|
-
rack (~> 1.1.0)
|
14
|
-
activerecord (2.3.8)
|
15
|
-
activesupport (= 2.3.8)
|
16
|
-
activeresource (2.3.8)
|
17
|
-
activesupport (= 2.3.8)
|
18
|
-
activesupport (2.3.8)
|
19
|
-
columnize (0.3.1)
|
20
|
-
linecache (0.43)
|
21
|
-
rack (1.1.0)
|
22
|
-
rails (2.3.8)
|
23
|
-
actionmailer (= 2.3.8)
|
24
|
-
actionpack (= 2.3.8)
|
25
|
-
activerecord (= 2.3.8)
|
26
|
-
activeresource (= 2.3.8)
|
27
|
-
activesupport (= 2.3.8)
|
28
|
-
rake (>= 0.8.3)
|
29
|
-
rake (0.8.7)
|
30
|
-
rspec (1.2.9)
|
31
|
-
rspec-rails (1.2.9)
|
32
|
-
rack (>= 1.0.0)
|
33
|
-
rspec (>= 1.2.9)
|
34
|
-
ruby-debug (0.10.3)
|
35
|
-
columnize (>= 0.1)
|
36
|
-
ruby-debug-base (~> 0.10.3.0)
|
37
|
-
ruby-debug-base (0.10.3)
|
38
|
-
linecache (>= 0.3)
|
39
|
-
|
40
|
-
PLATFORMS
|
41
|
-
ruby
|
42
|
-
|
43
|
-
DEPENDENCIES
|
44
|
-
aegis!
|
45
|
-
rails (= 2.3.8)
|
46
|
-
rspec (= 1.2.9)
|
47
|
-
rspec-rails (= 1.2.9)
|
48
|
-
ruby-debug
|