rails_admin 3.0.0.rc2 → 3.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 142382cf0987b581cb64996e716ad77cf9ae76dab5aa1bf019b8ca38fb7daed0
4
- data.tar.gz: 58a52e67fc458713f0245ea244e2a129f370309edc91511678ba06bbc756e9cc
3
+ metadata.gz: 5ed0d71c0798b98c4a0afdff5fa2ed48ffd05d1e0124d52ccdb371012d117479
4
+ data.tar.gz: ed51dc928885ae4c57e9f02a9e40cf7689731570a78efc7d1bdfbe3afbd7e298
5
5
  SHA512:
6
- metadata.gz: 55fce15b0a7bf4f168b042ab7415fd24f0cefdb509d61efdb2f3f15de42b657bbbe24b62e686a359f18239f0c9ad36436bbd229c22b35c28be17d8f27fb5ef7f
7
- data.tar.gz: 9d076ac618ecdbb0680e7d8e7dd3472b7d0e47d10d5d12b4bdfc260c43297ded2e430a410926d0a680cbe120406e20da3678b5adb5ef2050efebe9aa8e2f8e12
6
+ metadata.gz: ff6f4ff15d8722cb44f4bbfeb8375c6c68c24be7cfadaa1e0b2dcf323f43321bc40296c60cdbcd2a9ecc28685261ca5ef00b046481394044d3f6f3970e6ddf86
7
+ data.tar.gz: a23d415f1987f61dd8d5bf7dcac7d2d7307e602a0afe3d16c94d8a639ad952135154cc31728bd1f41e181e0f1a829d39afb8898c6fc1a301a75fa64649b117d7
data/README.md CHANGED
@@ -45,7 +45,7 @@ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing
45
45
 
46
46
  ## Installation
47
47
 
48
- 1. On your gemfile: `gem 'rails_admin', ['>= 3.0.0.rc2', '< 4']`
48
+ 1. On your gemfile: `gem 'rails_admin', ['>= 3.0.0.rc3', '< 4']`
49
49
  2. Run `bundle install`
50
50
  3. Run `rails g rails_admin:install`
51
51
  4. Provide a namespace for the routes when asked
@@ -13,9 +13,8 @@ module RailsAdmin
13
13
 
14
14
  def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = get_association_scope_from_params, pagination = !(params[:associated_collection] || params[:all] || params[:bulk_ids]))
15
15
  scope = model_config.scope
16
- if auth_scope = @authorization_adapter&.query(auth_scope_key, model_config.abstract_model)
17
- scope = scope.merge(auth_scope)
18
- end
16
+ auth_scope = @authorization_adapter&.query(auth_scope_key, model_config.abstract_model)
17
+ scope = scope.merge(auth_scope) if auth_scope
19
18
  scope = scope.instance_eval(&additional_scope) if additional_scope
20
19
  get_collection(model_config, scope, pagination)
21
20
  end
@@ -20,17 +20,24 @@ module RailsAdmin
20
20
  end
21
21
 
22
22
  def edit_user_link
23
- return nil unless _current_user.respond_to?(:email)
24
- return nil unless abstract_model = RailsAdmin.config(_current_user.class).abstract_model
25
-
26
- content = [
27
- RailsAdmin::Config.show_gravatar && _current_user.email.present? && image_tag("#{request.ssl? ? 'https://secure' : 'http://www'}.gravatar.com/avatar/#{Digest::MD5.hexdigest _current_user.email}?s=30", alt: ''),
28
- content_tag(:span, _current_user.email),
29
- ].compact.join.html_safe
30
- if (edit_action = RailsAdmin::Config::Actions.find(:edit, controller: controller, abstract_model: abstract_model, object: _current_user)).try(:authorized?)
31
- link_to content, rails_admin.url_for(action: edit_action.action_name, model_name: abstract_model.to_param, id: _current_user.id, controller: 'rails_admin/main'), class: 'nav-link'
23
+ return nil unless _current_user.try(:email).present?
24
+ return nil unless (abstract_model = RailsAdmin.config(_current_user.class).abstract_model)
25
+
26
+ edit_action = action(:edit, abstract_model, _current_user)
27
+ authorized = edit_action.try(:authorized?)
28
+ content = edit_user_link_label
29
+
30
+ if authorized
31
+ edit_url = rails_admin.url_for(
32
+ action_name: edit_action.action_name,
33
+ model_name: abstract_model.to_param,
34
+ controller: 'rails_admin/main',
35
+ id: _current_user.id,
36
+ )
37
+
38
+ link_to content, edit_url, class: 'nav-link'
32
39
  else
