cantango 0.8.0 → 0.8.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +32 -19
- data/README.textile +79 -131
- data/VERSION +1 -1
- data/cantango.gemspec +94 -61
- data/lib/cantango.rb +4 -6
- data/lib/cantango/ability.rb +28 -17
- data/lib/cantango/ability/cache.rb +30 -60
- data/lib/cantango/ability/cache/base_cache.rb +1 -1
- data/lib/cantango/ability/cache/key.rb +39 -0
- data/lib/cantango/ability/cache/kompiler.rb +22 -6
- data/lib/cantango/ability/cache/moneta_cache.rb +1 -1
- data/lib/cantango/ability/cache/reader.rb +32 -0
- data/lib/cantango/ability/cache/rules_cache.rb +31 -0
- data/lib/cantango/ability/cache/session_cache.rb +3 -2
- data/lib/cantango/ability/cache/writer.rb +42 -0
- data/lib/cantango/ability/cache_helpers.rb +28 -0
- data/lib/cantango/ability/masquerade_helpers.rb +7 -2
- data/lib/cantango/ability/permission_helpers.rb +0 -8
- data/lib/cantango/ability/permit_helpers.rb +0 -17
- data/lib/cantango/ability/role_helpers.rb +0 -2
- data/lib/cantango/ability/user_helpers.rb +1 -0
- data/lib/cantango/adapter/compiler.rb +9 -0
- data/lib/cantango/adapter/moneta.rb +23 -0
- data/lib/cantango/api.rb +1 -1
- data/lib/cantango/api/aliases.rb +4 -8
- data/lib/cantango/api/attributes.rb +17 -0
- data/lib/cantango/api/common.rb +6 -0
- data/lib/cantango/api/options.rb +9 -5
- data/lib/cantango/cache.rb +1 -1
- data/lib/cantango/cache/hash_cache.rb +34 -0
- data/lib/cantango/configuration.rb +13 -8
- data/lib/cantango/configuration/adapters.rb +25 -0
- data/lib/cantango/configuration/categories.rb +3 -1
- data/lib/cantango/configuration/engines.rb +83 -11
- data/lib/cantango/configuration/engines/cache.rb +12 -1
- data/lib/cantango/configuration/engines/engine.rb +5 -5
- data/lib/cantango/configuration/engines/permission.rb +1 -1
- data/lib/cantango/configuration/permit_registry.rb +17 -0
- data/lib/cantango/configuration/permits.rb +29 -0
- data/lib/cantango/configuration/registry.rb +5 -2
- data/lib/cantango/configuration/role_groups.rb +3 -0
- data/lib/cantango/configuration/role_registry.rb +4 -0
- data/lib/cantango/configuration/roles.rb +2 -0
- data/lib/cantango/configuration/user_accounts.rb +1 -0
- data/lib/cantango/configuration/users.rb +1 -0
- data/lib/cantango/engine.rb +13 -0
- data/lib/cantango/filters.rb +5 -0
- data/lib/cantango/filters/filter.rb +34 -0
- data/lib/cantango/filters/role_filter.rb +29 -0
- data/lib/cantango/filters/role_group_filter.rb +28 -0
- data/lib/cantango/permission_engine.rb +26 -1
- data/lib/cantango/permission_engine/collector.rb +7 -2
- data/lib/cantango/permission_engine/compiler.rb +8 -1
- data/lib/cantango/permission_engine/evaluator.rb +2 -2
- data/lib/cantango/permission_engine/factory.rb +8 -12
- data/lib/cantango/permission_engine/loader.rb +1 -1
- data/lib/cantango/permission_engine/loader/base.rb +1 -1
- data/lib/cantango/permission_engine/loader/categories.rb +3 -3
- data/lib/cantango/permission_engine/loader/permissions.rb +8 -5
- data/lib/cantango/permission_engine/moneta_store.rb +2 -2
- data/lib/cantango/permission_engine/parser.rb +1 -1
- data/lib/cantango/permission_engine/parser/categories.rb +1 -1
- data/lib/cantango/permission_engine/parser/category.rb +1 -1
- data/lib/cantango/permission_engine/parser/default.rb +1 -2
- data/lib/cantango/permission_engine/parser/ownership.rb +1 -1
- data/lib/cantango/permission_engine/parser/permissions.rb +1 -1
- data/lib/cantango/permission_engine/parser/regex.rb +2 -2
- data/lib/cantango/permission_engine/parser/relationship.rb +1 -1
- data/lib/cantango/permission_engine/parser/rule.rb +1 -1
- data/lib/cantango/permission_engine/permission.rb +2 -2
- data/lib/cantango/permission_engine/selector.rb +3 -3
- data/lib/cantango/permission_engine/selector/account_types.rb +24 -0
- data/lib/cantango/permission_engine/selector/base.rb +3 -3
- data/lib/cantango/permission_engine/selector/licenses.rb +2 -2
- data/lib/cantango/permission_engine/selector/role_groups.rb +7 -6
- data/lib/cantango/permission_engine/selector/roles.rb +10 -6
- data/lib/cantango/permission_engine/selector/user_types.rb +23 -0
- data/lib/cantango/permission_engine/selector/users.rb +2 -2
- data/lib/cantango/permission_engine/statement.rb +10 -9
- data/lib/cantango/permission_engine/statements.rb +27 -25
- data/lib/cantango/permission_engine/store.rb +1 -1
- data/lib/cantango/permission_engine/yaml_store.rb +2 -2
- data/lib/cantango/permit_engine.rb +29 -4
- data/lib/cantango/permit_engine/builder.rb +2 -3
- data/lib/cantango/permit_engine/builder/base.rb +9 -1
- data/lib/cantango/permit_engine/builder/special_permits.rb +7 -8
- data/lib/cantango/permit_engine/compatibility.rb +1 -1
- data/lib/cantango/permit_engine/executor.rb +1 -1
- data/lib/cantango/permit_engine/executor/abstract.rb +1 -1
- data/lib/cantango/permit_engine/executor/base.rb +1 -1
- data/lib/cantango/permit_engine/executor/system.rb +1 -1
- data/lib/cantango/permit_engine/factory.rb +2 -7
- data/lib/cantango/permit_engine/finder.rb +43 -9
- data/lib/cantango/permit_engine/role_matcher.rb +1 -1
- data/lib/cantango/permit_engine/util.rb +2 -1
- data/lib/cantango/permits.rb +9 -0
- data/lib/cantango/{permit_engine → permits}/account_permit.rb +15 -4
- data/lib/cantango/{permit_engine → permits}/account_permit/builder.rb +2 -6
- data/lib/cantango/{permit_engine → permits}/account_permit/finder.rb +2 -2
- data/lib/cantango/{permit_engine → permits}/license.rb +1 -1
- data/lib/cantango/{permit_engine → permits}/license/loader.rb +1 -1
- data/lib/cantango/{permit_engine → permits}/license/rules.rb +1 -1
- data/lib/cantango/permits/macros.rb +19 -0
- data/lib/cantango/{permit_engine → permits}/permit.rb +13 -1
- data/lib/cantango/{permit_engine → permits}/role_group_permit.rb +15 -3
- data/lib/cantango/{permit_engine → permits}/role_group_permit/builder.rb +10 -22
- data/lib/cantango/{permit_engine → permits}/role_group_permit/finder.rb +2 -2
- data/lib/cantango/{permit_engine → permits}/role_permit.rb +15 -3
- data/lib/cantango/permits/role_permit/builder.rb +27 -0
- data/lib/cantango/{permit_engine → permits}/role_permit/finder.rb +2 -2
- data/lib/cantango/{permit_engine → permits}/user_permit.rb +15 -3
- data/lib/cantango/{permit_engine → permits}/user_permit/builder.rb +2 -6
- data/lib/cantango/{permit_engine → permits}/user_permit/finder.rb +2 -2
- data/lib/cantango/rails.rb +3 -1
- data/lib/cantango/rails/engine.rb +11 -6
- data/lib/cantango/rails/helpers/base_helper.rb +28 -0
- data/lib/cantango/rails/helpers/controller_helper.rb +17 -0
- data/lib/cantango/rails/helpers/rest_helper.rb +44 -0
- data/lib/cantango/rails/helpers/view_helper.rb +17 -0
- data/lib/cantango/rails/railtie.rb +1 -1
- data/lib/cantango/rspec/config.rb +1 -1
- data/lib/cantango/rspec/matchers/be_allowed_to.rb +5 -3
- data/lib/cantango/rules/user_relation.rb +1 -1
- data/lib/cantango/users/macros.rb +8 -2
- data/lib/cantango/users/user.rb +1 -1
- data/lib/generators/cantango/account_permit/account_permit_generator.rb +37 -0
- data/lib/generators/cantango/account_permit/templates/account_permit.erb +13 -0
- data/lib/generators/cantango/base.rb +15 -18
- data/lib/generators/cantango/basic.rb +41 -0
- data/lib/generators/cantango/install/install_generator.rb +37 -0
- data/lib/generators/cantango/install/templates/cantango.rb +4 -0
- data/{spec/active_record/scenarios/user_accounts/config/account_permits.yml → lib/generators/cantango/install/templates/categories.yml} +0 -0
- data/lib/generators/cantango/install/templates/permissions.yml +4 -0
- data/lib/generators/cantango/license/license_generator.rb +6 -11
- data/lib/generators/cantango/license/templates/license.erb +1 -1
- data/lib/generators/cantango/license_base.rb +2 -2
- data/lib/generators/cantango/licenses/licenses_generator.rb +2 -7
- data/lib/generators/cantango/permit_generator.rb +31 -10
- data/lib/generators/cantango/role_permit/role_permit_generator.rb +11 -14
- data/lib/generators/cantango/role_permit/templates/account_permit.erb +2 -2
- data/lib/generators/cantango/role_permit/templates/role_group_permit.erb +2 -2
- data/lib/generators/cantango/role_permit/templates/role_permit.erb +2 -2
- data/lib/generators/cantango/role_permits/role_permits_generator.rb +16 -98
- data/lib/generators/cantango/user_permit/templates/account_permit.erb +5 -0
- data/lib/generators/cantango/user_permit/templates/user_permit.erb +13 -0
- data/lib/generators/cantango/user_permit/user_permit_generator.rb +36 -0
- data/spec/TODO +1 -6
- data/spec/active_record/helper/permits_config.rb +1 -1
- data/spec/active_record/scenarios/engines/permission_engine/{cantango_permissions.yml → permissions.yml} +2 -1
- data/spec/active_record/scenarios/engines/permission_engine/tango_permission_yml_spec.rb +8 -9
- data/spec/active_record/scenarios/engines/permit_engine/licenses_spec.rb +2 -2
- data/spec/active_record/scenarios/engines/permit_engine/role_groups_permits_spec.rb +2 -2
- data/spec/active_record/scenarios/shared/{can_tango.rb → cantango.rb} +1 -1
- data/spec/active_record/scenarios/shared/models/items.rb +0 -1
- data/spec/active_record/scenarios/shared/models/users.rb +6 -1
- data/spec/active_record/spec_helper.rb +6 -4
- data/spec/cantango/ability/cache/key_spec.rb +64 -0
- data/spec/cantango/ability/cache/{compiler_spec.rb → kompiler_spec.rb} +9 -21
- data/spec/cantango/ability/cache/reader_compile_spec.rb +42 -0
- data/spec/cantango/ability/cache/reader_spec.rb +33 -0
- data/spec/cantango/ability/cache/rules_cache_spec.rb +15 -0
- data/spec/cantango/ability/cache/session_cache_spec.rb +1 -1
- data/spec/cantango/ability/cache/writer_spec.rb +21 -0
- data/spec/cantango/ability/cache_spec.rb +6 -2
- data/spec/cantango/ability_filters_spec.rb +5 -10
- data/spec/cantango/ability_spec.rb +2 -3
- data/spec/cantango/api/attributes_spec.rb +27 -0
- data/spec/cantango/api/user/can_api_spec.rb +2 -2
- data/spec/cantango/api/user_account/can_api_spec.rb +2 -2
- data/spec/cantango/configuration/adapter_spec.rb +28 -0
- data/spec/cantango/configuration/engines/cache_spec.rb +2 -2
- data/spec/cantango/configuration/engines/permission_spec.rb +3 -3
- data/spec/cantango/configuration/engines/permit_spec.rb +1 -1
- data/spec/cantango/configuration/engines/store_shared.rb +3 -1
- data/spec/cantango/configuration/engines_spec.rb +106 -3
- data/spec/cantango/configuration/hash_registry_spec.rb +1 -1
- data/spec/cantango/configuration/permit_registry_spec.rb +14 -0
- data/spec/cantango/configuration/permits_spec.rb +25 -0
- data/spec/cantango/configuration/registry_spec.rb +1 -1
- data/spec/cantango/configuration/shared/registry_ex.rb +2 -1
- data/spec/cantango/configuration_spec.rb +5 -5
- data/spec/cantango/permission_engine/compiler_spec.rb +8 -0
- data/spec/cantango/permission_engine/permission_spec.rb +1 -1
- data/spec/cantango/permission_engine/yaml_store_spec.rb +14 -4
- data/spec/cantango/permission_engine_spec.rb +0 -0
- data/spec/cantango/permit_engine/account_permit_spec.rb +2 -4
- data/spec/cantango/permit_engine/builder/role_group_permits_spec.rb +4 -7
- data/spec/cantango/permit_engine/builder/role_permits_spec.rb +5 -6
- data/spec/cantango/permit_engine/builder/special_permits_spec.rb +3 -4
- data/spec/cantango/permit_engine/executor/system_spec.rb +2 -2
- data/spec/cantango/permit_engine/factory_spec.rb +2 -3
- data/spec/cantango/permit_engine/finder_spec.rb +144 -23
- data/spec/cantango/permit_engine/permit/permit_static_and_dynamic_rules_spec.rb +4 -5
- data/spec/cantango/permit_engine/role_group_permit_spec.rb +1 -1
- data/spec/cantango/permit_engine/role_permit_spec.rb +6 -7
- data/spec/cantango/permit_engine/user_permit_spec.rb +2 -3
- data/spec/cantango/permit_engine_spec.rb +2 -0
- data/spec/cantango/permits/macros_spec.rb +41 -0
- data/spec/cantango/permits/permit_spec.rb +46 -0
- data/spec/cantango_spec.rb +13 -0
- data/spec/devise-dummy/app/helpers/application_helper.rb +7 -0
- data/spec/devise-dummy/app/views/articles/admin.html.haml +1 -1
- data/spec/devise-dummy/app/views/articles/admin_account.html.haml +1 -1
- data/spec/devise-dummy/app/views/articles/guest.html.haml +1 -1
- data/spec/devise-dummy/app/views/articles/index.html.haml +1 -1
- data/spec/devise-dummy/app/views/comments/guest.html.haml +1 -1
- data/spec/devise-dummy/app/views/comments/index.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/admin.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/admin_account.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/guest.html.haml +1 -1
- data/spec/devise-dummy/app/views/concertos/index.html.haml +1 -1
- data/spec/devise-dummy/app/views/users/index.html.haml +1 -1
- data/spec/devise-dummy/config/initializers/cantango.rb +3 -3
- data/spec/devise-dummy/config/{cantango_permissions.yml → permissions.yml} +2 -1
- data/spec/devise-integration/concerto_spec.rb +1 -1
- data/spec/dummy/app/models/user.rb +1 -0
- data/spec/dummy/app/views/articles/admin.html.haml +1 -1
- data/spec/dummy/app/views/articles/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/articles/guest.html.haml +1 -1
- data/spec/dummy/app/views/articles/index.html.haml +1 -1
- data/spec/dummy/app/views/comments/guest.html.haml +1 -1
- data/spec/dummy/app/views/comments/index.html.haml +1 -1
- data/spec/dummy/app/views/concertos/admin.html.haml +1 -1
- data/spec/dummy/app/views/concertos/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/concertos/guest.html.haml +1 -1
- data/spec/dummy/app/views/concertos/index.html.haml +1 -1
- data/spec/dummy/app/views/posts/admin.html.haml +1 -1
- data/spec/dummy/app/views/posts/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/posts/guest.html.haml +1 -1
- data/spec/dummy/app/views/posts/index.html.haml +1 -1
- data/spec/dummy/app/views/users/admin.html.haml +1 -1
- data/spec/dummy/app/views/users/admin_account.html.haml +1 -1
- data/spec/dummy/app/views/users/guest.html.haml +1 -1
- data/spec/dummy/app/views/users/index.html.haml +1 -1
- data/spec/dummy/config/application.rb +1 -0
- data/spec/dummy/config/initializers/cantango.rb +1 -3
- data/spec/dummy/config/{cantango_permissions.yml → permissions.yml} +2 -2
- data/spec/dummy_spec_helper.rb +2 -0
- data/spec/entire_suite_spec.rb +2 -0
- data/spec/factories/user.rb +8 -0
- data/spec/factories/user_account.rb +6 -0
- data/spec/fixtures/config/permissions.yml +60 -19
- data/spec/fixtures/models/admin.rb +2 -0
- data/spec/fixtures/models/admin_account.rb +22 -0
- data/spec/fixtures/models/simple_roles.rb +5 -0
- data/spec/fixtures/models/user.rb +4 -0
- data/spec/helpers/dummy_app_ability.rb +2 -5
- data/spec/integration/cache_using_moneta_spec.rb +3 -1
- data/spec/integration/cache_using_session_spec.rb +2 -2
- data/spec/integration/user/articles_spec.rb +1 -1
- data/spec/integration/user/concerto_spec.rb +1 -1
- data/spec/spec_helper.rb +5 -5
- metadata +120 -95
- data/lib/cantango/ability/class_methods.rb +0 -27
- data/lib/cantango/api/aliases/account_permit.rb +0 -8
- data/lib/cantango/api/aliases/license.rb +0 -7
- data/lib/cantango/api/aliases/permit.rb +0 -9
- data/lib/cantango/api/aliases/role_group_permit.rb +0 -7
- data/lib/cantango/api/aliases/role_permit.rb +0 -7
- data/lib/cantango/api/aliases/user_permit.rb +0 -8
- data/lib/cantango/permission_engine/builder.rb +0 -6
- data/lib/cantango/permit_engine/role_permit/builder.rb +0 -46
- data/lib/cantango/rails/base_helpers.rb +0 -26
- data/lib/cantango/rails/controller_helpers.rb +0 -15
- data/lib/cantango/rails/view_helpers.rb +0 -15
- data/spec/active_record/scenarios/shared/permits/PERMITS README.textile +0 -3
- data/spec/active_record/scenarios/user_accounts/docs/USER_ACCOUNTS_SCENARIO.textile +0 -20
- data/spec/active_record/scenarios/user_accounts/docs/basic_rules_spec_possible_samples.txt +0 -84
- data/spec/factories.rb +0 -8
- data/spec/fixtures/config/cantango_permissions.yml +0 -48
@@ -1,6 +1,6 @@
|
|
1
1
|
module CanTango
|
2
|
-
module
|
3
|
-
class RoleGroupPermit < CanTango::
|
2
|
+
module Permits
|
3
|
+
class RoleGroupPermit < CanTango::Permit
|
4
4
|
|
5
5
|
class Builder < CanTango::PermitEngine::Builder::Base
|
6
6
|
#class NoAvailableRoleGroups < StandardError; end
|
@@ -10,36 +10,24 @@ module CanTango
|
|
10
10
|
def build
|
11
11
|
# raise NoAvailableRoleGroups, "no available roles groups are defined" if available_role_groups.empty?
|
12
12
|
role_groups.inject([]) do |permits, role_group|
|
13
|
-
(permits << create_permit(role_group)) if valid?(role_group
|
13
|
+
(permits << create_permit(role_group)) if valid?(role_group)
|
14
14
|
permits
|
15
15
|
end.compact
|
16
16
|
end
|
17
17
|
|
18
|
-
def finder
|
19
|
-
CanTango::PermitEngine::RoleGroupPermit::Finder
|
20
|
-
end
|
21
|
-
|
22
|
-
protected
|
23
|
-
|
24
18
|
def valid? role_group
|
25
|
-
return
|
26
|
-
|
19
|
+
return true if !role_groups_filter?
|
20
|
+
filter(role_group).valid?
|
27
21
|
end
|
28
22
|
|
29
|
-
def
|
30
|
-
|
23
|
+
def filter role_group
|
24
|
+
CanTango::Filters::RoleGroupFilter.new role_group
|
31
25
|
end
|
32
26
|
|
33
|
-
|
34
|
-
excluded_role_groups.include? role_group
|
35
|
-
end
|
36
|
-
|
37
|
-
def only_role_groups
|
38
|
-
CanTango.config.role_groups.onlies
|
39
|
-
end
|
27
|
+
private
|
40
28
|
|
41
|
-
def
|
42
|
-
CanTango.config.role_groups.
|
29
|
+
def role_groups_filter?
|
30
|
+
CanTango.config.role_groups.filter?
|
43
31
|
end
|
44
32
|
end
|
45
33
|
end
|
@@ -1,11 +1,23 @@
|
|
1
1
|
module CanTango
|
2
|
-
module
|
3
|
-
class RolePermit < CanTango::
|
2
|
+
module Permits
|
3
|
+
class RolePermit < CanTango::Permit
|
4
4
|
|
5
5
|
autoload_modules :Builder, :Finder
|
6
6
|
|
7
|
+
def self.inherited(base_clazz)
|
8
|
+
CanTango.config.permits.register_permit_class role_name(base_clazz), base_clazz, type, account_name(base_clazz)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.type
|
12
|
+
:role
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.role_name clazz
|
16
|
+
clazz.name.demodulize.gsub(/(.*)(RolePermit)/, '\1').underscore.to_sym
|
17
|
+
end
|
18
|
+
|
7
19
|
def role
|
8
|
-
self.class.
|
20
|
+
self.class.role_name self.class
|
9
21
|
end
|
10
22
|
|
11
23
|
# creates the permit
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Permits
|
3
|
+
class RolePermit < CanTango::Permit
|
4
|
+
class Builder < CanTango::PermitEngine::Builder::Base
|
5
|
+
# builds a list of Permits for each role of the current ability user (or account)
|
6
|
+
# @return [Array<RoleGroupPermit::Base>] the role permits built for this ability
|
7
|
+
def build
|
8
|
+
roles.inject([]) do |permits, role|
|
9
|
+
(permits << create_permit(role)) if valid?(role.to_sym)
|
10
|
+
permits
|
11
|
+
end.compact
|
12
|
+
end
|
13
|
+
|
14
|
+
protected
|
15
|
+
|
16
|
+
def valid? role
|
17
|
+
filter(role).valid?
|
18
|
+
end
|
19
|
+
|
20
|
+
def filter role
|
21
|
+
CanTango::Filters::RoleFilter.new role
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,12 +1,24 @@
|
|
1
1
|
module CanTango
|
2
|
-
module
|
3
|
-
class UserPermit < CanTango::
|
2
|
+
module Permits
|
3
|
+
class UserPermit < CanTango::Permit
|
4
4
|
|
5
5
|
autoload_modules :Builder, :Finder
|
6
6
|
|
7
|
+
def self.inherited(base_clazz)
|
8
|
+
CanTango.config.permits.register_permit_class user_type_name(base_clazz), base_clazz, type, account_name(base_clazz)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.type
|
12
|
+
:user
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.user_type_name clazz
|
16
|
+
clazz.name.demodulize.gsub(/(.*)(Permit)/, '\1').underscore.to_sym
|
17
|
+
end
|
18
|
+
|
7
19
|
# fx for User user class, becomes simply UserPermit
|
8
20
|
def user_type
|
9
|
-
self.class.
|
21
|
+
self.class.user_type_name self.class
|
10
22
|
end
|
11
23
|
|
12
24
|
# creates the permit
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module CanTango
|
2
|
-
module
|
3
|
-
class UserPermit < CanTango::
|
2
|
+
module Permits
|
3
|
+
class UserPermit < CanTango::Permit
|
4
4
|
class Builder < CanTango::PermitEngine::Builder::Base
|
5
5
|
# class NoAvailableRoles < StandardError; end
|
6
6
|
|
@@ -10,10 +10,6 @@ module CanTango
|
|
10
10
|
# raise NoAvailableRoles, "no available roles are defined" if available_roles.empty?
|
11
11
|
[] << create_permit(user.class.to_s)
|
12
12
|
end
|
13
|
-
|
14
|
-
def finder
|
15
|
-
CanTango::PermitEngine::UserPermit::Finder
|
16
|
-
end
|
17
13
|
end
|
18
14
|
end
|
19
15
|
end
|
data/lib/cantango/rails.rb
CHANGED
@@ -2,24 +2,29 @@ module CanTango
|
|
2
2
|
# Include helpers in the given scope to AC and AV.
|
3
3
|
# "Borrowed" from devise
|
4
4
|
def self.include_helpers(scope)
|
5
|
-
|
5
|
+
|
6
|
+
# Seems like the order of initializers is important! ActiveRecord should go first!
|
7
|
+
ActiveSupport.on_load(:active_record) do
|
8
|
+
RailsAutoLoader.load_models! if CanTango.config.autoload.models?
|
9
|
+
end
|
6
10
|
|
7
|
-
|
11
|
+
ActiveSupport.on_load(:action_controller) do
|
12
|
+
include scope::Rails::Helpers::ControllerHelper
|
8
13
|
end
|
9
14
|
|
10
15
|
ActiveSupport.on_load(:action_view) do
|
11
|
-
|
12
|
-
include scope::Rails::ViewHelpers
|
16
|
+
include scope::Rails::Helpers::ViewHelper
|
13
17
|
end
|
18
|
+
|
14
19
|
end
|
15
20
|
|
16
|
-
class
|
21
|
+
class RailsEngine < ::Rails::Engine
|
22
|
+
|
17
23
|
initializer "cantango.helpers" do
|
18
24
|
CanTango.include_helpers(CanTango)
|
19
25
|
|
20
26
|
# load all models
|
21
27
|
# this is needed in order to register all users and accounts with CanTango using the user/account macros!
|
22
|
-
RailsAutoLoader.load_models! if CanTango.config.autoload.models?
|
23
28
|
|
24
29
|
# load all permits
|
25
30
|
RailsAutoLoader.load_permits! if CanTango.config.autoload.permits?
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
module BaseHelper
|
5
|
+
def self.included(base)
|
6
|
+
include_apis(base)
|
7
|
+
# base.send :include, CanTango::Rails::Helpers::RestHelper
|
8
|
+
base.extend ClassMethods
|
9
|
+
end
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
def include_apis(clazz)
|
13
|
+
return if !respond_to?(:apis) || !apis
|
14
|
+
apis.each do |api|
|
15
|
+
clazz.send :include, "CanTango::Api::User::#{api}".constantize
|
16
|
+
clazz.send :include, "CanTango::Api::UserAccount::#{api}".constantize
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def apis
|
21
|
+
[:Can, :Scope]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
extend ClassMethods
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
module ControllerHelper
|
5
|
+
include CanTango::Rails::Helpers::BaseHelper
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
include_apis(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apis
|
12
|
+
[] # [:Can, :Active, :Scope]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
class RestHelper
|
2
|
+
CanTango.config.models.available_models.each do |model|
|
3
|
+
class_eval %{
|
4
|
+
def delete_#{model}_path obj, options = {}
|
5
|
+
#{model}_path obj, {:method => 'delete'}.merge(options)
|
6
|
+
end
|
7
|
+
}
|
8
|
+
end
|
9
|
+
|
10
|
+
def link_to_new obj, user_type, options = {}
|
11
|
+
return unless send(:"#{user_type}_can?", :create, obj)
|
12
|
+
# use i18n translation on label
|
13
|
+
link_to t(".create"), action_method(obj, :new)
|
14
|
+
end
|
15
|
+
|
16
|
+
def link_to_delete obj, user_type, options = {}
|
17
|
+
return unless send(:"#{user_type}_can?", :delete, obj)
|
18
|
+
# use i18n translation on label
|
19
|
+
link_to t(".delete"), send action_method(obj, :delete), obj, options
|
20
|
+
end
|
21
|
+
|
22
|
+
def link_to_edit obj, user_type, options = {}
|
23
|
+
return unless send(:"#{user_type}_can?", :edit, obj)
|
24
|
+
# use i18n translation on label
|
25
|
+
link_to t(".edit"), send action_method(obj, :edit), obj, options
|
26
|
+
end
|
27
|
+
|
28
|
+
def link_to_view obj, user_type, options = {}
|
29
|
+
return unless send(:"#{user_type}_can?", :edit, obj)
|
30
|
+
# use i18n translation on label
|
31
|
+
link_to t(".view"), send view_method(obj), obj, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
protected
|
35
|
+
|
36
|
+
def view_method obj
|
37
|
+
"#{obj.class.to_s.underscore}_path"
|
38
|
+
end
|
39
|
+
|
40
|
+
def action_method obj, action
|
41
|
+
"#{action}_#{obj.class.to_s.underscore}_path"
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Rails
|
3
|
+
module Helpers
|
4
|
+
module ViewHelper
|
5
|
+
include CanTango::Rails::Helpers::BaseHelper
|
6
|
+
|
7
|
+
def self.included(base)
|
8
|
+
include_apis(self)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.apis
|
12
|
+
[] # [:Can, :Active, :Scope]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -5,5 +5,5 @@ require 'cantango/rspec/matchers'
|
|
5
5
|
RSpec.configure do |config|
|
6
6
|
config.include RSpec::RubyContentMatchers::License
|
7
7
|
config.include RSpec::RubyContentMatchers::LicenseClass
|
8
|
-
config.include RSpec::RubyContentMatchers::LicenseFile
|
8
|
+
config.include RSpec::RubyContentMatchers::LicenseFile
|
9
9
|
end
|
@@ -5,17 +5,19 @@ RSpec::Matchers.define :be_allowed_to do |action, objects|
|
|
5
5
|
chain :with_options do |options|
|
6
6
|
@options = options
|
7
7
|
end
|
8
|
-
|
8
|
+
|
9
9
|
match do |subject|
|
10
10
|
@options ? subject.can?(action, objects, @options) : subject.can?(action, objects)
|
11
11
|
end
|
12
12
|
|
13
13
|
failure_message_for_should do |subject|
|
14
|
-
|
14
|
+
%{expected that #{subject} could #{action} the #{objects}
|
15
|
+
#{subject.send :rules}}
|
15
16
|
end
|
16
17
|
|
17
18
|
failure_message_for_should_not do |actual|
|
18
|
-
|
19
|
+
%{did not expect that #{subject} could #{action} the #{objects}
|
20
|
+
#{subject.send :rules}}
|
19
21
|
end
|
20
22
|
|
21
23
|
description do
|
@@ -1,9 +1,15 @@
|
|
1
1
|
class Module
|
2
|
-
def tango_user
|
2
|
+
def tango_user options = {}
|
3
3
|
self.send :include, CanTango::Users::User
|
4
|
+
self.send :include, CanTango::Users::Masquerade if options[:masquerade]
|
4
5
|
end
|
5
6
|
|
6
|
-
def tango_user_account
|
7
|
+
def tango_user_account options = {}
|
7
8
|
self.send :include, CanTango::Users::UserAccount
|
9
|
+
self.send :include, CanTango::Users::Masquerade if options[:masquerade]
|
10
|
+
end
|
11
|
+
|
12
|
+
def masquerader
|
13
|
+
self.send :include, CanTango::Users::Masquerade
|
8
14
|
end
|
9
15
|
end
|
data/lib/cantango/users/user.rb
CHANGED
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'generators/cantango/base'
|
2
|
+
require 'generators/cantango/license_base'
|
3
|
+
require 'generators/cantango/permit_generator'
|
4
|
+
|
5
|
+
module Cantango
|
6
|
+
module Generators
|
7
|
+
class AccountPermitGenerator < Cantango::Generators::Base
|
8
|
+
desc "Creates a Permit for an account in 'app/permits' with specific permissions and/or licenses"
|
9
|
+
|
10
|
+
argument :account, :type => :string, :desc => "Account class to create permit for"
|
11
|
+
|
12
|
+
class_option :licenses, :type => :array, :default => [], :desc => "Licenses to use in Permit"
|
13
|
+
|
14
|
+
class_option :account, :type => :string,
|
15
|
+
:desc => "Generate permits for a specific user account"
|
16
|
+
|
17
|
+
class_option :group, :type => :boolean, :default => false, :desc => "Generate permit for a role group"
|
18
|
+
|
19
|
+
source_root File.dirname(__FILE__) + '/templates'
|
20
|
+
|
21
|
+
def main_flow
|
22
|
+
template_permit account
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def is_account?
|
28
|
+
true
|
29
|
+
end
|
30
|
+
|
31
|
+
include Cantango::Generators::LicenseBase
|
32
|
+
include Cantango::Generators::PermitGenerator
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
|