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
@@ -0,0 +1,13 @@
|
|
1
|
+
class <%= account.to_s.camelize %>AccountPermit < CanTango::AccountPermit
|
2
|
+
def initialize ability
|
3
|
+
super
|
4
|
+
end
|
5
|
+
|
6
|
+
protected
|
7
|
+
|
8
|
+
def permit_rules
|
9
|
+
# insert your can, cannot and any other rule statements here
|
10
|
+
<%= permit_logic.strip %>
|
11
|
+
<%= license_logic %>
|
12
|
+
end
|
13
|
+
end
|
@@ -1,23 +1,14 @@
|
|
1
|
-
require '
|
2
|
-
require 'sugar-high/array'
|
3
|
-
require 'active_support/inflector'
|
4
|
-
require 'rails_artifactor'
|
1
|
+
require 'generators/cantango/basic'
|
5
2
|
|
6
|
-
module
|
3
|
+
module Cantango
|
7
4
|
module Generators
|
8
5
|
class Base < ::Rails::Generators::Base
|
9
|
-
def self.inherited(subclass)
|
10
|
-
subclass.extend ClassMethods
|
11
|
-
end
|
12
6
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
end
|
17
|
-
end
|
18
|
-
extend ClassMethods
|
7
|
+
include Cantango::Generators::Basic
|
8
|
+
|
9
|
+
CAN_ACTIONS = [:create, :update, :manage, :read, :access]
|
19
10
|
|
20
|
-
|
11
|
+
CAN_ACTIONS.each do |action|
|
21
12
|
class_eval %{
|
22
13
|
class_option :#{action}, :type => :array, :default => [], :desc => "Models allowed to #{action}"
|
23
14
|
}
|
@@ -25,7 +16,13 @@ module CanTango
|
|
25
16
|
|
26
17
|
protected
|
27
18
|
|
28
|
-
|
19
|
+
[:user, :account].each do |name|
|
20
|
+
define_method :"#{name}?" do
|
21
|
+
false
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
CAN_ACTIONS.each do |action|
|
29
26
|
class_eval %{
|
30
27
|
def #{action}
|
31
28
|
options[:#{action}]
|
@@ -34,11 +31,11 @@ module CanTango
|
|
34
31
|
end
|
35
32
|
|
36
33
|
def rules_logic
|
37
|
-
|
34
|
+
CAN_ACTIONS.map do |action|
|
38
35
|
send(action).map do |c|
|
39
36
|
"can(:#{action}, #{act_model(c)})"
|
40
37
|
end.join("\n ")
|
41
|
-
end.join("\n
|
38
|
+
end.join("\n")
|
42
39
|
end
|
43
40
|
|
44
41
|
def act_model name
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Cantango
|
2
|
+
module Generators
|
3
|
+
module Basic
|
4
|
+
def rules_logic
|
5
|
+
''
|
6
|
+
end
|
7
|
+
|
8
|
+
def license_logic
|
9
|
+
''
|
10
|
+
end
|
11
|
+
|
12
|
+
def base_logic
|
13
|
+
%{
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
def admin_logic
|
18
|
+
%{
|
19
|
+
can :manage, :all
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
def guest_logic
|
24
|
+
%{
|
25
|
+
can :read, :all
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def account
|
30
|
+
options[:account]
|
31
|
+
end
|
32
|
+
|
33
|
+
[:is_user, :is_account, :is_group].each do |name|
|
34
|
+
define_method :"#{name}?" do
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Cantango
|
2
|
+
module Generators
|
3
|
+
class InstallGenerator < Rails::Generators::Base
|
4
|
+
desc "Add role strategy to a User model"
|
5
|
+
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
class_option :categories, :type => :boolean, :default => true, :desc => "Create categories"
|
9
|
+
class_option :permissions, :type => :boolean, :default => true, :desc => "Create yaml permissions store"
|
10
|
+
|
11
|
+
def copy_initializer
|
12
|
+
template "cantango.rb", "config/initializers/cantango.rb"
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_categories
|
16
|
+
return unless categories?
|
17
|
+
template "categories.yml", "config/categories.yml"
|
18
|
+
end
|
19
|
+
|
20
|
+
def copy_permissions
|
21
|
+
return unless permissions?
|
22
|
+
template "permissions.yml", "config/permissions.yml"
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
|
27
|
+
def permissions?
|
28
|
+
options[:permissions]
|
29
|
+
end
|
30
|
+
|
31
|
+
def categories?
|
32
|
+
options[:categories]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
File without changes
|
@@ -1,17 +1,12 @@
|
|
1
|
-
require 'rails/generators/base'
|
2
|
-
require 'sugar-high/array'
|
3
|
-
require 'active_support/inflector'
|
4
|
-
require 'rails_artifactor'
|
5
|
-
|
6
1
|
require 'generators/cantango/base'
|
7
2
|
require 'generators/cantango/license_base'
|
8
3
|
|
9
|
-
module
|
4
|
+
module Cantango
|
10
5
|
module Generators
|
11
|
-
class LicenseGenerator <
|
6
|
+
class LicenseGenerator < Cantango::Generators::Base
|
12
7
|
desc "Creates a License for a Permit in 'app/licenses' with reusable permissions"
|
13
8
|
|
14
|
-
argument :name, :type => :string, :
|
9
|
+
argument :name, :type => :string, :desc => "Name of license"
|
15
10
|
|
16
11
|
class_option :licenses, :type => :array, :default => [], :desc => "Sub licenses"
|
17
12
|
|
@@ -25,10 +20,10 @@ module CanTango
|
|
25
20
|
protected
|
26
21
|
|
27
22
|
def create_license
|
28
|
-
template "license.erb", "app/licenses/#{name}_license.rb"
|
23
|
+
template "license.erb", "app/permits/licenses/#{name}_license.rb"
|
29
24
|
end
|
30
25
|
|
31
|
-
include
|
32
|
-
|
26
|
+
include Cantango::Generators::LicenseBase
|
27
|
+
end
|
33
28
|
end
|
34
29
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module Cantango
|
2
2
|
module Generators
|
3
3
|
module LicenseBase
|
4
4
|
def licenses
|
@@ -6,7 +6,7 @@ module CanTango
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def license_logic
|
9
|
-
return '' if licenses.empty?
|
9
|
+
return ' # use any licenses here' if licenses.empty?
|
10
10
|
ls = licenses.map{|c| ":#{c}"}.join(", ")
|
11
11
|
"licenses #{ls}"
|
12
12
|
end
|
@@ -1,14 +1,9 @@
|
|
1
|
-
|
2
|
-
require 'sugar-high/array'
|
3
|
-
require 'active_support/inflector'
|
4
|
-
require 'rails_artifactor'
|
5
|
-
|
6
|
-
module CanTango
|
1
|
+
module Cantango
|
7
2
|
module Generators
|
8
3
|
class LicensesGenerator < Rails::Generators::Base
|
9
4
|
desc "Creates Licenses for use with CanCan Permits"
|
10
5
|
|
11
|
-
argument :licenses, :type => :array, :
|
6
|
+
argument :licenses, :type => :array, :desc => "Licenses"
|
12
7
|
|
13
8
|
source_root File.dirname(__FILE__) + '/../license/templates'
|
14
9
|
|
@@ -1,18 +1,28 @@
|
|
1
|
-
|
1
|
+
require 'generators/cantango/basic'
|
2
|
+
|
3
|
+
module Cantango
|
2
4
|
module Generators
|
3
5
|
module PermitGenerator
|
6
|
+
attr_accessor :permit_name, :permit_logic
|
7
|
+
|
8
|
+
include Cantango::Generators::Basic
|
9
|
+
|
10
|
+
def template_permit name, account = nil
|
11
|
+
@permit_name = name
|
12
|
+
set_logic name
|
13
|
+
account.present? ? template_account_permit(name, account) : template_simple_permit(name)
|
14
|
+
end
|
4
15
|
|
5
|
-
def
|
6
|
-
|
7
|
-
template permit_source, "app/permits/#{permit_target(role)}" unless account
|
16
|
+
def template_simple_permit name
|
17
|
+
template permit_source, "app/permits/#{permit_target(name)}"
|
8
18
|
end
|
9
19
|
|
10
|
-
def template_account_permit
|
11
|
-
template "account_permit.erb" , "app/permits/#{account}
|
20
|
+
def template_account_permit name, account
|
21
|
+
template "account_permit.erb" , "app/permits/#{account}/#{permit_target(name)}"
|
12
22
|
end
|
13
23
|
|
14
24
|
def load_permit_template name
|
15
|
-
template = ERB.new File.open(template_filepath).read
|
25
|
+
template = ERB.new File.open(template_filepath).read.gsub(/\n/, "\n\s\s")
|
16
26
|
template.result(binding)
|
17
27
|
end
|
18
28
|
|
@@ -25,11 +35,22 @@ module CanTango
|
|
25
35
|
end
|
26
36
|
|
27
37
|
def permit_source
|
28
|
-
|
38
|
+
return "user_permit.erb" if is_user?
|
39
|
+
return "account_permit.erb" if is_account?
|
40
|
+
|
41
|
+
is_group? ? "role_group_permit.erb" : "role_permit.erb"
|
42
|
+
end
|
43
|
+
|
44
|
+
def permit_target name
|
45
|
+
return "#{name}_permit.rb" if is_user?
|
46
|
+
return "#{name}_account_permit.rb" if is_account?
|
47
|
+
|
48
|
+
is_group? ? "#{name}_role_group_permit.rb" : "#{name}_role_permit.rb"
|
29
49
|
end
|
30
50
|
|
31
|
-
def
|
32
|
-
|
51
|
+
def set_logic name
|
52
|
+
meth = "#{name}_logic"
|
53
|
+
@permit_logic = respond_to?(meth) ? send(meth) : base_logic
|
33
54
|
end
|
34
55
|
end
|
35
56
|
end
|
@@ -1,21 +1,17 @@
|
|
1
|
-
require 'rails/generators/base'
|
2
|
-
require 'sugar-high/array'
|
3
|
-
require 'active_support/inflector'
|
4
|
-
require 'rails_artifactor'
|
5
|
-
# require 'logging_assist'
|
6
|
-
#
|
7
1
|
require 'generators/cantango/base'
|
8
2
|
require 'generators/cantango/license_base'
|
9
3
|
require 'generators/cantango/permit_generator'
|
10
4
|
|
11
|
-
module
|
5
|
+
module Cantango
|
12
6
|
module Generators
|
13
|
-
class RolePermitGenerator <
|
7
|
+
class RolePermitGenerator < Cantango::Generators::Base
|
14
8
|
desc "Creates a Permit for a role in 'app/permits' with specific permissions and/or licenses"
|
15
9
|
|
16
|
-
argument :role, :type => :string,
|
10
|
+
argument :role, :type => :string,
|
11
|
+
:desc => "Role to create permit for"
|
17
12
|
|
18
|
-
class_option :licenses, :type => :array, :default => [],
|
13
|
+
class_option :licenses, :type => :array, :default => [],
|
14
|
+
:desc => "Licenses to use in Permit"
|
19
15
|
|
20
16
|
class_option :account, :type => :string,
|
21
17
|
:desc => "Generate permits for a specific user account"
|
@@ -25,16 +21,17 @@ module CanTango
|
|
25
21
|
source_root File.dirname(__FILE__) + '/templates'
|
26
22
|
|
27
23
|
def main_flow
|
28
|
-
return if role.empty?
|
29
24
|
template_permit role
|
30
25
|
end
|
31
26
|
|
32
27
|
protected
|
33
28
|
|
34
|
-
include
|
35
|
-
include
|
29
|
+
include Cantango::Generators::LicenseBase
|
30
|
+
include Cantango::Generators::PermitGenerator
|
36
31
|
|
37
|
-
|
32
|
+
alias_method :role_group, :role
|
33
|
+
|
34
|
+
def is_group?
|
38
35
|
options[:group]
|
39
36
|
end
|
40
37
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= permit_name.to_s.camelize %>RoleGroupPermit < CanTango::RoleGroupPermit
|
2
2
|
def initialize ability
|
3
3
|
super
|
4
4
|
end
|
@@ -7,7 +7,7 @@ class <%= role_group.to_s.camelize %>RoleGroupPermit < CanTango::PermitEngine::R
|
|
7
7
|
|
8
8
|
def permit_rules
|
9
9
|
# insert your can, cannot and any other rule statements here
|
10
|
-
<%=
|
10
|
+
<%= rules_logic.strip %>
|
11
11
|
<%= license_logic %>
|
12
12
|
end
|
13
13
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
class <%=
|
1
|
+
class <%= permit_name.to_s.camelize %>RolePermit < CanTango::RolePermit
|
2
2
|
def initialize ability
|
3
3
|
super
|
4
4
|
end
|
@@ -7,7 +7,7 @@ class <%= role.to_s.camelize %>RolePermit < CanTango::PermitEngine::RolePermit
|
|
7
7
|
|
8
8
|
def permit_rules
|
9
9
|
# insert your can, cannot and any other rule statements here
|
10
|
-
<%=
|
10
|
+
<%= rules_logic.strip %>
|
11
11
|
<%= license_logic %>
|
12
12
|
end
|
13
13
|
end
|
@@ -1,26 +1,15 @@
|
|
1
|
-
require '
|
2
|
-
require 'sugar-high/array'
|
3
|
-
require 'active_support/inflector'
|
4
|
-
require 'rails_artifactor'
|
5
|
-
# require 'logging_assist'
|
1
|
+
require 'generators/cantango/permit_generator'
|
6
2
|
|
7
|
-
module
|
3
|
+
module Cantango
|
8
4
|
module Generators
|
9
|
-
class
|
5
|
+
class RolePermitsGenerator < Rails::Generators::Base
|
10
6
|
desc "Creates a Permit for each role in 'app/permits' and ensures that the permit folder is added to Rails load path."
|
11
7
|
|
12
|
-
argument :roles, :type => :array,
|
8
|
+
argument :roles, :type => :array,
|
13
9
|
:desc => "Roles to create permits for"
|
14
10
|
|
15
|
-
|
16
|
-
|
17
|
-
:desc => "ORM to use"
|
18
|
-
|
19
|
-
class_option :initializer, :type => :boolean, :default => true,
|
20
|
-
:desc => "Create Permits initializer"
|
21
|
-
|
22
|
-
class_option :default_permits, :type => :boolean, :default => true,
|
23
|
-
:desc => "Create default permits for guest and admin roles"
|
11
|
+
class_option :special_permits, :type => :boolean, :default => false,
|
12
|
+
:desc => "Create special permits Syatem and Any"
|
24
13
|
|
25
14
|
class_option :account, :type => :string,
|
26
15
|
:desc => "Generate permits for a specific user account"
|
@@ -31,96 +20,25 @@ module CanTango
|
|
31
20
|
source_root File.dirname(__FILE__) + '/../role_permit/templates'
|
32
21
|
|
33
22
|
def main_flow
|
34
|
-
|
35
|
-
|
36
|
-
end
|
37
|
-
|
38
|
-
template_permit :any
|
39
|
-
template_permit :system
|
40
|
-
|
41
|
-
permit_logic = base_logic
|
42
|
-
get_roles.each do |role|
|
43
|
-
template_permit(role) if !skip_permit?(role)
|
44
|
-
end
|
45
|
-
|
46
|
-
permits_initializer if permits_initializer?
|
23
|
+
create_special_permits if special_permits?
|
24
|
+
create_permits
|
47
25
|
end
|
48
26
|
|
49
27
|
protected
|
50
28
|
|
51
|
-
include PermitGenerator
|
52
|
-
|
53
|
-
extend RailsAssist::UseMacro
|
54
|
-
|
55
|
-
use_helpers :app, :file, :special
|
56
|
-
|
57
|
-
attr_accessor :permit_name, :permit_logic
|
58
|
-
|
59
|
-
def default_roles
|
60
|
-
[:guest, :admin]
|
61
|
-
end
|
62
|
-
|
63
|
-
def permits_initializer?
|
64
|
-
options[:initializer]
|
65
|
-
end
|
66
|
-
|
67
|
-
def skip_permit? permit
|
68
|
-
default_permits? && default_roles.include?(permit.to_sym)
|
69
|
-
end
|
70
|
-
|
71
|
-
|
72
|
-
# TODO: merge with any registered roles in application
|
73
|
-
def get_roles
|
74
|
-
roles.uniq.to_symbols
|
75
|
-
end
|
76
|
-
|
77
|
-
def default_permits?
|
78
|
-
options[:default_permits]
|
79
|
-
end
|
80
|
-
|
81
|
-
def orm
|
82
|
-
options[:orm]
|
83
|
-
end
|
84
|
-
|
85
|
-
def permits_initializer
|
86
|
-
create_initializer :permits do
|
87
|
-
%Q{CanTango.configure do |config|
|
88
|
-
config.orm = :#{orm}
|
89
|
-
end
|
90
|
-
}
|
91
|
-
end
|
92
|
-
end
|
93
|
-
|
94
|
-
def template_permit role, template_name=nil
|
95
|
-
if permit_roles.include?(role)
|
96
|
-
meth = "#{role}_logic"
|
97
|
-
self.permit_logic = respond_to?(meth) ? send(meth) : base_logic
|
98
|
-
end
|
99
|
-
self.permit_name = role
|
100
|
-
template_permit role
|
101
|
-
end
|
102
|
-
|
103
|
-
private
|
29
|
+
include Cantango::Generators::PermitGenerator
|
104
30
|
|
105
|
-
def
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
def base_logic
|
110
|
-
%{
|
111
|
-
}
|
31
|
+
def create_special_permits
|
32
|
+
template_permit :any
|
33
|
+
template_permit :system
|
112
34
|
end
|
113
35
|
|
114
|
-
def
|
115
|
-
|
116
|
-
can :manage, :all
|
117
|
-
}
|
36
|
+
def create_permits
|
37
|
+
roles.each { |role| template_permit role }
|
118
38
|
end
|
119
39
|
|
120
|
-
def
|
121
|
-
|
122
|
-
can :read, :all
|
123
|
-
}
|
40
|
+
def special_permits?
|
41
|
+
options[:special_permits]
|
124
42
|
end
|
125
43
|
end
|
126
44
|
end
|