activeadmin 1.0.0.pre5 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activeadmin might be problematic. Click here for more details.

Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +27 -0
  3. data/.travis.yml +21 -23
  4. data/Appraisals +12 -74
  5. data/CHANGELOG.md +21 -5
  6. data/CONTRIBUTING.md +2 -2
  7. data/Gemfile +8 -9
  8. data/README.md +19 -56
  9. data/Rakefile +1 -1
  10. data/activeadmin.gemspec +4 -4
  11. data/app/assets/stylesheets/active_admin/_forms.scss +10 -0
  12. data/config/locales/ca.yml +1 -1
  13. data/config/locales/da.yml +44 -12
  14. data/config/locales/el.yml +1 -1
  15. data/config/locales/en.yml +2 -0
  16. data/config/locales/fr.yml +16 -2
  17. data/config/locales/ja.yml +1 -0
  18. data/config/locales/zh-CN.yml +4 -0
  19. data/docs/12-arbre-components.md +23 -0
  20. data/docs/14-gotchas.md +1 -1
  21. data/docs/2-resource-customization.md +2 -5
  22. data/docs/5-forms.md +19 -0
  23. data/docs/6-show-pages.md +0 -28
  24. data/docs/9-batch-actions.md +0 -1
  25. data/docs/CNAME +1 -1
  26. data/docs/_includes/head.html +4 -4
  27. data/docs/_includes/toc.html +2 -1
  28. data/docs/documentation.md +2 -2
  29. data/docs/index.html +1 -6
  30. data/docs/stylesheets/main.css +172 -219
  31. data/features/belongs_to.feature +5 -5
  32. data/features/comments/commenting.feature +0 -13
  33. data/features/create_another.feature +55 -0
  34. data/features/development_reloading.feature +2 -4
  35. data/features/edit_page.feature +6 -7
  36. data/features/favicon.feature +2 -2
  37. data/features/i18n.feature +1 -0
  38. data/features/index/filters.feature +18 -0
  39. data/features/index/format_as_csv.feature +3 -3
  40. data/features/index/formats.feature +22 -0
  41. data/features/index/index_as_table.feature +6 -6
  42. data/features/index/page_title.feature +1 -2
  43. data/features/menu.feature +20 -1
  44. data/features/new_page.feature +6 -8
  45. data/features/registering_assets.feature +4 -4
  46. data/features/registering_pages.feature +18 -0
  47. data/features/renamed_resource.feature +2 -4
  48. data/features/show/page_title.feature +1 -2
  49. data/features/step_definitions/attribute_steps.rb +1 -1
  50. data/features/step_definitions/configuration_steps.rb +2 -2
  51. data/features/step_definitions/format_steps.rb +4 -0
  52. data/features/step_definitions/index_scope_steps.rb +1 -1
  53. data/features/step_definitions/menu_steps.rb +2 -2
  54. data/features/step_definitions/user_steps.rb +1 -1
  55. data/features/step_definitions/web_steps.rb +6 -5
  56. data/features/sti_resource.feature +2 -2
  57. data/features/strong_parameters.feature +0 -4
  58. data/features/support/env.rb +5 -19
  59. data/features/support/paths.rb +6 -9
  60. data/gemfiles/rails_42.gemfile +15 -23
  61. data/gemfiles/rails_50.gemfile +15 -16
  62. data/gemfiles/rails_51.gemfile +45 -0
  63. data/lib/active_admin/application.rb +4 -0
  64. data/lib/active_admin/base_controller.rb +2 -7
  65. data/lib/active_admin/base_controller/menu.rb +1 -5
  66. data/lib/active_admin/csv_builder.rb +2 -2
  67. data/lib/active_admin/dependency.rb +4 -8
  68. data/lib/active_admin/devise.rb +1 -1
  69. data/lib/active_admin/error.rb +1 -1
  70. data/lib/active_admin/filters/active.rb +2 -10
  71. data/lib/active_admin/filters/resource_extension.rb +1 -10
  72. data/lib/active_admin/inputs/filters/date_range_input.rb +1 -1
  73. data/lib/active_admin/inputs/filters/select_input.rb +1 -2
  74. data/lib/active_admin/inputs/filters/text_input.rb +2 -2
  75. data/lib/active_admin/menu.rb +1 -1
  76. data/lib/active_admin/namespace.rb +14 -7
  77. data/lib/active_admin/orm/active_record/comments.rb +2 -7
  78. data/lib/active_admin/orm/active_record/comments/comment.rb +2 -12
  79. data/lib/active_admin/page.rb +5 -0
  80. data/lib/active_admin/page_controller.rb +1 -5
  81. data/lib/active_admin/resource.rb +28 -5
  82. data/lib/active_admin/resource/attributes.rb +44 -0
  83. data/lib/active_admin/resource/menu.rb +4 -1
  84. data/lib/active_admin/resource/routes.rb +2 -3
  85. data/lib/active_admin/resource_controller.rb +13 -0
  86. data/lib/active_admin/resource_controller/data_access.rb +18 -9
  87. data/lib/active_admin/resource_dsl.rb +21 -18
  88. data/lib/active_admin/version.rb +1 -1
  89. data/lib/active_admin/view_helpers/breadcrumb_helper.rb +1 -1
  90. data/lib/active_admin/view_helpers/display_helper.rb +10 -12
  91. data/lib/active_admin/view_helpers/download_format_links_helper.rb +12 -0
  92. data/lib/active_admin/view_helpers/fields_for.rb +1 -2
  93. data/lib/active_admin/view_helpers/form_helper.rb +1 -1
  94. data/lib/active_admin/views/components/active_admin_form.rb +28 -2
  95. data/lib/active_admin/views/components/paginated_collection.rb +3 -8
  96. data/lib/active_admin/views/components/table_for.rb +1 -1
  97. data/lib/active_admin/views/index_as_table.rb +2 -2
  98. data/lib/active_admin/views/pages/layout.rb +1 -1
  99. data/lib/active_admin/views/pages/show.rb +1 -1
  100. data/lib/bug_report_templates/rails_5_master.rb +1 -3
  101. data/lib/generators/active_admin/devise/devise_generator.rb +1 -1
  102. data/lib/generators/active_admin/install/templates/active_admin.rb.erb +7 -0
  103. data/lib/generators/active_admin/install/templates/admin_user.rb.erb +0 -2
  104. data/lib/generators/active_admin/install/templates/migrations/create_active_admin_comments.rb.erb +5 -7
  105. data/lib/generators/active_admin/resource/resource_generator.rb +1 -1
  106. data/lib/generators/active_admin/resource/templates/{admin.rb → admin.rb.erb} +0 -2
  107. data/lib/ransack_ext.rb +2 -2
  108. data/spec/rails_helper.rb +1 -19
  109. data/spec/requests/default_namespace_spec.rb +40 -8
  110. data/spec/support/active_admin_integration_spec_helper.rb +9 -2
  111. data/spec/support/rails_template.rb +17 -20
  112. data/spec/support/rails_template_with_data.rb +3 -9
  113. data/spec/support/templates/admin/stores.rb +1 -3
  114. data/spec/unit/application_spec.rb +19 -8
  115. data/spec/unit/belongs_to_spec.rb +6 -2
  116. data/spec/unit/comments_spec.rb +0 -19
  117. data/spec/unit/controller_filters_spec.rb +5 -5
  118. data/spec/unit/csv_builder_spec.rb +7 -4
  119. data/spec/unit/filters/active_spec.rb +1 -8
  120. data/spec/unit/filters/filter_form_builder_spec.rb +2 -3
  121. data/spec/unit/filters/resource_spec.rb +3 -4
  122. data/spec/unit/form_builder_spec.rb +39 -11
  123. data/spec/unit/namespace/register_page_spec.rb +1 -1
  124. data/spec/unit/pretty_format_spec.rb +39 -35
  125. data/spec/unit/resource/attributes_spec.rb +50 -0
  126. data/spec/unit/resource/includes_spec.rb +1 -1
  127. data/spec/unit/resource/ordering_spec.rb +1 -1
  128. data/spec/unit/resource/routes_spec.rb +2 -2
  129. data/spec/unit/resource_controller/data_access_spec.rb +51 -10
  130. data/spec/unit/resource_controller/decorators_spec.rb +2 -2
  131. data/spec/unit/resource_controller/sidebars_spec.rb +3 -3
  132. data/spec/unit/resource_controller_spec.rb +16 -5
  133. data/spec/unit/resource_spec.rb +12 -38
  134. data/spec/unit/routing_spec.rb +2 -2
  135. data/spec/unit/view_helpers/breadcrumbs_spec.rb +36 -1
  136. data/spec/unit/view_helpers/display_helper_spec.rb +17 -2
  137. data/spec/unit/view_helpers/fields_for_spec.rb +1 -1
  138. data/spec/unit/view_helpers/form_helper_spec.rb +3 -3
  139. data/spec/unit/view_helpers/method_or_proc_helper_spec.rb +2 -2
  140. data/spec/unit/views/components/attributes_table_spec.rb +2 -2
  141. data/spec/unit/views/components/index_list_spec.rb +1 -1
  142. data/spec/unit/views/components/paginated_collection_spec.rb +4 -4
  143. data/spec/unit/views/components/table_for_spec.rb +1 -1
  144. data/spec/unit/views/components/unsupported_browser_spec.rb +1 -1
  145. data/spec/unit/views/pages/form_spec.rb +4 -1
  146. data/spec/unit/views/pages/index_spec.rb +1 -1
  147. data/spec/unit/views/pages/show_spec.rb +2 -3
  148. data/tasks/lint.rake +8 -0
  149. metadata +22 -29
  150. data/features/step_definitions/symbol_leak_steps.rb +0 -3
  151. data/features/symbol_leak.feature +0 -35
  152. data/gemfiles/rails_32.gemfile +0 -54
  153. data/gemfiles/rails_40.gemfile +0 -53
  154. data/gemfiles/rails_41.gemfile +0 -53
  155. data/spec/support/deferred_garbage_collection.rb +0 -19