33
- content_tag :span, content
40
+ content_tag :span, content, class: 'nav-link'
34
41
  end
35
42
  end
36
43
 
@@ -206,5 +213,20 @@ module RailsAdmin
206
213
  end
207
214
  raise e
208
215
  end
216
+
217
+ private
218
+
219
+ def edit_user_link_label
220
+ [
221
+ RailsAdmin::Config.show_gravatar &&
222
+ image_tag(gravatar_url(_current_user.email), alt: ''),
223
+
224
+ content_tag(:span, _current_user.email),
225
+ ].filter(&:present?).join.html_safe
226
+ end
227
+
228
+ def gravatar_url(email)
229
+ "https://secure.gravatar.com/avatar/#{Digest::MD5.hexdigest email}?s=30"
230
+ end
209
231
  end
210
232
  end
@@ -1,6 +1,6 @@
1
1
  <% params = request.params.except(:action, :controller, :utf8, :page, :per_page, :format, :authenticity_token) %>
2
2
  <% visible_fields = @model_config.export.with(view: self, object: @abstract_model.model.new, controller: self.controller).visible_fields %>
3
- <%= form_tag export_path(params.merge(all: true)), method: 'post', class: "main" do %>
3
+ <%= form_tag export_path(params.merge(all: true)), method: 'post', class: "main", data: {turbo: false} do %>
4
4
  <input name="send_data" type="hidden" value="true" />
5
5
  <fieldset id="fields_to_export" class="mb-3">
6
6
  <legend>
@@ -96,8 +96,8 @@
96
96
  <ul class="nav nav-tabs" id="scope_selector">
97
97
  <% @model_config.list.scopes.each_with_index do |scope, index| %>
98
98
  <% scope = '_all' if scope.nil? %>
99
- <li class="<%= 'active' if scope.to_s == params[:scope] || (params[:scope].blank? && index == 0) %>">
100
- <a href="<%= index_path(params.merge(scope: scope, page: nil)) %>">
99
+ <li class="nav-item">
100
+ <a href="<%= index_path(params.merge(scope: scope, page: nil)) %>" class="nav-link <%= 'active' if scope.to_s == params[:scope] || (params[:scope].blank? && index == 0) %>">
101
101
  <%= I18n.t("admin.scopes.#{@abstract_model.to_param}.#{scope}", default: I18n.t("admin.scopes.#{scope}", default: scope.to_s.titleize)) %>
102
102
  </a>
103
103
  </li>
@@ -8,7 +8,7 @@ module RailsAdmin
8
8
  include Generators::Utils::InstanceMethods
9
9
 
10
10
  argument :_namespace, type: :string, required: false, desc: 'RailsAdmin url namespace'
11
- class_option :asset, type: :string, required: false, default: nil, desc: 'Asset delivery method [options: webpack, webpacker, sprockets]'
11
+ class_option :asset, type: :string, required: false, default: nil, desc: 'Asset delivery method [options: webpacker, sprockets]'
12
12
  desc 'RailsAdmin installation generator'
13
13
 
14
14
  def install
@@ -39,9 +39,7 @@ module RailsAdmin
39
39
  def asset
40
40
  return options['asset'] if options['asset']
41
41
 
42
- if Rails.root.join('webpack.config.js').exist?
43
- 'webpack'
44
- elsif defined?(Webpacker)
42
+ if defined?(Webpacker)
45
43
  'webpacker'
