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
@@ -6,9 +6,20 @@ module CanTango
|
|
6
6
|
class Cache < Engine
|
7
7
|
include Singleton
|
8
8
|
|
9
|
+
def compile state
|
10
|
+
raise "Must be set to :on or :off" if ![:on, :off].include? state
|
11
|
+
@compile = state
|
12
|
+
end
|
13
|
+
|
14
|
+
def compile?
|
15
|
+
@compile ||= :on
|
16
|
+
@compile == :on
|
17
|
+
end
|
18
|
+
|
9
19
|
def store &block
|
10
20
|
@store ||= ns::Store.new
|
11
|
-
|
21
|
+
# CanTango::Ability::Cache::MonetaCache
|
22
|
+
@store.default_class ||= CanTango::Ability::Cache::SessionCache
|
12
23
|
yield @store if block
|
13
24
|
@store
|
14
25
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CanTango
|
2
|
+
class Configuration
|
3
|
+
class Permits < PermitRegistry
|
4
|
+
include Singleton
|
5
|
+
|
6
|
+
attr_reader :accounts
|
7
|
+
# CanTango.config.permits.accounts[:admin].role => {}
|
8
|
+
|
9
|
+
def accounts
|
10
|
+
@accounts ||= Hash.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def account_hash name
|
14
|
+
accounts[name]
|
15
|
+
end
|
16
|
+
|
17
|
+
def method_missing method_name, *args
|
18
|
+
accounts[method_name] ||= PermitRegistry.new
|
19
|
+
end
|
20
|
+
|
21
|
+
def register_permit_class(permit_name, permit_clazz, permit_type, account_name)
|
22
|
+
registry = account_name ? self.send(account_name.to_sym) : self
|
23
|
+
registry.send(permit_type)[permit_name] = permit_clazz
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
@@ -4,11 +4,10 @@ require 'sugar-high/kind_of'
|
|
4
4
|
module CanTango
|
5
5
|
class Configuration
|
6
6
|
class Registry
|
7
|
+
|
7
8
|
attr_writer :default
|
8
9
|
attr_accessor :registered
|
9
10
|
|
10
|
-
include Singleton
|
11
|
-
|
12
11
|
def types= *types
|
13
12
|
@types = types.select {|t| t.is_a? Class }
|
14
13
|
end
|
@@ -43,6 +42,10 @@ module CanTango
|
|
43
42
|
@registered ||= default
|
44
43
|
end
|
45
44
|
|
45
|
+
def registered? label
|
46
|
+
registered.map(&:to_s).include? label.to_s
|
47
|
+
end
|
48
|
+
|
46
49
|
def default
|
47
50
|
@default ||= []
|
48
51
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Filters
|
3
|
+
class Filter
|
4
|
+
attr_reader :item, :include_list
|
5
|
+
|
6
|
+
def initialize item, list = nil
|
7
|
+
@item = item.to_sym
|
8
|
+
@include_list = list || []
|
9
|
+
end
|
10
|
+
|
11
|
+
def valid?
|
12
|
+
return false if !in_include_list?
|
13
|
+
return false if not_only?
|
14
|
+
!excluded?
|
15
|
+
end
|
16
|
+
|
17
|
+
def in_include_list?
|
18
|
+
return true if include_list.empty?
|
19
|
+
include_list.include? item
|
20
|
+
end
|
21
|
+
|
22
|
+
def not_only?
|
23
|
+
false
|
24
|
+
end
|
25
|
+
|
26
|
+
def excluded?
|
27
|
+
false
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Filters
|
3
|
+
class RoleFilter < Filter
|
4
|
+
alias_method :role, :item
|
5
|
+
|
6
|
+
def initialize role, roles = nil
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def not_only?
|
11
|
+
!only_roles.empty? && !only_roles.include?(role)
|
12
|
+
end
|
13
|
+
|
14
|
+
def excluded?
|
15
|
+
!excluded_roles.empty? && excluded_roles.include?(role)
|
16
|
+
end
|
17
|
+
|
18
|
+
def only_roles
|
19
|
+
CanTango.config.roles.onlies
|
20
|
+
end
|
21
|
+
|
22
|
+
def excluded_roles
|
23
|
+
CanTango.config.roles.excluded
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module CanTango
|
2
|
+
module Filters
|
3
|
+
class RoleGroupFilter < Filter
|
4
|
+
alias_method :role_group, :item
|
5
|
+
|
6
|
+
def initialize role_group, role_groups = nil
|
7
|
+
super
|
8
|
+
end
|
9
|
+
|
10
|
+
def not_only?
|
11
|
+
!only_role_groups.empty? && !only_role_groups.include?(role_group)
|
12
|
+
end
|
13
|
+
|
14
|
+
def excluded?
|
15
|
+
!excluded_role_groups.empty? && excluded_role_groups.include?(role_group)
|
16
|
+
end
|
17
|
+
|
18
|
+
def only_role_groups
|
19
|
+
CanTango.config.role_groups.onlies
|
20
|
+
end
|
21
|
+
|
22
|
+
def excluded_role_groups
|
23
|
+
CanTango.config.role_groups.excluded
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
@@ -1,7 +1,32 @@
|
|
1
1
|
module CanTango
|
2
|
-
|
2
|
+
class PermissionEngine < Engine
|
3
3
|
autoload_modules :Collector, :Compiler, :Evaluator, :Selector
|
4
4
|
autoload_modules :Factory, :Loader, :Parser, :Permission
|
5
5
|
autoload_modules :RulesParser, :Store, :YamlStore, :Statements, :Statement
|
6
|
+
|
7
|
+
def initialize ability
|
8
|
+
super
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute!
|
12
|
+
puts "permissions"
|
13
|
+
permissions.each do |permission|
|
14
|
+
permission.evaluate! user
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def permissions
|
19
|
+
permission_factory.build!
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def user
|
25
|
+
ability.user
|
26
|
+
end
|
27
|
+
|
28
|
+
def permission_factory
|
29
|
+
@permission_factory ||= CanTango::PermissionEngine::Factory.new ability
|
30
|
+
end
|
6
31
|
end
|
7
32
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module CanTango
|
2
|
-
|
2
|
+
class PermissionEngine < Engine
|
3
3
|
class Collector
|
4
4
|
attr_reader :ability, :permissions, :type
|
5
5
|
|
@@ -10,7 +10,7 @@ module CanTango
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def build
|
13
|
-
relevant_rules.inject([]){|evaluators, (name, rules)|
|
13
|
+
relevant_rules.inject([]){|evaluators, (name, rules)|
|
14
14
|
evaluators << CanTango::PermissionEngine::Evaluator.new(ability, rules)
|
15
15
|
}
|
16
16
|
end
|
@@ -35,6 +35,11 @@ module CanTango
|
|
35
35
|
ability.user
|
36
36
|
end
|
37
37
|
|
38
|
+
def user_account
|
39
|
+
ability.user_account
|
40
|
+
end
|
41
|
+
alias_method :account, :user_account
|
42
|
+
|
38
43
|
def user_key_field
|
39
44
|
ability.user_key_field
|
40
45
|
end
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module CanTango
|
2
|
-
|
2
|
+
class PermissionEngine < Engine
|
3
3
|
class Compiler
|
4
4
|
attr_reader :permission, :categories
|
5
5
|
|
@@ -36,7 +36,14 @@ module CanTango
|
|
36
36
|
statements(method)
|
37
37
|
end
|
38
38
|
|
39
|
+
# TODO: make cleaner!
|
40
|
+
def check_actions method
|
41
|
+
permission_actions = permission.static_rules.send(method).keys.to_symbols
|
42
|
+
raise "valid actions are: #{valid_actions}" if (permission_actions - valid_actions).size > 0
|
43
|
+
end
|
44
|
+
|
39
45
|
def statements method
|
46
|
+
check_actions method
|
40
47
|
valid_actions.map do |action|
|
41
48
|
statements_string(method, :action => action)
|
42
49
|
end.compact.join("\n")
|
@@ -1,10 +1,6 @@
|
|
1
|
-
require 'sugar-high/class_ext'
|
2
|
-
|
3
1
|
module CanTango
|
4
|
-
|
2
|
+
class PermissionEngine < Engine
|
5
3
|
class Factory
|
6
|
-
include ClassExt
|
7
|
-
|
8
4
|
attr_accessor :ability
|
9
5
|
|
10
6
|
# creates the factory for the ability
|
@@ -31,29 +27,29 @@ module CanTango
|
|
31
27
|
end
|
32
28
|
|
33
29
|
def store
|
34
|
-
store_class.new :
|
30
|
+
store_class.new :permissions, store_options
|
35
31
|
end
|
36
32
|
|
37
33
|
def store_class
|
38
|
-
|
34
|
+
permission_engine.store.default_class
|
39
35
|
end
|
40
36
|
|
41
37
|
def store_options
|
42
|
-
|
38
|
+
permission_engine.store.options.merge(:path => config_path)
|
43
39
|
end
|
44
40
|
|
45
41
|
def permission_types
|
46
|
-
|
42
|
+
permission_engine.types
|
47
43
|
end
|
48
44
|
|
49
45
|
def config_path
|
50
|
-
|
46
|
+
permission_engine.config_path
|
51
47
|
end
|
52
48
|
|
53
49
|
private
|
54
50
|
|
55
|
-
def
|
56
|
-
CanTango.config.
|
51
|
+
def permission_engine
|
52
|
+
CanTango.config.permission_engine
|
57
53
|
end
|
58
54
|
end
|
59
55
|
end
|