@@ -43,7 +43,7 @@ module ActiveAdmin
43
43
  "/#{namespace}"
44
44
  end
45
45
 
46
- # NOTE: `relative_url_root` is deprecated by rails.
46
+ # NOTE: `relative_url_root` is deprecated by Rails.
47
47
  # Remove prefix here if it is removed completely.
48
48
  prefix = Rails.configuration.action_controller[:relative_url_root] || ''
49
49
  prefix + path
@@ -5,7 +5,7 @@ module ActiveAdmin
5
5
  class AccessDenied < StandardError
6
6
  attr_reader :user, :action, :subject
7
7
 
8
- def initialize(user, action, subject)
8
+ def initialize(user, action, subject = nil)
9
9
  @user, @action, @subject = user, action, subject
10
10
 
11
11
  super()
@@ -8,23 +8,15 @@ module ActiveAdmin
8
8
 
9
9
  def initialize(resource_class, params)
10
10
  @resource_class = resource_class
11
- @params = normalize_params(params)
11
+ @params = params.to_unsafe_h
12
12
  @scope = humanize_scope
13
13
  @filters = build_filters
14
14
  end
15
15
 
16
16
  private
17
17
 
18
- def normalize_params(params)
19
- if params.is_a?(HashWithIndifferentAccess)
20
- params
21
- else
22
- params.to_unsafe_h
23
- end
24
- end
25
-
26
18
  def build_filters
