hancock_cms 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (182) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.rspec +1 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/Gemfile +4 -0
  7. data/LICENSE.txt +22 -0
  8. data/README.md +113 -0
  9. data/Rakefile +1 -0
  10. data/app/assets/images/devices/login-bg.jpg +0 -0
  11. data/app/assets/images/rails-admin/hancock_logo.svg +5 -0
  12. data/app/assets/javascripts/hancock/app/back_to_top.coffee +24 -0
  13. data/app/assets/javascripts/hancock/cms.coffee +11 -0
  14. data/app/assets/javascripts/hancock/cms/flash.coffee +3 -0
  15. data/app/assets/javascripts/hancock/cms/init.coffee +1 -0
  16. data/app/assets/javascripts/hancock/cms/map.coffee +22 -0
  17. data/app/assets/javascripts/hancock/rails_admin/cms.ui.coffee +43 -0
  18. data/app/assets/javascripts/hancock/rails_admin/custom/ui.coffee +0 -0
  19. data/app/assets/javascripts/head.load.js +707 -0
  20. data/app/assets/javascripts/jquery.placeholder.js +157 -0
  21. data/app/assets/javascripts/rails_admin/custom/ui.coffee +2 -0
  22. data/app/assets/stylesheets/hancock/cms.sass +9 -0
  23. data/app/assets/stylesheets/hancock/cms/devise.sass +157 -0
  24. data/app/assets/stylesheets/hancock/cms/flash.sass +69 -0
  25. data/app/assets/stylesheets/hancock/cms/mixins.sass +98 -0
  26. data/app/assets/stylesheets/hancock/cms/normalize.scss +407 -0
  27. data/app/assets/stylesheets/hancock/cms/powered.sass +18 -0
  28. data/app/assets/stylesheets/hancock/rails_admin/cms.theming.sass +703 -0
  29. data/app/assets/stylesheets/hancock/rails_admin/custom/theming.sass +1 -0
  30. data/app/assets/stylesheets/hancock/toplink/toplink.sass +24 -0
  31. data/app/assets/stylesheets/rails_admin/custom/theming.sass +4 -0
  32. data/app/controllers/concerns/hancock/current_user.rb +12 -0
  33. data/app/controllers/concerns/hancock/decorators/home.rb +12 -0
  34. data/app/controllers/concerns/hancock/decorators/registrations.rb +5 -0
  35. data/app/controllers/concerns/hancock/decorators/sessions.rb +5 -0
  36. data/app/controllers/concerns/hancock/errors.rb +94 -0
  37. data/app/controllers/concerns/hancock/fancybox.rb +14 -0
  38. data/app/controllers/concerns/hancock/no_cache.rb +12 -0
  39. data/app/controllers/hancock/home_controller.rb +10 -0
  40. data/app/controllers/hancock/registrations_controller.rb +23 -0
  41. data/app/controllers/hancock/sessions_controller.rb +24 -0
  42. data/app/helpers/hancock/gzip_helper.rb +27 -0
  43. data/app/helpers/hancock/home_helper.rb +2 -0
  44. data/app/helpers/hancock/powered_helper.rb +42 -0
  45. data/app/models/concerns/hancock/boolean_field.rb +21 -0
  46. data/app/models/concerns/hancock/cacheable.rb +33 -0
  47. data/app/models/concerns/hancock/decorators/embedded_element.rb +28 -0
  48. data/app/models/concerns/hancock/enableable.rb +8 -0
  49. data/app/models/concerns/hancock/geocodeable.rb +4 -0
  50. data/app/models/concerns/hancock/hash_field.rb +113 -0
  51. data/app/models/concerns/hancock/html_field.rb +33 -0
  52. data/app/models/concerns/hancock/mappable.rb +91 -0
  53. data/app/models/concerns/hancock/model_localizeable.rb +33 -0
  54. data/app/models/concerns/hancock/rails_admin_patch.rb +86 -0
  55. data/app/models/concerns/hancock/sort_field.rb +20 -0
  56. data/app/models/concerns/hancock/sortable.rb +8 -0
  57. data/app/models/hancock/embedded_element.rb +17 -0
  58. data/app/views/blocks/_favicon.html.slim +60 -0
  59. data/app/views/blocks/_footer.html.slim +1 -0
  60. data/app/views/blocks/_header.html.slim +3 -0
  61. data/app/views/devise/passwords/edit.html.slim +29 -0
  62. data/app/views/devise/passwords/new.html.slim +19 -0
  63. data/app/views/devise/registrations/edit.html.slim +31 -0
  64. data/app/views/devise/registrations/new.html.slim +39 -0
  65. data/app/views/devise/sessions/new.html.slim +39 -0
  66. data/app/views/devise/shared/_links.html.slim +11 -0
  67. data/app/views/hancock/errors/_base.html.slim +3 -0
  68. data/app/views/hancock/errors/error_403.html.slim +1 -0
  69. data/app/views/hancock/errors/error_404.html.slim +1 -0
  70. data/app/views/hancock/errors/error_500.html.slim +1 -0
  71. data/app/views/hancock/home/index.html.slim +1 -0
  72. data/app/views/hancock/simple_captcha/_simple_captcha.html.slim +13 -0
  73. data/app/views/hancock/toplink/_toplink.html.slim +2 -0
  74. data/app/views/layouts/application.html.slim +35 -0
  75. data/app/views/layouts/hancock/devise/confirmations.html.slim +22 -0
  76. data/app/views/layouts/hancock/devise/passwords.html.slim +22 -0
  77. data/app/views/layouts/hancock/devise/registrations.html.slim +22 -0
  78. data/app/views/layouts/hancock/devise/sessions.html.slim +22 -0
  79. data/app/views/layouts/hancock/devise/unlocks.html.slim +22 -0
  80. data/app/views/layouts/rails_admin/_footer.html.slim +2 -0
  81. data/app/views/layouts/rails_admin/_footer_navigation.html.slim +20 -0
  82. data/app/views/layouts/rails_admin/_navigation.html.slim +73 -0
  83. data/app/views/layouts/rails_admin/_secondary_navigation.html.slim +32 -0
  84. data/app/views/layouts/rails_admin/application.html.haml +68 -0
  85. data/app/views/layouts/rails_admin/pjax.html.haml +17 -0
  86. data/app/views/rails_admin/main/_check_boxes.html.slim +27 -0
  87. data/app/views/rails_admin/main/_enum_check_boxes.html.slim +5 -0
  88. data/app/views/rails_admin/main/_enum_radio_buttons.html.slim +5 -0
  89. data/app/views/rails_admin/main/_form_hancock_multiselect.html.slim +48 -0
  90. data/app/views/rails_admin/main/_form_raw.html.slim +1 -0
  91. data/app/views/rails_admin/main/_hancock_hash.html.slim +9 -0
  92. data/app/views/rails_admin/main/_hancock_hash_ml.html.slim +10 -0
  93. data/app/views/rails_admin/main/_hancock_html.html.slim +16 -0
  94. data/app/views/rails_admin/main/_hancock_html_ml.html.slim +53 -0
  95. data/app/views/shared/_admin_link.html.slim +3 -0
  96. data/app/views/shared/_messages.html.slim +7 -0
  97. data/config/initializers/embedded_findable.rb +57 -0
  98. data/config/initializers/hancock_cms.rb +11 -0
  99. data/config/initializers/simple_captcha.rb +70 -0
  100. data/config/locales/en.hancock.yml +29 -0
  101. data/config/locales/en.hancock_admin.yml +6 -0
  102. data/config/locales/ru.cancan.yml +4 -0
  103. data/config/locales/ru.devise.yml +65 -0
  104. data/config/locales/ru.hancock.yml +36 -0
  105. data/config/locales/ru.hancock_admin.yml +6 -0
  106. data/config/locales/ru.models.yml +82 -0
  107. data/config/locales/ru.mongoid.yml +450 -0
  108. data/config/locales/ru.rails_admin.yml +168 -0
  109. data/hancock_cms.gemspec +46 -0
  110. data/lib/filename_to_slug.rb +32 -0
  111. data/lib/generators/hancock/cms/ability_generator.rb +14 -0
  112. data/lib/generators/hancock/cms/admin_generator.rb +21 -0
  113. data/lib/generators/hancock/cms/application_generator.rb +14 -0
  114. data/lib/generators/hancock/cms/assets_generator.rb +35 -0
  115. data/lib/generators/hancock/cms/config_generator.rb +13 -0
  116. data/lib/generators/hancock/cms/controllers/decorators_generator.rb +27 -0
  117. data/lib/generators/hancock/cms/gemfile_generator.rb +13 -0
  118. data/lib/generators/hancock/cms/layout_generator.rb +14 -0
  119. data/lib/generators/hancock/cms/model_generator.rb +39 -0
  120. data/lib/generators/hancock/cms/models/embedded_element_generator.rb +56 -0
  121. data/lib/generators/hancock/cms/models/templates/embedded_element.erb +47 -0
  122. data/lib/generators/hancock/cms/paperclip_optimizer_generator.rb +13 -0
  123. data/lib/generators/hancock/cms/rack_generator.rb +12 -0
  124. data/lib/generators/hancock/cms/robots_generator.rb +14 -0
  125. data/lib/generators/hancock/cms/scripts_generator.rb +31 -0
  126. data/lib/generators/hancock/cms/templates/Gemfile.erb +69 -0
  127. data/lib/generators/hancock/cms/templates/ability.erb +49 -0
  128. data/lib/generators/hancock/cms/templates/admin.erb +74 -0
  129. data/lib/generators/hancock/cms/templates/application.erb +42 -0
  130. data/lib/generators/hancock/cms/templates/assets/javascripts/application.coffee.erb +5 -0
  131. data/lib/generators/hancock/cms/templates/assets/stylesheets/application.sass.erb +88 -0
  132. data/lib/generators/hancock/cms/templates/hancock_cms.erb +30 -0
  133. data/lib/generators/hancock/cms/templates/model.erb +42 -0
  134. data/lib/generators/hancock/cms/templates/paperclip_optimizer.erb +80 -0
  135. data/lib/generators/hancock/cms/templates/rack.erb +15 -0
  136. data/lib/generators/hancock/cms/templates/robots.txt.erb +5 -0
  137. data/lib/generators/hancock/cms/templates/scripts/assets_precompile.sh +3 -0
  138. data/lib/generators/hancock/cms/templates/scripts/bundle_production.sh +4 -0
  139. data/lib/generators/hancock/cms/templates/scripts/db_dump.sh.erb +3 -0
  140. data/lib/generators/hancock/cms/templates/scripts/db_restore.sh +3 -0
  141. data/lib/generators/hancock/cms/templates/scripts/full_assets_precompile.sh +4 -0
  142. data/lib/generators/hancock/cms/templates/scripts/restart_thru_kill.sh +3 -0
  143. data/lib/generators/hancock/cms/templates/scripts/send_hup.sh +3 -0
  144. data/lib/generators/hancock/cms/templates/scripts/send_usr2.sh +3 -0
  145. data/lib/generators/hancock/cms/templates/scripts/server.sh +5 -0
  146. data/lib/generators/hancock/cms/templates/scripts/server_alt.sh +5 -0
  147. data/lib/generators/hancock/cms/templates/unicorn.erb +57 -0
  148. data/lib/generators/hancock/cms/templates/unicorn.god.erb +59 -0
  149. data/lib/generators/hancock/cms/unicorn_god_generator.rb +15 -0
  150. data/lib/generators/hancock/cms/utils.rb +21 -0
  151. data/lib/hancock/admin.rb +60 -0
  152. data/lib/hancock/admin/embedded_element.rb +26 -0
  153. data/lib/hancock/configuration.rb +48 -0
  154. data/lib/hancock/controller.rb +30 -0
  155. data/lib/hancock/engine.rb +48 -0
  156. data/lib/hancock/migration.rb +15 -0
  157. data/lib/hancock/model.rb +53 -0
  158. data/lib/hancock/models/embedded_element.rb +12 -0
  159. data/lib/hancock/models/mongoid/embedded_element.rb +14 -0
  160. data/lib/hancock/plugin.rb +25 -0
  161. data/lib/hancock/plugin_configuration.rb +30 -0
  162. data/lib/hancock/rails_admin_ext/config.rb +129 -0
  163. data/lib/hancock/rails_admin_ext/hancock_hash.rb +84 -0
  164. data/lib/hancock/rails_admin_ext/hancock_html.rb +79 -0
  165. data/lib/hancock/rails_admin_ext/hancock_multiselect.rb +44 -0
  166. data/lib/hancock/rails_admin_ext/hancock_slugs.rb +35 -0
  167. data/lib/hancock/rails_admin_ext/patches/field_patch.rb +14 -0
  168. data/lib/hancock/rails_admin_ext/patches/group_patch.rb +41 -0
  169. data/lib/hancock/rails_admin_ext/patches/hancock_cms_group.rb +61 -0
  170. data/lib/hancock/rails_admin_ext/patches/new_controller_patch.rb +54 -0
  171. data/lib/hancock/routes.rb +20 -0
  172. data/lib/hancock/simple_form_patch.rb +12 -0
  173. data/lib/hancock/tasks.rb +13 -0
  174. data/lib/hancock/version.rb +3 -0
  175. data/lib/hancock_cms.rb +130 -0
  176. data/lib/manual_slug.rb +10 -0
  177. data/lib/manual_slug/active_record.rb +32 -0
  178. data/lib/manual_slug/mongoid.rb +40 -0
  179. data/lib/rails_admin/custom_show_in_app.rb +43 -0
  180. data/release.sh +12 -0
  181. data/template.rb +564 -0
  182. metadata +455 -0
