stffn-declarative_authorization 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/init.rb +4 -14
- data/lib/declarative_authorization.rb +15 -0
- data/lib/{authorization.rb → declarative_authorization/authorization.rb} +1 -1
- data/lib/{helper.rb → declarative_authorization/helper.rb} +0 -0
- data/lib/{in_controller.rb → declarative_authorization/in_controller.rb} +0 -0
- data/lib/{in_model.rb → declarative_authorization/in_model.rb} +0 -0
- data/lib/{maintenance.rb → declarative_authorization/maintenance.rb} +0 -0
- data/lib/{obligation_scope.rb → declarative_authorization/obligation_scope.rb} +0 -0
- data/lib/{rails_legacy.rb → declarative_authorization/rails_legacy.rb} +0 -0
- data/lib/{reader.rb → declarative_authorization/reader.rb} +0 -0
- data/test/helper_test.rb +1 -2
- data/test/maintenance_test.rb +1 -1
- data/test/model_test.rb +28 -1
- data/test/test_helper.rb +4 -4
- metadata +10 -9
data/init.rb
CHANGED
@@ -1,15 +1,5 @@
|
|
1
|
-
|
2
|
-
require File.dirname(__FILE__)
|
3
|
-
|
4
|
-
require
|
5
|
-
require File.dirname(__FILE__) + "/lib/obligation_scope.rb"
|
6
|
-
|
7
|
-
min_rails_version = "2.1.0"
|
8
|
-
if Rails::VERSION::STRING < min_rails_version
|
9
|
-
raise "declarative_authorization requires Rails #{min_rails_version}. You are using #{Rails::VERSION::STRING}."
|
1
|
+
begin
|
2
|
+
require File.join(File.dirname(__FILE__), 'lib', 'declarative_authorization') # From here
|
3
|
+
rescue LoadError
|
4
|
+
require 'declarative_authorization' # From gem
|
10
5
|
end
|
11
|
-
|
12
|
-
ActionController::Base.send :include, Authorization::AuthorizationInController
|
13
|
-
ActionController::Base.helper Authorization::AuthorizationHelper
|
14
|
-
|
15
|
-
ActiveRecord::Base.send :include, Authorization::AuthorizationInModel
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require File.join(%w{declarative_authorization rails_legacy})
|
2
|
+
require File.join(%w{declarative_authorization helper})
|
3
|
+
require File.join(%w{declarative_authorization in_controller})
|
4
|
+
require File.join(%w{declarative_authorization in_model})
|
5
|
+
require File.join(%w{declarative_authorization obligation_scope})
|
6
|
+
|
7
|
+
min_rails_version = "2.1.0"
|
8
|
+
if Rails::VERSION::STRING < min_rails_version
|
9
|
+
raise "declarative_authorization requires Rails #{min_rails_version}. You are using #{Rails::VERSION::STRING}."
|
10
|
+
end
|
11
|
+
|
12
|
+
ActionController::Base.send :include, Authorization::AuthorizationInController
|
13
|
+
ActionController::Base.helper Authorization::AuthorizationHelper
|
14
|
+
|
15
|
+
ActiveRecord::Base.send :include, Authorization::AuthorizationInModel
|
@@ -124,7 +124,7 @@ module Authorization
|
|
124
124
|
#
|
125
125
|
# Example: permit!( :edit, :object => user.posts )
|
126
126
|
#
|
127
|
-
if options[:object].respond_to?( :proxy_reflection )
|
127
|
+
if options[:object].respond_to?( :proxy_reflection ) && options[:object].respond_to?( :new )
|
128
128
|
options[:object] = options[:object].new
|
129
129
|
end
|
130
130
|
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/helper_test.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
-
require File.dirname(__FILE__)
|
3
|
-
require File.dirname(__FILE__) + '/../lib/helper.rb'
|
2
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization helper})
|
4
3
|
|
5
4
|
|
6
5
|
class HelperMocksController < MocksController
|
data/test/maintenance_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
-
require File.join(File.dirname(__FILE__), %w{.. lib maintenance})
|
2
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization maintenance})
|
3
3
|
|
4
4
|
class MaintenanceTest < Test::Unit::TestCase
|
5
5
|
|
data/test/model_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
|
-
require File.join(File.dirname(__FILE__),
|
2
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization in_model})
|
3
3
|
|
4
4
|
ActiveRecord::Base.send :include, Authorization::AuthorizationInModel
|
5
5
|
#ActiveRecord::Base.logger = Logger.new(STDOUT)
|
@@ -533,6 +533,33 @@ class ModelTest < Test::Unit::TestCase
|
|
533
533
|
TestAttr.delete_all
|
534
534
|
end
|
535
535
|
|
536
|
+
def test_permit_with_has_one_raises_no_name_error
|
537
|
+
reader = Authorization::Reader::DSLReader.new
|
538
|
+
reader.parse %{
|
539
|
+
authorization do :test_attr_has_one
|
540
|
+
role :test_role do
|
541
|
+
has_permission_on :test_attrs, :to => :update do
|
542
|
+
if_attribute :id => is { user.test_attr.id }
|
543
|
+
end
|
544
|
+
end
|
545
|
+
end
|
546
|
+
}
|
547
|
+
instance = Authorization::Engine.instance(reader)
|
548
|
+
|
549
|
+
test_model = TestModel.create!
|
550
|
+
test_attr = test_model.create_test_attr_has_one
|
551
|
+
assert !test_attr.new_record?
|
552
|
+
|
553
|
+
user = MockUser.new(:test_role, :test_attr => test_attr)
|
554
|
+
|
555
|
+
assert_nothing_raised do
|
556
|
+
assert instance.permit?(:update, :user => user, :object => test_model.test_attr_has_one)
|
557
|
+
end
|
558
|
+
|
559
|
+
TestModel.delete_all
|
560
|
+
TestAttr.delete_all
|
561
|
+
end
|
562
|
+
|
536
563
|
def test_named_scope_with_is_and_has_one_through_conditions
|
537
564
|
reader = Authorization::Reader::DSLReader.new
|
538
565
|
reader.parse %{
|
data/test/test_helper.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'test/unit'
|
2
|
-
RAILS_ROOT = File.dirname(__FILE__)
|
3
|
-
require File.dirname(__FILE__)
|
4
|
-
require File.dirname(__FILE__)
|
5
|
-
require File.dirname(__FILE__)
|
2
|
+
RAILS_ROOT = File.join(File.dirname(__FILE__), %w{.. .. .. ..})
|
3
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization rails_legacy})
|
4
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization authorization})
|
5
|
+
require File.join(File.dirname(__FILE__), %w{.. lib declarative_authorization in_controller})
|
6
6
|
|
7
7
|
unless defined?(ActiveRecord)
|
8
8
|
if File.directory? RAILS_ROOT + 'config'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stffn-declarative_authorization
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Steffen Bartsch
|
@@ -46,14 +46,15 @@ files:
|
|
46
46
|
- app/views/authorization_rules/graph.dot.erb
|
47
47
|
- app/views/authorization_rules/graph.html.erb
|
48
48
|
- config/routes.rb
|
49
|
-
- lib/
|
50
|
-
- lib/
|
51
|
-
- lib/
|
52
|
-
- lib/
|
53
|
-
- lib/
|
54
|
-
- lib/
|
55
|
-
- lib/
|
56
|
-
- lib/
|
49
|
+
- lib/declarative_authorization.rb
|
50
|
+
- lib/declarative_authorization/in_controller.rb
|
51
|
+
- lib/declarative_authorization/reader.rb
|
52
|
+
- lib/declarative_authorization/rails_legacy.rb
|
53
|
+
- lib/declarative_authorization/obligation_scope.rb
|
54
|
+
- lib/declarative_authorization/in_model.rb
|
55
|
+
- lib/declarative_authorization/helper.rb
|
56
|
+
- lib/declarative_authorization/authorization.rb
|
57
|
+
- lib/declarative_authorization/maintenance.rb
|
57
58
|
- test/authorization_test.rb
|
58
59
|
- test/schema.sql
|
59
60
|
- test/maintenance_test.rb
|