27
- filters = @params[:q] || []
19
+ filters = @params['q'] || []
28
20
  filters.map{ |param| Humanized.new(param) }
29
21
  end
30
22
 
@@ -109,7 +109,7 @@ module ActiveAdmin
109
109
  def default_filters
110
110
  result = []
111
111
  result.concat default_association_filters if namespace.include_default_association_filters
112
- result.concat default_content_filters
112
+ result.concat content_columns
113
113
  result.concat custom_ransack_filters
114
114
  result
115
115
  end
@@ -137,15 +137,6 @@ module ActiveAdmin
137
137
  end
138
138
  end
139
139
 
140
- # Returns a default set of filters for the content columns
141
- def default_content_filters
142
- if resource_class.respond_to? :content_columns
143
- resource_class.content_columns.map{ |c| c.name.to_sym }
144
- else
145
- []
146
- end
147
- end
148
-
149
140
  def add_filters_sidebar_section
150
141
  self.sidebar_sections << filters_sidebar_section
151
142
  end
@@ -27,7 +27,7 @@ module ActiveAdmin
27
27
  current_value = begin
28
28
  #cast value to date object before rendering input
29
29
  @object.public_send(input_name).to_s.to_date
30
- rescue
30
+ rescue
31
31
  nil
32
32
  end