46
44
  else
47
45
  'sprockets'
@@ -86,9 +86,8 @@ module RailsAdmin
86
86
  associations.each do |association|
87
87
  case association.type
88
88
  when :has_one
89
- if child = object.send(association.name)
90
- yield(association, [child])
91
- end
89
+ child = object.send(association.name)
90
+ yield(association, [child]) if child
92
91
  when :has_many
93
92
  children = object.send(association.name)
94
93
  yield(association, Array.new(children))
@@ -13,7 +13,8 @@ module RailsAdmin
13
13
  end
14
14
 
15
15
  def get(id, scope = scoped)
16
- return unless object = scope.where(primary_key => id).first
16
+ object = scope.where(primary_key => id).first
17
+ return unless object
17
18
 
18
19
  object.extend(ObjectExtension)
19
20
  end
@@ -52,10 +52,10 @@ module RailsAdmin
52
52
  scope
53
53
  rescue NoMethodError => e
54
54
  if /page/.match?(e.message)
55
- e = e.exception <<-EOM.gsub(/^\s{12}/, '')
55
+ e = e.exception <<-ERROR.gsub(/^\s{12}/, '')
56
56
  #{e.message}
57
57
  If you don't have kaminari-mongoid installed, add `gem 'kaminari-mongoid'` to your Gemfile.
58
- EOM
58
+ ERROR
59
59
  end
60
60
  raise e
61
61
  end
@@ -14,7 +14,8 @@ module RailsAdmin
14
14
 
15
15
  register_instance_option :controller do
16
16
  proc do
17
- if format = params[:json] && :json || params[:csv] && :csv || params[:xml] && :xml
17
+ format = params[:json] && :json || params[:csv] && :csv || params[:xml] && :xml
18
+ if format
18
19
  request.format = format
19
20
  @schema = HashHelper.symbolize(params[:schema].slice(:except, :include, :methods, :only).permit!.to_h) if params[:schema] # to_json and to_xml expect symbols for keys AND values.
20
21
  @objects = list_entries(@model_config, :export)
@@ -20,7 +20,8 @@ module RailsAdmin
20
20
 
21
21
  register_instance_option :breadcrumb_parent do
22
22
  parent_model = bindings[:abstract_model].try(:config).try(:parent)
23
- if am = parent_model && RailsAdmin.config(parent_model).try(:abstract_model)
23
+ am = parent_model && RailsAdmin.config(parent_model).try(:abstract_model)
24
+ if am
24
25
  [:index, am]
25
26
  else
26
27
  [:dashboard]
@@ -21,7 +21,8 @@ module RailsAdmin
21
21
  @authorization_adapter&.attributes_for(:new, @abstract_model)&.each do |name, value|
22
22
  @object.send("#{name}=", value)
23
23
  end
24
- if object_params = params[@abstract_model.param_key]
24
+ object_params = params[@abstract_model.param_key]
25
+ if object_params
25
26
  sanitize_params_for!(request.xhr? ? :modal : :create)
26
27
  @object.assign_attributes(@object.attributes.merge(object_params.to_h))
27
28
  end
@@ -301,14 +301,14 @@ module RailsAdmin
301
301
  def value
302
302
  bindings[:object].safe_send(name)
303
303
  rescue NoMethodError => e
304
- raise e.exception <<-EOM.gsub(/^\s{10}/, '')
304
+ raise e.exception <<-ERROR.gsub(/^\s{10}/, '')
305
305
  #{e.message}
306
306
  If you want to use a RailsAdmin virtual field(= a field without corresponding instance method),
307
307
  you should declare 'formatted_value' in the field definition.
308
308
  field :#{name} do
309
309
  formatted_value{ bindings[:object].call_some_method }
310
310
  end
311
- EOM
311
+ ERROR
312
312
  end
313
313
 
314
314
  # Reader for nested attributes
@@ -16,7 +16,8 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
16
16
  ["#{name}_attachment".to_sym, "#{name}_blob".to_sym]
17
17
  end
