cantango-permits 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.rspec +1 -0
- data/Gemfile +39 -0
- data/Gemfile.lock +155 -0
- data/MIT-LICENSE +20 -0
- data/README.mdown +362 -0
- data/Rakefile +45 -0
- data/VERSION +1 -0
- data/lib/cantango/executor.rb +5 -0
- data/lib/cantango/executor/base.rb +9 -0
- data/lib/cantango/executor/permit.rb +7 -0
- data/lib/cantango/executor/permit/abstract.rb +27 -0
- data/lib/cantango/executor/permit/base.rb +19 -0
- data/lib/cantango/executor/permit/special.rb +9 -0
- data/lib/cantango/executor/permit_type.rb +50 -0
- data/lib/cantango/license.rb +19 -0
- data/lib/cantango/license/rules.rb +17 -0
- data/lib/cantango/permit.mdown +4 -0
- data/lib/cantango/permit.rb +5 -0
- data/lib/cantango/permit/account_type.rb +44 -0
- data/lib/cantango/permit/attribute.rb +71 -0
- data/lib/cantango/permit/base.rb +94 -0
- data/lib/cantango/permit/class_methods.rb +49 -0
- data/lib/cantango/permit/helper.rb +11 -0
- data/lib/cantango/permit/helper/execution.rb +38 -0
- data/lib/cantango/permit/helper/host.rb +13 -0
- data/lib/cantango/permit/helper/license.rb +34 -0
- data/lib/cantango/permit/helper/naming.rb +38 -0
- data/lib/cantango/permit/helper/state.rb +21 -0
- data/lib/cantango/permit/special.rb +17 -0
- data/lib/cantango/permit/user.rb +36 -0
- data/lib/cantango/permit/user_type.rb +34 -0
- data/lib/cantango/permits.rb +20 -0
- data/lib/cantango/permits_ext.rb +7 -0
- data/lib/cantango/permits_ext/ability.rb +7 -0
- data/lib/cantango/permits_ext/ability/helper.rb +9 -0
- data/lib/cantango/permits_ext/ability/helper/permits.rb +8 -0
- data/lib/cantango/permits_ext/builder.rb +7 -0
- data/lib/cantango/permits_ext/builder/permit.rb +9 -0
- data/lib/cantango/permits_ext/builder/permit/account_type.rb +13 -0
- data/lib/cantango/permits_ext/builder/permit/base.rb +94 -0
- data/lib/cantango/permits_ext/builder/permit/special.rb +13 -0
- data/lib/cantango/permits_ext/builder/permit/user_type.rb +7 -0
- data/lib/cantango/permits_ext/class_methods.rb +28 -0
- data/lib/cantango/permits_ext/config.rb +11 -0
- data/lib/cantango/permits_ext/config/engines.rb +9 -0
- data/lib/cantango/permits_ext/config/engines/permit.rb +20 -0
- data/lib/cantango/permits_ext/config/permits.rb +43 -0
- data/lib/cantango/permits_ext/config/permits/accounts.rb +15 -0
- data/lib/cantango/permits_ext/config/permits/disabling.rb +22 -0
- data/lib/cantango/permits_ext/config/permits/enabling.rb +14 -0
- data/lib/cantango/permits_ext/config/permits/execution.rb +21 -0
- data/lib/cantango/permits_ext/config/permits/key.rb +19 -0
- data/lib/cantango/permits_ext/config/permits/registration.rb +33 -0
- data/lib/cantango/permits_ext/config/permits/tracking.rb +19 -0
- data/lib/cantango/permits_ext/config/permits/types.rb +25 -0
- data/lib/cantango/permits_ext/engine.rb +7 -0
- data/lib/cantango/permits_ext/engine/permits.rb +75 -0
- data/lib/cantango/permits_ext/factory.rb +7 -0
- data/lib/cantango/permits_ext/factory/permits.rb +40 -0
- data/lib/cantango/permits_ext/finder.rb +7 -0
- data/lib/cantango/permits_ext/finder/base.rb +35 -0
- data/lib/cantango/permits_ext/finder/permit.rb +7 -0
- data/lib/cantango/permits_ext/finder/permit/account.rb +47 -0
- data/lib/cantango/permits_ext/finder/permit/base.rb +53 -0
- data/lib/cantango/permits_ext/loader.rb +7 -0
- data/lib/cantango/permits_ext/loader/categories.rb +50 -0
- data/lib/cantango/permits_ext/loader/license.rb +19 -0
- data/lib/cantango/permits_ext/macros.rb +7 -0
- data/lib/cantango/permits_ext/macros/permit.rb +32 -0
- data/lib/cantango/permits_ext/parser.rb +7 -0
- data/lib/cantango/permits_ext/parser/categories.rb +15 -0
- data/lib/cantango/permits_ext/registry.rb +7 -0
- data/lib/cantango/permits_ext/registry/permit.rb +45 -0
- data/lib/generators/cantango/account_permit/account_permit_generator.rb +37 -0
- data/lib/generators/cantango/account_permit/templates/account_permit.erb +23 -0
- data/lib/generators/cantango/base.rb +71 -0
- data/lib/generators/cantango/basic.rb +41 -0
- data/lib/generators/cantango/license/license_generator.rb +29 -0
- data/lib/generators/cantango/license/templates/license.erb +10 -0
- data/lib/generators/cantango/license_base.rb +15 -0
- data/lib/generators/cantango/licenses/licenses_generator.rb +26 -0
- data/lib/generators/cantango/permit_generator.rb +58 -0
- data/lib/generators/cantango/role_permit/role_permit_generator.rb +39 -0
- data/lib/generators/cantango/role_permit/templates/account_permit.erb +4 -0
- data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +24 -0
- data/lib/generators/cantango/role_permit/templates/role_permit.erb +23 -0
- data/lib/generators/cantango/role_permits/role_permits_generator.rb +45 -0
- data/lib/generators/cantango/user_permit/templates/account_permit.erb +5 -0
- data/lib/generators/cantango/user_permit/templates/user_permit.erb +23 -0
- data/lib/generators/cantango/user_permit/user_permit_generator.rb +36 -0
- data/lib/tasks/permits_tasks.rake +4 -0
- data/spec/cantango/ability/helper/permits_spec.rb +14 -0
- data/spec/cantango/builder/permit/account_type_spec.rb +25 -0
- data/spec/cantango/builder/permit/base_spec.rb +30 -0
- data/spec/cantango/builder/permit/special_spec.rb +25 -0
- data/spec/cantango/builder/permit/user_type_spec.rb +27 -0
- data/spec/cantango/config/engines/permit_spec.rb +14 -0
- data/spec/cantango/config/engines_spec.rb +142 -0
- data/spec/cantango/config/permit_registry_ex.rb +9 -0
- data/spec/cantango/config/permit_registry_spec.rb +8 -0
- data/spec/cantango/config/permits/accounts_spec.rb +23 -0
- data/spec/cantango/config/permits/disabling_spec.rb +38 -0
- data/spec/cantango/config/permits/enabling_spec.rb +19 -0
- data/spec/cantango/config/permits/execution_spec.rb +27 -0
- data/spec/cantango/config/permits/registration_spec.rb +15 -0
- data/spec/cantango/config/permits/tracking_spec.rb +19 -0
- data/spec/cantango/config/permits/types_spec.rb +27 -0
- data/spec/cantango/config/permits_spec.rb +76 -0
- data/spec/cantango/engine/permit_cached_spec.rb +52 -0
- data/spec/cantango/engine/permit_spec.rb +58 -0
- data/spec/cantango/engine/permit_static_dynamic_spec.rb +65 -0
- data/spec/cantango/executor/custom_permit_spec.rb +65 -0
- data/spec/cantango/executor/more_permit_spec.rb +45 -0
- data/spec/cantango/executor/permit_base_spec.rb +46 -0
- data/spec/cantango/executor/permit_spec.rb +53 -0
- data/spec/cantango/executor/special_permit_spec.rb +36 -0
- data/spec/cantango/factory/permits_spec.rb +70 -0
- data/spec/cantango/finder/account_permit_spec.rb +30 -0
- data/spec/cantango/finder/permit_spec.rb +23 -0
- data/spec/cantango/license/save_license_spec.rb +24 -0
- data/spec/cantango/license_spec.rb +0 -0
- data/spec/cantango/loader/categories_spec.rb +47 -0
- data/spec/cantango/loader/license_spec.rb +7 -0
- data/spec/cantango/macros/permit_spec.rb +38 -0
- data/spec/cantango/parser/categories_spec.rb +19 -0
- data/spec/cantango/permit/account_type_spec.rb +34 -0
- data/spec/cantango/permit/attribute_permit_spec.rb +65 -0
- data/spec/cantango/permit/base_spec.rb +106 -0
- data/spec/cantango/permit/class_methods_spec.rb +34 -0
- data/spec/cantango/permit/helper/execution_spec.rb +54 -0
- data/spec/cantango/permit/helper/host_spec.rb +29 -0
- data/spec/cantango/permit/helper/license_spec.rb +37 -0
- data/spec/cantango/permit/helper/naming_spec.rb +56 -0
- data/spec/cantango/permit/helper/state_spec.rb +24 -0
- data/spec/cantango/permit/special_default_spec.rb +2 -0
- data/spec/cantango/permit/special_first_spec.rb +2 -0
- data/spec/cantango/permit/user_type_spec.rb +78 -0
- data/spec/cantango/registry/permit_spec.rb +67 -0
- data/spec/fixtures/config/cantango_permissions.yml +49 -0
- data/spec/fixtures/config/categories.yml +6 -0
- data/spec/fixtures/config/evaluator_fixtures.yml +18 -0
- data/spec/fixtures/config/licenses.yml +4 -0
- data/spec/fixtures/config/permissions.yml +60 -0
- data/spec/fixtures/config/role_group.yml +4 -0
- data/spec/fixtures/config/roles.yml +4 -0
- data/spec/fixtures/config/test_permissions.yml +55 -0
- data/spec/fixtures/config/user_permissions.yml +8 -0
- data/spec/fixtures/models.rb +15 -0
- data/spec/fixtures/models/admin.rb +2 -0
- data/spec/fixtures/models/admin_account.rb +22 -0
- data/spec/fixtures/models/items.rb +11 -0
- data/spec/fixtures/models/permission.rb +12 -0
- data/spec/fixtures/models/simple_roles.rb +49 -0
- data/spec/fixtures/models/user.rb +52 -0
- data/spec/fixtures/models/user_account.rb +21 -0
- data/spec/fixtures/tango_fixtures.rb +29 -0
- data/spec/generators/cantango/account_role_permit_generator_spec.rb +35 -0
- data/spec/generators/cantango/account_role_permits_generator_spec.rb +59 -0
- data/spec/generators/cantango/license_generator_spec.rb +33 -0
- data/spec/generators/cantango/licenses_generator_spec.rb +58 -0
- data/spec/generators/cantango/role_permit_generator_spec.rb +35 -0
- data/spec/generators/cantango/role_permits_generator_spec.rb +58 -0
- data/spec/helpers/current_user_accounts.rb +20 -0
- data/spec/helpers/current_users.rb +10 -0
- data/spec/spec_helper.rb +24 -0
- metadata +325 -0
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
CanTango.config.permits.types.register :user_type
|
|
4
|
+
CanTango.config.debug.set :on
|
|
5
|
+
|
|
6
|
+
class EditorPermit < CanTango::Permit::UserType
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class UserTypePermitBuilder < CanTango::Builder::Permit::Base
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
describe CanTango::Builder::Permit::Base do
|
|
13
|
+
before do
|
|
14
|
+
@user = User.new 'kris', 'kris@mail.ru'
|
|
15
|
+
@ability = CanTango::Ability::Base.new @user
|
|
16
|
+
@finder = CanTango::Finder::Permit::Base.new :editor, :type => :user_type
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
subject do
|
|
20
|
+
UserTypePermitBuilder.new @ability, @finder
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
its(:permit_type) { should == :user_type }
|
|
24
|
+
|
|
25
|
+
specify { UserTypePermitBuilder.permit_type.should == :user_type }
|
|
26
|
+
|
|
27
|
+
specify do
|
|
28
|
+
lambda { subject.build }.should raise_error NotImplementedError
|
|
29
|
+
end
|
|
30
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'fixtures/models'
|
|
3
|
+
|
|
4
|
+
class MySystemPermitBuilder < CanTango::Builder::Permit::Special
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
describe CanTango::Builder::Permit::Special do
|
|
8
|
+
before do
|
|
9
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
subject { MySystemPermitBuilder.new }
|
|
13
|
+
|
|
14
|
+
describe 'attributes' do
|
|
15
|
+
it "should have an ability" do
|
|
16
|
+
subject.ability.should be_a(CanTango::Ability::Base)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe '#build' do
|
|
21
|
+
it 'should build a permit' do
|
|
22
|
+
subject.build.should be_a(CanTango::Permit::Special)
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class AdminUserPermitBuilder < CanTango::Builder::Permit::UserType
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
describe CanTango::Builder::Permit::UserType do
|
|
7
|
+
before do
|
|
8
|
+
@user = User.new 'kris', 'kris@mail.ru', :roles => [:editor]
|
|
9
|
+
@ability = CanTango::Ability::Base.new @user
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
subject do
|
|
13
|
+
AdminUserPermitBuilder.new @ability
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
its(:permit_type) { should == :user_type }
|
|
17
|
+
|
|
18
|
+
describe 'build' do
|
|
19
|
+
it 'should build permits' do
|
|
20
|
+
its(:build) { should be_a CanTango::Permit::UserType }
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'self.permit_type' do
|
|
25
|
+
specify { AdminUserPermitBuilder.permit_type.should == :user_type }
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
require 'cantango'
|
|
3
|
+
require 'fixtures/models'
|
|
4
|
+
|
|
5
|
+
describe CanTango::Config::Engines::Permit do
|
|
6
|
+
subject { CanTango.config.permit_engine }
|
|
7
|
+
|
|
8
|
+
describe 'SpecialPermits' do
|
|
9
|
+
describe 'default settings' do
|
|
10
|
+
its(:special_permits) { should include(:any, :system) }
|
|
11
|
+
its(:types) { should include(:roles, :role_groups, :licenses, :users) }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
require 'rspec'
|
|
2
|
+
require 'cantango'
|
|
3
|
+
require 'fixtures/models'
|
|
4
|
+
|
|
5
|
+
require 'cantango/configuration/engines/engine_shared'
|
|
6
|
+
|
|
7
|
+
class InvalidPerformanceTool
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class PerformanceTool
|
|
11
|
+
attr_reader :ability
|
|
12
|
+
|
|
13
|
+
def execute!
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
describe CanTango::Config::Engines do
|
|
18
|
+
subject { CanTango.config.engines }
|
|
19
|
+
|
|
20
|
+
describe 'default settings' do
|
|
21
|
+
describe 'default_available' do
|
|
22
|
+
its(:default_available) { should include(:permission, :permit, :cache) }
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'available' do
|
|
26
|
+
%w(permit permission).each do |engine|
|
|
27
|
+
specify { subject.available?(engine).should be_true }
|
|
28
|
+
specify { subject.available?(engine.to_sym).should be_true }
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
specify { subject.registered.keys.should include(:permit, :permission) }
|
|
33
|
+
|
|
34
|
+
# TODO: should it be empty?
|
|
35
|
+
describe 'active' do
|
|
36
|
+
its(:active) { should == [] }
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
describe 'execution_order' do
|
|
40
|
+
its(:execution_order) { should == [:permission, :permit] }
|
|
41
|
+
end
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
describe 'Permission engine' do
|
|
45
|
+
it_should_behave_like 'Engine' do
|
|
46
|
+
subject { CanTango.config.engine(:permission) }
|
|
47
|
+
end
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
describe 'Permit engine' do
|
|
51
|
+
it_should_behave_like 'Engine' do
|
|
52
|
+
subject { CanTango.config.engine(:permit) }
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
describe 'Cache engine' do
|
|
57
|
+
it_should_behave_like 'Engine' do
|
|
58
|
+
subject { CanTango.config.engine(:cache) }
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
context 'all on' do
|
|
63
|
+
subject { CanTango.config.engines }
|
|
64
|
+
|
|
65
|
+
before do
|
|
66
|
+
subject.all :on
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
specify do
|
|
70
|
+
[:permit, :permission, :cache].each do |engine|
|
|
71
|
+
CanTango.config.send("#{engine}_engine").on?.should be_true
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
describe 'active' do
|
|
76
|
+
its(:active) { should include(:permit, :permission) }
|
|
77
|
+
end
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
describe 'register' do
|
|
81
|
+
describe 'invalid engine registration' do
|
|
82
|
+
specify do
|
|
83
|
+
lambda { subject.register :performance => InvalidPerformanceTool }.should raise_error
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
describe 'valid engine registration' do
|
|
88
|
+
before do
|
|
89
|
+
subject.register :performance => PerformanceTool
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
specify { subject.registered.keys.should include(:performance) }
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
|
|
96
|
+
describe 'execution' do
|
|
97
|
+
context 'reverse execution order' do
|
|
98
|
+
before do
|
|
99
|
+
subject.execution_order = :permit, :permission
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
its(:execution_order) { should == [:permit, :permission] }
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
describe 'execute_before' do
|
|
106
|
+
before do
|
|
107
|
+
subject.execute_before :permit, :non_existing
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
its(:execution_order) { should == [:non_existing, :permit, :permission] }
|
|
111
|
+
end
|
|
112
|
+
|
|
113
|
+
describe 'execute_after' do
|
|
114
|
+
before do
|
|
115
|
+
subject.execute_after :permit, :performance
|
|
116
|
+
subject.execute_after :permission, :last
|
|
117
|
+
end
|
|
118
|
+
|
|
119
|
+
its(:execution_order) { should == [:non_existing, :permit, :performance, :permission, :last] }
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
describe 'execute_after' do
|
|
123
|
+
before do
|
|
124
|
+
subject.execute_last :very_last
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
its(:execution_order) { should == [:non_existing, :permit, :performance, :permission, :last, :very_last] }
|
|
128
|
+
end
|
|
129
|
+
|
|
130
|
+
describe 'execute_first' do
|
|
131
|
+
before do
|
|
132
|
+
subject.execute_first :very_first
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
after do
|
|
136
|
+
CanTango.config.engines.clear!
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
its(:execution_order) { should == [:very_first, :non_existing, :permit, :performance, :permission, :last, :very_last] }
|
|
140
|
+
end
|
|
141
|
+
end
|
|
142
|
+
end
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
shared_examples_for CanTango::Config::PermitRegistry do
|
|
4
|
+
it "#get_registry_for should work for default permit types" do
|
|
5
|
+
[:user_type, :account_type, :role, :role_group].each do |type|
|
|
6
|
+
subject.get_registry_for(type).should_not be_nil
|
|
7
|
+
end
|
|
8
|
+
end
|
|
9
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Accounts
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Accounts
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe CanTango::Config::Permits::Accounts do
|
|
10
|
+
subject { Accounts.new }
|
|
11
|
+
|
|
12
|
+
describe 'accounts=' do
|
|
13
|
+
pending
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'accounts' do
|
|
17
|
+
pending
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'account_hash name' do
|
|
21
|
+
pending
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Disabling
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Disabling
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
class CanTango::Permit::Mine < CanTango::Permit::UserType
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
CanTango.config do |c|
|
|
13
|
+
c.permits.register_permit CanTango::Permit::Mine
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe CanTango::Config::Permits::Disabling do
|
|
17
|
+
subject { Disabling.new }
|
|
18
|
+
|
|
19
|
+
describe 'disable_for :type, [name1, name2]' do
|
|
20
|
+
before do
|
|
21
|
+
Disabling.disable_for :user_type, [:mine]
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
describe 'disable_for :type => [name1, name2]' do
|
|
26
|
+
before do
|
|
27
|
+
Disabling.disable_for :user_type => [:mine]
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
describe 'disabled_for type' do
|
|
32
|
+
pending
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
describe 'disabled' do
|
|
36
|
+
pending
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Enabling
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Enabling
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe CanTango::Config::Permits::Enabling do
|
|
10
|
+
subject { Enabling.new }
|
|
11
|
+
|
|
12
|
+
describe 'enabled_all_for' do
|
|
13
|
+
pending
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'enable_all!' do
|
|
17
|
+
pending
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Execution
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Execution
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe CanTango::Config::Permits::Execution do
|
|
10
|
+
subject { Execution.new }
|
|
11
|
+
|
|
12
|
+
describe 'was_executed(permit, ability)' do
|
|
13
|
+
pending
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'executed_for(ability)' do
|
|
17
|
+
pending
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'executed' do
|
|
21
|
+
pending
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'clear_executed!' do
|
|
25
|
+
pending
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Registration
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Registration
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe CanTango::Config::Permits::Registration do
|
|
10
|
+
subject { Registration.new }
|
|
11
|
+
|
|
12
|
+
describe '' do
|
|
13
|
+
pending
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Tracking
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Tracking
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe CanTango::Config::Permits::Tracking do
|
|
10
|
+
subject { Tracking.new }
|
|
11
|
+
|
|
12
|
+
describe 'allowed(candidate, actions, subjects)' do
|
|
13
|
+
pending
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'denied(candidate, actions, subjects)' do
|
|
17
|
+
pending
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class Types
|
|
4
|
+
include Singleton
|
|
5
|
+
|
|
6
|
+
include CanTango::Config::Permits::Types
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
describe CanTango::Config::Permits::Types do
|
|
10
|
+
subject { Types.new }
|
|
11
|
+
|
|
12
|
+
describe 'available' do
|
|
13
|
+
pending
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
describe 'enabled' do
|
|
17
|
+
pending
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
describe 'disable *types' do
|
|
21
|
+
pending
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
describe 'enable_all!' do
|
|
25
|
+
pending
|
|
26
|
+
end
|
|
27
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
require 'cantango/configuration/permit_registry_ex'
|
|
3
|
+
|
|
4
|
+
class Menu
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
class WaiterPermit < CanTango::Permit::UserType
|
|
8
|
+
def initialize ability
|
|
9
|
+
super
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
protected
|
|
13
|
+
|
|
14
|
+
def calc_rules
|
|
15
|
+
can :read, Menu
|
|
16
|
+
cannot :write, Menu
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
class ChefPermit < CanTango::Permit::UserType
|
|
21
|
+
def initialize ability
|
|
22
|
+
super
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
protected
|
|
26
|
+
|
|
27
|
+
def calc_rules
|
|
28
|
+
can :publish, Menu
|
|
29
|
+
can :write, Menu
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
class Context
|
|
34
|
+
include CanTango::Api::Ability::User
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
describe CanTango::Config::Permits do
|
|
38
|
+
subject { CanTango::Config::Permits.instance }
|
|
39
|
+
|
|
40
|
+
it_should_behave_like CanTango::Config::PermitRegistry
|
|
41
|
+
|
|
42
|
+
describe 'clear_permits_executed!' do
|
|
43
|
+
specify { CanTango.config.permits.executed.should be_empty }
|
|
44
|
+
|
|
45
|
+
before do
|
|
46
|
+
CanTango.config.permits.executed[:x] = 1
|
|
47
|
+
subject.clear_permits_executed!
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
specify { CanTango.config.permits.executed.should be_empty }
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
describe 'debugging permits' do
|
|
54
|
+
let(:context) { Context.new }
|
|
55
|
+
let (:user) do
|
|
56
|
+
User.new 'kris', 'kris@gmail.com', :role => :waiter
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
before do
|
|
60
|
+
CanTango.config.debug.set :on
|
|
61
|
+
# context.user_ability(user).can? :read, Menu
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
describe 'should tell which permits allowe :read' do
|
|
65
|
+
it 'should show WaiterRolePermit as the permit that allowed :read of Menu' do
|
|
66
|
+
CanTango.permits_allowed(user, :read, Menu).should include(WaiterPermit)
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
describe 'should tell which permits denied :write' do
|
|
71
|
+
it 'should show WaiterRolePermit as the permit that denied :write of Menu' do
|
|
72
|
+
CanTango.permits_denied(user, :write, Menu).should include(WaiterPermit)
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
end
|