33
33
  { size: 12,
@@ -45,8 +45,7 @@ module ActiveAdmin
45
45
  end
46
46
 
47
47
  def pluck_column
48
- distinct = ActiveAdmin::Dependency.rails >= 4 ? :distinct : :uniq
49
- klass.reorder("#{method} asc").public_send(distinct).pluck method
48
+ klass.reorder("#{method} asc").distinct.pluck method
50
49
  end
51
50
 
52
51
  end
@@ -7,8 +7,8 @@ module ActiveAdmin
7
7
 
8
8
  def input_html_options
9
9
  {
10
- :cols => builder.default_text_area_width,
11
- :rows => builder.default_text_area_height
10
+ cols: builder.default_text_area_width,
11
+ rows: builder.default_text_area_height
12
12
  }.merge(super)
13
13
  end
14
14
 
@@ -71,7 +71,7 @@ module ActiveAdmin
71
71
  # Returns sorted array of menu items that should be displayed in this context.
72
72
  # Sorts by priority first, then alphabetically by label if needed.
73
73
  def items(context = nil)
74
- @children.values.select{ |i| i.display?(context) }.sort do |a,b|
74
+ @children.values.select{ |i| i.display?(context) }.sort do |a, b|
75
75
  result = a.priority <=> b.priority
76
76
  result = a.label(context) <=> b.label(context) if result == 0
77
77
  result
@@ -27,16 +27,20 @@ module ActiveAdmin
27
27
  class Namespace
28
28
  RegisterEvent = 'active_admin.namespace.register'.freeze
29
29
 
30
- attr_reader :application, :resources, :name, :menus
30
+ attr_reader :application, :resources, :menus
31
31
 
32
32
  def initialize(application, name)
33
33
  @application = application
34
- @name = name.to_s.underscore.to_sym
34
+ @name = name.to_s.underscore
35
35
  @resources = ResourceCollection.new
36
36
  register_module unless root?
37
37
  build_menu_collection
38
38
  end
39
39
 
40
+ def name
41
+ @name.to_sym
42
+ end
43
+
40
44
  # Register a resource into this namespace. The preffered method to access this is to
41
45
  # use the global registration ActiveAdmin.register which delegates to the proper
42
46
  # namespace instance.
@@ -45,7 +49,7 @@ module ActiveAdmin
45
49
 
46
50
  # Register the resource
47
51
  register_resource_controller(config)
48
- parse_registration_block(config, resource_class, &block) if block_given?
52
+ parse_registration_block(config, &block) if block_given?
49
53
  reset_menu!
50
54
 
51
55
  # Dispatch a registration event
@@ -78,8 +82,11 @@ module ActiveAdmin
78
82
  # Namespace.new(:root).module_name # => nil
79
83
  #
80
84
  def module_name
81
- return nil if root?
82
- @module_name ||= name.to_s.camelize
85
+ root? ? nil : @name.camelize
86
+ end
87
+
88
+ def route_prefix
89
+ root? ? nil : @name
83
90
  end
84
91
 
85
92
  # Unload all the registered resources for this namespace
@@ -218,8 +225,8 @@ module ActiveAdmin
218
225
  config.controller.active_admin_config = config
219
226
  end
220
227
 
221
- def parse_registration_block(config, resource_class, &block)
222
- config.dsl = ResourceDSL.new(config, resource_class)
228
+ def parse_registration_block(config, &block)
229
+ config.dsl = ResourceDSL.new(config)
223
230
  config.dsl.run_registration_block(&block)
224
231
  end
225
232
 
@@ -46,10 +46,7 @@ ActiveAdmin.after_load do |app|
46
46
  controller do
47
47
  # Prevent N+1 queries
48
48
  def scoped_collection
49
- super.includes *( # rails/rails#14734
50
- ActiveAdmin::Dependency.rails?('>= 4.1.0', '<= 4.1.1') ?
51
- [:author] : [:author, :resource]
52
- )
49
+ super.includes(:author, :resource)
53
50
  end
54
51
 
55
52
  # Redirect to the resource show page after comment creation
@@ -77,9 +74,7 @@ ActiveAdmin.after_load do |app|
77
74
  end
78
75
  end
79
76
 
80
- if ActiveAdmin::Dependency.rails.strong_parameters?
81
- permit_params :body, :namespace, :resource_id, :resource_type
82
- end
77
+ permit_params :body, :namespace, :resource_id, :resource_type
83
78
 
84
79
  index do
85
80
  column I18n.t('active_admin.comments.resource_type'), :resource_type
@@ -6,7 +6,7 @@ module ActiveAdmin
6
6
  belongs_to :resource, polymorphic: true
7
7
  belongs_to :author, polymorphic: true
8
8
 
9
- unless Rails::VERSION::MAJOR > 3 && !defined? ProtectedAttributes
9
+ if defined? ProtectedAttributes
10
10
  attr_accessible :resource, :resource_id, :resource_type, :body, :namespace
11
11
  end
12
12
 
@@ -19,27 +19,17 @@ module ActiveAdmin
19
19
  ResourceController::Decorators.undecorate(resource).class.base_class.name.to_s
20
20
  end
21
21
 
22
- # Postgres adapters won't compare strings to numbers (issue 34)
23
- def self.resource_id_cast(record)
24
- resource_id_type == :string ? record.id.to_s : record.id
25
- end
26
-
27
22
  def self.find_for_resource_in_namespace(resource, namespace)
28
23
  where(
29
24
  resource_type: resource_type(resource),
30
- resource_id: resource_id_cast(resource),
25
+ resource_id: resource,
31
26
  namespace: namespace.to_s
32
27
  ).order(ActiveAdmin.application.namespaces[namespace.to_sym].comments_order)
33
28
  end
34
29
 
35
- def self.resource_id_type
36
- columns.detect{ |i| i.name == "resource_id" }.type
37
- end
38
-
39
30
  def set_resource_type
40
31
  self.resource_type = self.class.resource_type(resource)
41
32
  end
42
33
 
43
34
  end
44
35
  end
45
-
@@ -102,5 +102,10 @@ module ActiveAdmin
102
102
  def breadcrumb
103
103
  instance_variable_defined?(:@breadcrumb) ? @breadcrumb : namespace.breadcrumb
104
104
  end
105
+
106
+ def order_clause
107
+ @order_clause || namespace.order_clause
108
+ end
109
+
105
110
  end
106
111
  end
@@ -8,11 +8,7 @@ module ActiveAdmin
8
8
 
9
9
  actions :index
10
10
 
11
- if ActiveAdmin::Dependency.rails >= 4
12
- before_action :authorize_access!
13
- else
14
- before_filter :authorize_access!
15
- end
11
+ before_action :authorize_access!
16
12
 
17
13
  def index(options={}, &block)
18
14
  render "active_admin/page/index"
@@ -1,4 +1,5 @@
1
1
  require 'active_admin/resource/action_items'
2
+ require 'active_admin/resource/attributes'
2
3
  require 'active_admin/resource/controllers'
3
4
  require 'active_admin/resource/menu'
4
5
  require 'active_admin/resource/page_presenters'
@@ -53,6 +54,9 @@ module ActiveAdmin
53
54
 
54
55
  #Set order clause
55
56
  attr_writer :order_clause
57
+ # Display create another checkbox on a new page
58
+ # @return [Boolean]
59
+ attr_writer :create_another
56
60
 
57
61
  # Store a reference to the DSL so that we can dereference it during garbage collection.
58
62
  attr_accessor :dsl
@@ -87,6 +91,7 @@ module ActiveAdmin
87
91
  include Sidebars
88
92
  include Routes
89
93
  include Ordering
94
+ include Attributes
90
95
 
91
96
  # The class this resource wraps. If you register the Post model, Resource#resource_class
92
97
  # will point to the Post class
@@ -126,7 +131,7 @@ module ActiveAdmin
126
131
 
127
132
  def belongs_to(target, options = {})
128
133
  @belongs_to = Resource::BelongsTo.new(self, target, options)
129
- self.navigation_menu_name = target unless @belongs_to.optional?
134
+ self.menu_item_options = false if @belongs_to.required?
130
135
  controller.send :belongs_to, target, options.dup
131
136
  end
132
137
 
@@ -158,25 +163,43 @@ module ActiveAdmin
158
163
  @order_clause || namespace.order_clause
159
164
  end
160
165
 
166
+ def create_another
167
+ instance_variable_defined?(:@create_another) ? @create_another : namespace.create_another
168
+ end
169
+
161
170
  def find_resource(id)
162
171
  resource = resource_class.public_send *method_for_find(id)
163
172
  (decorator_class && resource) ? decorator_class.new(resource) : resource
164
173
  end
165
174
 
175
+ def resource_columns
176
+ resource_attributes.values
177
+ end
178
+
179
+ def resource_attributes
180
+ @resource_attributes ||= default_attributes
181
+ end
182
+
183
+ def association_columns
184
+ @association_columns ||= resource_attributes.select{ |key, value| key != value }.values
185
+ end
186
+
187
+ def content_columns
188
+ @content_columns ||= resource_attributes.select{ |key, value| key == value }.values
189
+ end
190
+
166
191
  private
167
192
 
168
193
  def method_for_find(id)
169
194
  if finder = resources_configuration[:self][:finder]
170
195
  [finder, id]
171
- elsif Rails::VERSION::MAJOR >= 4
172
- [:find_by, { resource_class.primary_key => id }]
173
196
  else
174
- [:"find_by_#{resource_class.primary_key}", id]
197
+ [:find_by, { resource_class.primary_key => id }]
175
198
  end
176
199
  end
177
200
 
178
201
  def default_csv_builder
179
- @default_csv_builder ||= CSVBuilder.default_for_resource(resource_class)
202
+ @default_csv_builder ||= CSVBuilder.default_for_resource(self)
180
203
  end
181
204
 
182
205
  end # class Resource
@@ -0,0 +1,44 @@
1
+ module ActiveAdmin
2
+
3
+ class Resource
4
+ module Attributes
5
+
6
+ def default_attributes
7
+ resource_class.columns.each_with_object({}) do |c, attrs|
8
+ unless reject_col?(c)
9
+ name = c.name.to_sym
10
+ attrs[name] = (method_for_column(name) || name)
11
+ end
12
+ end
13
+ end
14
+
15
+ def method_for_column(c)
16
+ resource_class.respond_to?(:reflect_on_all_associations) && foreign_methods.has_key?(c) && foreign_methods[c].name.to_sym
17
+ end
18
+
19
+ def foreign_methods
20
+ @foreign_methods ||= resource_class.reflect_on_all_associations.
21
+ select{ |r| r.macro == :belongs_to }.
22
+ reject{ |r| r.chain.length > 2 && !r.options[:polymorphic] }.
23
+ index_by{ |r| r.foreign_key.to_sym }
24
+ end
25
+
26
+ def reject_col?(c)
27
+ primary_col?(c) || sti_col?(c) || counter_cache_col?(c)
28
+ end
29
+
30
+ def primary_col?(c)
31
+ c.name == resource_class.primary_key
32
+ end
33
+
34
+ def sti_col?(c)
35
+ c.name == resource_class.inheritance_column
36
+ end
37
+
38
+ def counter_cache_col?(c)
39
+ c.name.end_with?('_count')
40
+ end
41
+
42
+ end
43
+ end
44
+ end
@@ -10,6 +10,7 @@ module ActiveAdmin
10
10
  @include_in_menu = false
11
11
  @menu_item_options = {}
12
12
  else
13
+ @include_in_menu = true
13
14
  @navigation_menu_name = options[:menu_name]
14
15
  @menu_item_options = default_menu_options.merge options
15
16
  end
@@ -31,7 +32,9 @@ module ActiveAdmin
31
32
  }