@@ -0,0 +1,26 @@
1
+ module Hancock
2
+ module Admin
3
+ module EmbeddedElement
4
+ def self.config(nav_label = nil, fields = {})
5
+ if nav_label.is_a?(Hash)
6
+ nav_label, fields = nil, nav_label
7
+ end
8
+ Proc.new {
9
+ navigation_label(nav_label || I18n.t('hancock.cms'))
10
+ field :enabled, :toggle do
11
+ searchable false
12
+ end
13
+ field :name, :string do
14
+ searchable true
15
+ end
16
+
17
+ Hancock::RailsAdminGroupPatch::hancock_cms_group(self, fields)
18
+
19
+ if block_given?
20
+ yield self
21
+ end
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,48 @@
1
+ module Hancock
2
+ include Hancock::PluginConfiguration
3
+
4
+ def self.config_class
5
+ Configuration
6
+ end
7
+
8
+ def self.configure
9
+ yield configuration
10
+ Hancock::PLUGINS.map(&:reconfigure!)
11
+ end
12
+
13
+
14
+ class Configuration
15
+ attr_accessor :main_index_layout
16
+ attr_accessor :error_layout
17
+
18
+ attr_accessor :localize
19
+
20
+ attr_accessor :ability_manager_config
21
+ attr_accessor :ability_admin_config
22
+
23
+ attr_accessor :admin_enter_captcha
24
+ attr_accessor :registration_captcha
25
+ attr_accessor :recaptcha_support
26
+ attr_accessor :simple_captcha_support
27
+
28
+ attr_accessor :captcha_on_development
29
+
30
+ def initialize
31
+ @main_index_layout = 'application'
32
+ @error_layout = 'application'
33
+
34
+ @localize = false
35
+
36
+ @ability_manager_config = []
37
+ @ability_admin_config = []
38
+
39
+ @recaptcha_support = defined?(Recaptcha)
40
+ @simple_captcha_support = defined?(SimpleCaptcha)
41
+
42
+ @admin_enter_captcha = @recaptcha_support or @simple_captcha_support
43
+ @registration_captcha = @admin_enter_captcha
44
+
45
+ @captcha_on_development = false
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,30 @@
1
+ module Hancock::Controller
2
+ extend ActiveSupport::Concern
3
+ included do
4
+ include Hancock::Errors
5
+ include Hancock::Fancybox
6
+ if defined?(Hancock::Pages)
7
+ include Hancock::Pages::SeoPages
8
+ include Hancock::Pages::NavMenu
9
+ include Hancock::Pages::Blocksetable
10
+ end
11
+ protect_from_forgery with: :exception
12
+ helper_method :page_title
13
+ helper_method :hide_ym_ga
14
+ end
15
+
16
+ protected
17
+
18
+ def page_title
19
+ Settings ? Settings.default_title : "" #temp
20
+ end
21
+
22
+ def ckeditor_authenticate
23
+ redirect_to '/' unless user_signed_in? && current_user.has_role?('admin')
24
+ end
25
+
26
+
27
+ def hide_ym_ga
28
+ false
29
+ end
30
+ end
@@ -0,0 +1,48 @@
1
+ module Hancock
2
+ class Engine < ::Rails::Engine
3
+ # isolate_namespace Hancock
4
+
5
+ # rake_tasks do
6
+ # require File.expand_path('../tasks', __FILE__)
7
+ # end
8
+
9
+ initializer "hancock_cms.email_defaults" do
10
+ # Write default email settings to DB so they can be changed.
11
+
12
+ #temp
13
+ # begin
14
+ # if Settings and Settings.table_exists?
15
+ # Settings.default_email_from(default: 'noreply@site.domain')
16
+ # Settings.form_email(default: 'admin@site.domain')
17
+ # Settings.email_topic(default: 'с сайта')
18
+ # end
19
+ # rescue
20
+ # end
21
+ end
22
+ initializer 'hancock_cms.paperclip' do
23
+ # require 'paperclip/style'
24
+ # module ::Paperclip
25
+ # class Style
26
+ # alias_method :processor_options_without_auto_orient, :processor_options
27
+ # def processor_options
28
+ # processor_options_without_auto_orient.merge(auto_orient: false)
29
+ # end
30
+ # end
31
+ # end
32
+ end
33
+
34
+ config.after_initialize do
35
+ # trigger autoload so models are registered in Mongoid::Elasticearch
36
+ # Hancock.config.search_models.map(&:constantize)
37
+
38
+ # Write default email settings to DB so they can be changed.
39
+ if Settings and Settings.table_exists?
40
+ # Settings.default_email_from(default: 'noreply@site.domain')
41
+ # Settings.form_email(default: 'admin@site.domain')
42
+ # Settings.email_topic(default: 'с сайта')
43
+ #
44
+ Settings.logo_image(kind: :image)
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,15 @@
1
+ module Hancock
2
+ module Migration
3
+ extend self
4
+
5
+ def map_fields(t)
6
+ t.text :address
7
+ t.text :map_address
8
+ t.text :map_hint
9
+ t.float :latitude
10
+ t.float :longitude
11
+ t.float :lat
12
+ t.float :lon
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,53 @@
1
+ module Hancock
2
+ module Model
3
+ extend ActiveSupport::Concern
4
+ included do
5
+ Hancock.register_model(self)
6
+
7
+ if Hancock.mongoid?
8
+ include Mongoid::Document
9
+ include Mongoid::Timestamps::Short
10
+
11
+ if Hancock.config.localize
12
+ include Hancock::ModelLocalizeable
13
+ end
14
+
15
+ _collection_name = collection_name.to_s
16
+ if _collection_name =~ /^hancock_/
17
+ enjoy_collection_name = _collection_name.sub(/^hancock_/, 'enjoy_')
18
+ if Mongoid.client('default').collections.map(&:name).include?(enjoy_collection_name)
19
+ modules = []
20
+ self.name.sub("Hancock", "Enjoy").split("::").each do |mod|
21
+ modules << mod
22
+ eval("::#{modules.join("::")} ||= #{modules.join("::").sub("Enjoy", "Hancock")}")
23
+ end
24
+ store_in collection: enjoy_collection_name
25
+ end
26
+ end
27
+
28
+ def self.goto_hancock
29
+ end
30
+ end
31
+
32
+ include ActiveModel::ForbiddenAttributesProtection
33
+ include Hancock::BooleanField
34
+ include Hancock::SortField
35
+
36
+ if Hancock.mongoid? and defined?(RailsAdminComments)
37
+ include RailsAdminComments::Commentable
38
+ include RailsAdminComments::ModelCommentable
39
+ end
40
+
41
+ if Hancock.mongoid?
42
+ if defined?(TrackablePatch)
43
+ include TrackablePatch
44
+ elsif defined?(Trackable)
45
+ include Trackable
46
+ end
47
+ end
48
+
49
+ include Hancock::RailsAdminPatch
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,12 @@
1
+ module Hancock
2
+ module Models
3
+ module EmbeddedElement
4
+ extend ActiveSupport::Concern
5
+ include Hancock::Model
6
+ include Hancock::Enableable
7
+ include Hancock::Sortable
8
+
9
+ include Hancock.orm_specific('EmbeddedElement')
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,14 @@
1
+ module Hancock
2
+ module Models
3
+ module Mongoid
4
+ module EmbeddedElement
5
+ extend ActiveSupport::Concern
6
+
7
+ included do
8
+ field :name, type: String, localize: Hancock.configuration.localize, default: ""
9
+ end
10
+
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,25 @@
1
+ module Hancock::Plugin
2
+
3
+ module ClassMethods
4
+ def orm
5
+ Hancock.orm
6
+ end
7
+ def mongoid?
8
+ self.orm == :mongoid
9
+ end
10
+ def active_record?
11
+ self.orm == :active_record
12
+ end
13
+ def model_namespace
14
+ "#{self}::Models::#{self.orm.to_s.camelize}".freeze
15
+ end
16
+ def orm_specific(name)
17
+ "#{model_namespace}::#{name}".constantize
18
+ end
19
+ end
20
+
21
+ def self.included(base)
22
+ Hancock::register_plugin(base) unless base == Hancock
23
+ base.extend(ClassMethods)
24
+ end
25
+ end
@@ -0,0 +1,30 @@
1
+ module Hancock::PluginConfiguration
2
+
3
+ module ClassMethods
4
+ def configuration
5
+ @configuration ||= config_class.new if config_class
6
+ end
7
+ def config
8
+ @configuration ||= config_class.new if config_class
9
+ end
10
+
11
+ def configure
12
+ yield configuration
13
+ end
14
+
15
+ def reconfigure!
16
+ if config_class
17
+ @configuration = config_class.new
18
+ configure &block if block_given?
19
+ end
20
+ end
21
+
22
+ def config_class
23
+ end
24
+ end
25
+
26
+ def self.included(base)
27
+ base.extend(ClassMethods)
28
+ end
29
+
30
+ end
@@ -0,0 +1,129 @@
1
+ module Hancock
2
+ class << self
3
+ def rails_admin_configuration
4
+ @rails_admin_configuration ||= RailsAdminConfiguration.new
5
+ end
6
+ def rails_admin_config
7
+ @rails_admin_configuration ||= RailsAdminConfiguration.new
8
+ end
9
+ def rails_admin_configure
10
+ yield rails_admin_configuration
11
+ end
12
+
13
+ def action_visible_for(action_name, model_name)
14
+ rails_admin_config.action_visible_for action_name, model_name
15
+ end
16
+ def action_unvisible_for(action_name, model_name)
17
+ rails_admin_config.action_unvisible_for action_name, model_name
18
+ end
19
+
20
+ def rails_admin_config_for_actions(actions)
21
+ rails_admin_config.actions_config(actions)
22
+ end
23
+
24
+ def cancancan_admin_rules(ability_object)
25
+ rails_admin_config.cancancan_admin_rules(ability_object)
26
+ end
27
+ def cancancan_manager_rules(ability_object)
28
+ rails_admin_config.cancancan_manager_rules(ability_object)
29
+ end
30
+ end
31
+
32
+ class RailsAdminConfiguration
33
+
34
+ attr_reader :actions_list
35
+ attr_reader :actions_visibility
36
+
37
+ def initialize
38
+ @actions_list ||= []
39
+ @actions_visibility ||= {}
40
+
41
+ action_unvisible_for(:custom_show_in_app, Proc.new { false })
42
+ action_visible_for(:model_settings, Proc.new { false })
43
+ end
44
+
45
+ def add_action(action_name)
46
+ @actions_list << action_name.to_sym
47
+ @actions_list.uniq
48
+ end
49
+
50
+ def remove_action(action_name)
51
+ @remove_action.delete remove_action.to_sym
52
+ @actions_list.uniq
53
+ end
54
+
55
+ def action_visible_for(action_name, model_name)
56
+ action_name = action_name.to_sym
57
+ add_action(action_name) unless @actions_list.include?(action_name)
58
+
59
+ if model_name.is_a?(Proc)
60
+ @actions_visibility[action_name] = model_name
61
+ else
62
+ @actions_visibility[action_name] = [] if @actions_visibility[action_name].is_a?(Proc)
63
+ @actions_visibility[action_name] ||= []
64
+ @actions_visibility[action_name] << model_name.to_s
65
+ end
66
+ end
67
+
68
+ def action_unvisible_for(action_name, model_name)
69
+ action_name = action_name.to_sym
70
+ add_action(action_name) unless @actions_list.include?(action_name)
71
+
72
+ if model_name.is_a?(Proc)
73
+ # @actions_visibility[action_name] = model_name
74
+ else
75
+ @actions_visibility[action_name] = [] if @actions_visibility[action_name].is_a?(Proc)
76
+ @actions_visibility[action_name] ||= []
77
+ @actions_visibility[action_name].delete model_name.to_s
78
+ end
79
+ end
80
+
81
+ def actions_config(rails_admin_actions)
82
+
83
+ @actions_list.each do |action|
84
+ if rails_admin_actions.respond_to?(action)
85
+ rails_admin_actions.send(action) do
86
+ visible do
87
+ ret = false
88
+ if bindings[:abstract_model].model.respond_to?(:rails_admin_visible_actions)
89
+ ret = bindings[:abstract_model].model.rails_admin_visible_actions.include?(action)
90
+ else
91
+ if visibility = Hancock.rails_admin_config.actions_visibility[action]
92
+ if visibility.is_a?(Proc)
93
+ ret = visibility.call(self)
94
+ else
95
+ ret = visibility.include? bindings[:abstract_model].model_name
96
+ end
97
+ end
98
+ end # if bindings[:abstract_model].model.respond_to?(:rails_admin_visible_actions)
99
+ ret
100
+ end # visible do
101
+ end # rails_admin_actions.send(action) do
102
+ end # if rails_admin_actions.respond_to?(action)
103
+ end # @actions_list.each do |action|
104
+
105
+ end
106
+
107
+ def cancancan_admin_rules(ability_object)
108
+ Hancock.config.ability_admin_config.each do |config|
109
+ _model = config[:model]
110
+ _model = _model.constantize if _model.is_a?(String)
111
+ ability_object.send(config[:method], config[:actions], _model)
112
+ end
113
+ Hancock::MODELS.each do |_model|
114
+ ability_object.can _model.admin_can_actions, _model
115
+ end
116
+ end
117
+ def cancancan_manager_rules(ability_object)
118
+ Hancock.config.ability_manager_config.each do |config|
119
+ _model = config[:model]
120
+ _model = _model.constantize if _model.is_a?(String)
121
+ ability_object.send(config[:method], config[:actions], _model)
122
+ end
123
+ Hancock::MODELS.each do |_model|
124
+ ability_object.can _model.manager_can_actions, _model
125
+ end
126
+ end
127
+
128
+ end
129
+ end