18
18
  children_fields = associations.map do |child_name|
19
- next unless child_association = parent.abstract_model.associations.detect { |p| p.name.to_sym == child_name }
19
+ child_association = parent.abstract_model.associations.detect { |p| p.name.to_sym == child_name }
20
+ next unless child_association
20
21
 
21
22
  child_field = fields.detect { |f| f.name == child_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_association, fields)
22
23
  child_field.hide unless field == child_field
@@ -3,7 +3,8 @@ require 'rails_admin/config/fields/types'
3
3
  require 'rails_admin/config/fields/types/belongs_to_association'
4
4
 
5
5
  RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
6
- if association = parent.abstract_model.associations.detect { |a| a.foreign_key == properties.name && %i[belongs_to has_and_belongs_to_many].include?(a.type) }
6
+ association = parent.abstract_model.associations.detect { |a| a.foreign_key == properties.name && %i[belongs_to has_and_belongs_to_many].include?(a.type) }
7
+ if association
7
8
  field = RailsAdmin::Config::Fields::Types.load("#{association.polymorphic? ? :polymorphic : association.type}_association").new(parent, association.name, association)
8
9
  fields << field
9
10
 
@@ -15,9 +16,8 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
15
16
  end.collect { |k| association.send(k) }.compact
16
17
 
17
18
  parent.abstract_model.properties.select { |p| possible_field_names.include? p.name }.each do |column|
18
- unless child_field = fields.detect { |f| f.name.to_s == column.name.to_s }
19
- child_field = RailsAdmin::Config::Fields.default_factory.call(parent, column, fields)
20
- end
19
+ child_field = fields.detect { |f| f.name.to_s == column.name.to_s }
20
+ child_field ||= RailsAdmin::Config::Fields.default_factory.call(parent, column, fields)
21
21
  child_columns << child_field
22
22
  end
23
23
 
@@ -12,7 +12,8 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
12
12
  fields << field
13
13
  children_fields = []
14
14
  columns.each do |children_column_name|
15
- next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
15
+ child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
16
+ next unless child_properties
16
17
 
17
18
  children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
18
19
  children_field.hide unless field == children_field
@@ -12,7 +12,8 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
12
12
  properties = parent.abstract_model.properties.detect { |p| ext == p.name }
13
13
  next unless properties
14
14
 
15
- unless field = fields.detect { |f| f.name == ext }
15
+ field = fields.detect { |f| f.name == ext }
16
+ unless field
16
17
  RailsAdmin::Config::Fields.default_factory.call(parent, properties, fields)
17
18
  field = fields.last
18
19
  end
@@ -9,7 +9,8 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
9
9
  children_fields = []
10
10
  extensions.each do |ext|
11
11
  children_column_name = "#{attachment_name}_#{ext}".to_sym
12
- next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
12
+ child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
13
+ next unless child_properties
13
14
 
14
15
  children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
15
16
  children_field.hide
@@ -10,7 +10,8 @@ RailsAdmin::Config::Fields.register_factory do |parent, properties, fields|
10
10
  children_fields = []
11
11
  extensions.each do |ext|
12
12
  children_column_name = "#{attachment_name}_#{ext}".to_sym
13
- next unless child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
13
+ child_properties = parent.abstract_model.properties.detect { |p| p.name.to_s == children_column_name.to_s }
14
+ next unless child_properties
14
15
 
15
16
  children_field = fields.detect { |f| f.name == children_column_name } || RailsAdmin::Config::Fields.default_factory.call(parent, child_properties, fields)
16
17
  children_field.hide
@@ -58,7 +58,8 @@ module RailsAdmin
58
58
  end
59
59
 
60
60
  register_instance_option :formatted_value do
61
- if time = (value || default_value)
61
+ time = (value || default_value)
62
+ if time
62
63
  ::I18n.l(time, format: strftime_format)
63
64
  else
64
65
  ''.html_safe
@@ -39,7 +39,7 @@ module RailsAdmin
39
39
  attr_accessor :included_models