32
33
  end
33
34
 
34
- attr_writer :navigation_menu_name
35
+ def navigation_menu_name=(menu_name)
36
+ self.menu_item_options = { menu_name: menu_name }
37
+ end
35
38
 
36
39
  def navigation_menu_name
37
40
  case @navigation_menu_name ||= DEFAULT_MENU
@@ -25,7 +25,7 @@ module ActiveAdmin
25
25
 
26
26
  # Returns the routes prefix for this config
27
27
  def route_prefix
28
- namespace.module_name.try(:underscore)
28
+ namespace.route_prefix
29
29
  end
30
30
 
31
31
  def route_builder
@@ -62,8 +62,7 @@ module ActiveAdmin
62
62
  )
63
63
 
64
64
  query = params.slice(:q, :scope)
65
- query = query.permit! if query.respond_to? :permit!
66
- query = query.to_h if Rails::VERSION::MAJOR >= 5
65
+ query = query.permit!.to_h
67
66
  routes.public_send route_name, *route_collection_params(params), additional_params.merge(query)
68
67
  end
69
68
 
@@ -21,6 +21,7 @@ module ActiveAdmin
21
21
  include Scoping
22
22
  include Streaming
23
23
  include Sidebars
24
+ include ViewHelpers::DownloadFormatLinksHelper
24
25
  extend ResourceClassMethods
25
26
 
26
27
  def self.active_admin_config=(config)
@@ -45,7 +46,19 @@ module ActiveAdmin
45
46
  def renderer_for(action)
46
47
  active_admin_namespace.view_factory["#{action}_page"]
47
48
  end
49
+
48
50
  helper_method :renderer_for
49
51
 
52
+ def restrict_format_access!
53
+ unless request.format.html?
54
+ presenter = active_admin_config.get_page_presenter(:index)
55
+ download_formats = (presenter || {}).fetch(:download_links, active_admin_config.namespace.download_links)
56
+ unless build_download_formats(download_formats).include?(request.format.symbol)
57
+ raise ActiveAdmin::AccessDenied.new(current_active_admin_user, :index)
58
+ end
59
+ end
60
+ end
61
+
62
+ before_action :restrict_format_access!, only: [:index, :show]
50
63
  end
51
64
  end