Class: Hancock::RailsAdminConfiguration
- Inherits:
-
Object
- Object
- Hancock::RailsAdminConfiguration
- Defined in:
- lib/hancock/rails_admin_ext/config.rb
Instance Attribute Summary collapse
-
#actions_list ⇒ Object
readonly
Returns the value of attribute actions_list.
-
#actions_visibility ⇒ Object
readonly
Returns the value of attribute actions_visibility.
Instance Method Summary collapse
- #action_unvisible_for(action_name, model_name) ⇒ Object
- #action_visible_for(action_name, model_name) ⇒ Object
- #actions_config(rails_admin_actions) ⇒ Object
- #add_action(action_name) ⇒ Object
- #cancancan_admin_rules(ability_object) ⇒ Object
- #cancancan_manager_rules(ability_object) ⇒ Object
-
#initialize ⇒ RailsAdminConfiguration
constructor
A new instance of RailsAdminConfiguration.
- #remove_action(action_name) ⇒ Object
Constructor Details
#initialize ⇒ RailsAdminConfiguration
Returns a new instance of RailsAdminConfiguration.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 37 def initialize @actions_list ||= [] @actions_visibility ||= {} action_unvisible_for(:custom_show_in_app, Proc.new { false }) action_visible_for(:model_settings, Proc.new { false }) if defined?(RailsAdminNestedSet) action_visible_for(:nested_set, Proc.new { false }) end if defined?(RailsAdminMultipleFileUpload) action_visible_for(:multiple_file_upload, Proc.new { false }) action_visible_for(:multiple_file_upload_collection, Proc.new { false }) end if defined?(RailsAdminUserAbilities) action_visible_for(:user_abilities, Proc.new { false }) action_visible_for(:model_accesses, Proc.new { false }) end if defined?(RailsAdminComments) action_visible_for(:comments, Proc.new { false }) action_visible_for(:model_comments, Proc.new { false }) end action_visible_for(:sort_embedded, Proc.new { false }) end |
Instance Attribute Details
#actions_list ⇒ Object (readonly)
Returns the value of attribute actions_list.
34 35 36 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 34 def actions_list @actions_list end |
#actions_visibility ⇒ Object (readonly)
Returns the value of attribute actions_visibility.
35 36 37 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 35 def actions_visibility @actions_visibility end |
Instance Method Details
#action_unvisible_for(action_name, model_name) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 90 def action_unvisible_for(action_name, model_name) action_name = action_name.to_sym add_action(action_name) unless @actions_list.include?(action_name) if model_name.is_a?(Proc) # @actions_visibility[action_name] = model_name else @actions_visibility[action_name] = [] if @actions_visibility[action_name].is_a?(Proc) @actions_visibility[action_name] ||= [] @actions_visibility[action_name].delete model_name.to_s end end |
#action_visible_for(action_name, model_name) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 77 def action_visible_for(action_name, model_name) action_name = action_name.to_sym add_action(action_name) unless @actions_list.include?(action_name) if model_name.is_a?(Proc) @actions_visibility[action_name] = model_name else @actions_visibility[action_name] = [] if @actions_visibility[action_name].is_a?(Proc) @actions_visibility[action_name] ||= [] @actions_visibility[action_name] << model_name.to_s end end |
#actions_config(rails_admin_actions) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 103 def actions_config(rails_admin_actions) @actions_list.each do |action| if rails_admin_actions.respond_to?(action) and !RailsAdmin::Config::Actions.all.map { |a| a.class.name.demodulize.underscore }.include?(action.to_s) rails_admin_actions.send(action) do visible do if !bindings or bindings[:abstract_model].blank? true else ret = false if bindings[:abstract_model].model.respond_to?(:rails_admin_visible_actions) ret = bindings[:abstract_model].model.rails_admin_visible_actions.include?(action.to_sym) else if visibility = Hancock.rails_admin_config.actions_visibility[action] if visibility.is_a?(Proc) ret = visibility.call(self) else ret = visibility.include? bindings[:abstract_model].model_name end end end # if bindings[:abstract_model].model.respond_to?(:rails_admin_visible_actions) _context = bindings[:controller] || bindings[:view] ret and _context and _context.can?(action, bindings[:abstract_model].model) end # !bindings or bindings[:abstract_model].blank? end # visible do end # rails_admin_actions.send(action) do end # if rails_admin_actions.respond_to?(action) end # @actions_list.each do |action| end |
#add_action(action_name) ⇒ Object
67 68 69 70 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 67 def add_action(action_name) @actions_list << action_name.to_sym @actions_list.uniq end |
#cancancan_admin_rules(ability_object) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 135 def cancancan_admin_rules(ability_object) Hancock.config.ability_admin_config.each do |config| _model = config[:model] _model = _model.constantize if _model.is_a?(String) ability_object.send(config[:method], config[:actions], _model) end Hancock::MODELS.each do |_model| ability_object.can _model.admin_can_actions, _model ability_object.cannot _model.admin_cannot_actions, _model end end |
#cancancan_manager_rules(ability_object) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 147 def cancancan_manager_rules(ability_object) Hancock.config.ability_manager_config.each do |config| _model = config[:model] _model = _model.constantize if _model.is_a?(String) ability_object.send(config[:method], config[:actions], _model) end Hancock::MODELS.each do |_model| ability_object.can _model.manager_can_actions, _model ability_object.cannot _model.manager_cannot_actions, _model end end |
#remove_action(action_name) ⇒ Object
72 73 74 75 |
# File 'lib/hancock/rails_admin_ext/config.rb', line 72 def remove_action(action_name) @remove_action.delete remove_action.to_sym @actions_list.uniq end |