40
40
 
41
41
  # Fields to be hidden in show, create and update views
42
- attr_accessor :default_hidden_fields
42
+ attr_reader :default_hidden_fields
43
43
 
44
44
  # Default items per page value used if a model level option has not
45
45
  # been configured
@@ -42,10 +42,6 @@ module RailsAdmin
42
42
  end
43
43
  end
44
44
 
45
- rake_tasks do
46
- Dir[File.join(File.dirname(__FILE__), '../tasks/*.rake')].each { |f| load f }
47
- end
48
-
49
45
  # Check for required middlewares, users may forget to use them in Rails API mode
50
46
  config.after_initialize do |app|
51
47
  has_session_store = app.config.middleware.to_a.any? do |m|
@@ -59,14 +55,14 @@ module RailsAdmin
59
55
  unless missing.empty? && has_session_store
60
56
  configs = missing.map { |m| "config.middleware.use #{m}" }
61
57
  configs << "config.middleware.use #{app.config.session_store.try(:name) || 'ActionDispatch::Session::CookieStore'}, #{app.config.session_options}" unless has_session_store
62
- raise <<~EOM
58
+ raise <<~ERROR
63
59
  Required middlewares for RailsAdmin are not added
64
60
  To fix this, add
65
61
 
66
62
  #{configs.join("\n ")}
67
63
 
68
64
  to config/application.rb.
69
- EOM
65
+ ERROR
70
66
  end
71
67
 
72
68
  RailsAdmin::Config.initialize!
@@ -49,7 +49,7 @@ module RailsAdmin
49
49
  created_at: :created_at,
50
50
  message: :event,
51
51
  }.freeze
52
- E_VERSION_MODEL_NOT_SET = <<-EOS.strip_heredoc.freeze
52
+ E_VERSION_MODEL_NOT_SET = <<-ERROR.strip_heredoc.freeze
53
53
  Please set up PaperTrail's version model explicitly.
54
54
 
55
55
  config.audit_with :paper_trail, 'User', 'PaperTrail::Version'
@@ -58,7 +58,7 @@ module RailsAdmin
58
58
  (https://github.com/paper-trail-gem/paper_trail#6a-custom-version-classes)
59
59
  that configuration will take precedence over what you specify in
60
60
  `audit_with`.
61
- EOS
61
+ ERROR
62
62
 
63
63
  def self.setup
64
64
  raise 'PaperTrail not found' unless defined?(::PaperTrail)
@@ -3,7 +3,7 @@ module RailsAdmin
3
3
  MAJOR = 3
4
4
  MINOR = 0
5
5
  PATCH = 0
6
- PRE = 'rc2'.freeze
6
+ PRE = 'rc3'.freeze
7
7
 
8
8
  class << self
9
9
  # @return [String]
data/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rails_admin",
3
- "version": "3.0.0-rc2",
3
+ "version": "3.0.0-rc3",
4
4
  "description": "RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data.",
5
5
  "homepage": "https://github.com/railsadminteam/rails_admin",
6
6
  "license": "MIT",
@@ -80,7 +80,7 @@ import I18n from "./i18n";
80
80
  .each(function () {
81
81
  $(this).siblings(".control-group").hide();
82
82
  });
83
- $(".form-actions .extra_buttons button")
83
+ $('button[name][type="submit"]')
84
84
  .attr("type", "button")
85
85
  .on("click", function () {
86
86
  var form = $(this).closest("form");
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_admin
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0.rc2
4
+ version: 3.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Michaels-Ober
@@ -12,7 +12,7 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2022-02-20 00:00:00.000000000 Z
15
+ date: 2022-02-27 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
18
  name: activemodel-serializers-xml
@@ -464,7 +464,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
464
464
  - !ruby/object:Gem::Version
465
465
  version: 1.3.1
466
466
  requirements: []
467
- rubygems_version: 3.2.22
467
+ rubygems_version: 3.2.32
468
468
  signing_key:
469
469
  specification_version: 4
470
470
  summary: Admin for Rails