administrate-field-active_storage 1.0.3 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 12fb995471a84f218352f4c630c6de6088c1eec7b975671f42125a1f91fe05d5
4
- data.tar.gz: 797c67a7742599097b761314a457f1f53f3153aeb5c6aa72c4556cfd0a86d449
3
+ metadata.gz: 9995a46284bc16b3ab7b6dcbe2902a5588c94034fc5993badfa203571c5f48c0
4
+ data.tar.gz: a6926e2ebb8590dbf1d384d5d00d895b05c4c3cf134a97784828addeecdea27c
5
5
  SHA512:
6
- metadata.gz: 3d285fd017385d5ce56a18a2ef464b5ec5d981fa065fe8a59706db2b7716676d81fbff44909a4b1543cfb70821c2368057184d0095bf6aaaafcf3e9139ad1b8e
7
- data.tar.gz: 6ccbf0a5119607bda9110ace878002ba9a8fd40ae39573c112c96f14cc69c0fa54855ddf28bc5ce7e437776532a85f2d3f5c44cea8373b4a695176cd78000493
6
+ metadata.gz: 2031ac855e60422a6c6d6d79a51a4cf11424270667800e00454d7ad2f85cdb5b025ff0cbe5774f67e6c8f79cae9553c8744b02cb8fb4c658c74ef0706c59beb7
7
+ data.tar.gz: 203436a2aa02b8c0ec56b709c12dc8efcfb1ac439cadfa8a00f7c79d5ee818bf70932065520eb970bf8ee68486fad4050189f4182097be06c5e5a12083f1c3d5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- administrate-field-active_storage (1.0.2)
4
+ administrate-field-active_storage (1.0.5)
5
5
  administrate (>= 0.2.2)
6
6
  rails (>= 7.0)
7
7
 
@@ -76,12 +76,13 @@ GEM
76
76
  sassc-rails (~> 2.1)
77
77
  selectize-rails (~> 0.6)
78
78
  ast (2.4.2)
79
+ base64 (0.2.0)
79
80
  builder (3.2.4)
80
81
  concurrent-ruby (1.1.9)
81
82
  crass (1.0.6)
82
- date (3.3.4)
83
+ date (3.4.1)
83
84
  erubi (1.10.0)
84
- ffi (1.16.3)
85
+ ffi (1.17.1)
85
86
  globalid (1.2.1)
86
87
  activesupport (>= 6.1)
87
88
  highline (2.0.3)
@@ -125,16 +126,16 @@ GEM
125
126
  method_source (1.0.0)
126
127
  mini_mime (1.1.5)
127
128
  minitest (5.15.0)
128
- net-imap (0.4.11)
129
+ net-imap (0.4.19)
129
130
  date
130
131
  net-protocol
131
132
  net-pop (0.1.2)
132
133
  net-protocol
133
134
  net-protocol (0.2.2)
134
135
  timeout
135
- net-smtp (0.5.0)
136
+ net-smtp (0.5.1)
136
137
  net-protocol
137
- nio4r (2.7.3)
138
+ nio4r (2.7.4)
138
139
  nokogiri (1.13.3-arm64-darwin)
139
140
  racc (~> 1.4)
140
141
  nokogiri (1.13.3-x86_64-darwin)
@@ -190,9 +191,9 @@ GEM
190
191
  sprockets (4.1.1)
191
192
  concurrent-ruby (~> 1.0)
192
193
  rack (> 1, < 3)
193
- sprockets-rails (3.4.2)
194
- actionpack (>= 5.2)
195
- activesupport (>= 5.2)
194
+ sprockets-rails (3.5.2)
195
+ actionpack (>= 6.1)
196
+ activesupport (>= 6.1)
196
197
  sprockets (>= 3.0.0)
197
198
  sqlite3 (1.7.3-arm64-darwin)
198
199
  sqlite3 (1.7.3-x86_64-darwin)
@@ -200,12 +201,13 @@ GEM
200
201
  terminal-table (3.0.2)
201
202
  unicode-display_width (>= 1.1.1, < 3)
202
203
  thor (1.1.0)
203
- tilt (2.3.0)
204
- timeout (0.4.1)
204
+ tilt (2.6.0)
205
+ timeout (0.4.3)
205
206
  tzinfo (2.0.4)
206
207
  concurrent-ruby (~> 1.0)
207
208
  unicode-display_width (2.1.0)
208
- websocket-driver (0.7.6)
209
+ websocket-driver (0.7.7)
210
+ base64
209
211
  websocket-extensions (>= 0.1.0)
210
212
  websocket-extensions (0.1.5)
211
213
  zeitwerk (2.5.2)
data/README.md CHANGED
@@ -54,7 +54,7 @@ class ModelDashboard < Administrate::BaseDashboard
54
54
  }
55
55
 
56
56
  # permitted for has_many_attached
57
- def permitted_attributes
57
+ def permitted_attributes(_action = nil)
58
58
  super + [:attachments => []]
59
59
  end
60
60
  ```
@@ -63,6 +63,43 @@ I know it is not ideal, if you have a workaround please submit a PR.
63
63
  Note: Rails 6 introduced a new config to determine the behavior on updates to `has_many_attached`. Setting `Rails.application.config.active_storage.replace_on_assign_to_many` to `true` will overwrite any existing values (purging the old ones), and setting it to `false` will append the new values. Please note that this configuation was [deprecated with Rails 7.1](https://github.com/rails/rails/blob/v7.0.2.3/activestorage/lib/active_storage/attached/model.rb#L150)
64
64
  >config.active_storage.replace_on_assign_to_many is deprecated and will be removed in Rails 7.1. Make sure that your code works well with config.active_storage.replace_on_assign_to_many set to true before upgrading. To append new attachables to the Active Storage association, prefer using attach. Using association setter would result in purging the existing attached attachments and replacing them with new ones.
65
65
 
66
+ This means that in Rails 7 for `has_many_attached`, whenever a form is submitted, all associations to existing attachments are being removed without the ActiveStorage objects being deleted. This is undesired behaviour because you have to re attach every time you update an object and it will result in orphaned ActiveStorage objects. To fix this and to add the ability to add more attachments to an existing set of attachments, follow this [workaround](https://stackoverflow.com/a/74207496). In short, you can create a concern:
67
+
68
+ ```ruby
69
+ # app/models/concerns/append_to_has_many_attached.rb
70
+ module AppendToHasManyAttached
71
+ def self.[](fields)
72
+ Module.new do
73
+ extend ActiveSupport::Concern
74
+
75
+ fields = Array(fields).compact_blank # will always return an array ( worst case is an empty array)
76
+
77
+ fields.each do |field|
78
+ field = field.to_s # We need the string version
79
+ define_method :"#{field}=" do |attachables|
80
+ attachables = Array(attachables).compact_blank
81
+
82
+ if attachables.any?
83
+ attachment_changes[field] =
84
+ ActiveStorage::Attached::Changes::CreateMany.new(field, self, public_send(field).public_send(:blobs) + attachables)
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ ```
92
+
93
+ And then load this concern in your model:
94
+ ```ruby
95
+ class Model < ApplicationModel
96
+ include AppendToHasManyAttached['files'] # you can include it before or after, order does not matter, explanation below
97
+
98
+ has_many_attached :files
99
+ end
100
+ ```
101
+
102
+ Please note, it does not matter if you prepend or include the module, see [original post](https://stackoverflow.com/a/74207496) for details.
66
103
 
67
104
  ### Prevent N+1 queries
68
105
  In order to prevent N+1 queries from active storage you have to modify your admin model controller, below an example for a model called `User` and with attached avatars
@@ -217,11 +254,17 @@ Displays the number of attachments in the `index` action.
217
254
 
218
255
  Defaults to `true` if number of attachments is not 1.
219
256
 
220
- ### direct_upload
257
+ ### file_field_options
258
+
259
+ Configure any options to give to `file_field`.
260
+
261
+ `multiple` is set by default based on `::ActiveStorage::Attached::Many`, but can be overridden.
262
+
263
+ #### direct
221
264
 
222
265
  Enables direct upload from the browser to the cloud.
223
266
 
224
- Defaults to `false`.
267
+ Defaults to `false`. Configure with `file_field_options: { direct: true }`.
225
268
 
226
269
  Don't forget to include [ActiveStorage JavaScript](https://edgeguides.rubyonrails.org/active_storage_overview.html#direct-uploads). You can use `rails generate administrate:assets:javascripts` to be able to customize Administrate JavaScripts in your application.
227
270
 
@@ -2,7 +2,7 @@ $:.push File.expand_path("../lib", __FILE__)
2
2
 
3
3
  Gem::Specification.new do |gem|
4
4
  gem.name = "administrate-field-active_storage"
5
- gem.version = "1.0.3"
5
+ gem.version = "1.0.5"
6
6
  gem.authors = ["Hamad AlGhanim"]
7
7
  gem.email = ["hamadyalghanim@gmail.com"]
8
8
  gem.homepage = "https://github.com/Dreamersoul/administrate-field-active_storage"
@@ -29,6 +29,6 @@ By default, the input is a text field for the image's URL.
29
29
  I18n.t("administrate.fields.active_storage.add", default: 'Add') :
30
30
  I18n.t("administrate.fields.active_storage.replace", default: 'Replace')
31
31
  %>
32
- <%= f.file_field field.attribute, multiple: field.many?, direct_upload: field.direct? %>
32
+ <%= f.file_field field.attribute, field.file_field_options %>
33
33
  </div>
34
34
  </div>
@@ -40,6 +40,13 @@ module Administrate
40
40
  options.fetch(:show_preview_variant, nil)
41
41
  end
42
42
 
43
+ def file_field_options
44
+ {
45
+ direct_upload: direct?,
46
+ multiple: many?,
47
+ }.merge options.fetch(:file_field_options, {})
48
+ end
49
+
43
50
  def many?
44
51
  data.is_a? ::ActiveStorage::Attached::Many
45
52
  end
data/test_app/Gemfile CHANGED
@@ -8,7 +8,7 @@ gem 'rails', '7.1.2'
8
8
  # Use sqlite3 as the database for Active Record
9
9
  gem 'sqlite3', '~> 1.4'
10
10
  # Use Puma as the app server
11
- gem 'puma', '~> 5.6'
11
+ gem 'puma', '~> 6.0'
12
12
  # Use SCSS for stylesheets
13
13
  gem 'sass-rails', '>= 6'
14
14
  # Use Active Model has_secure_password
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ..
3
3
  specs:
4
- administrate-field-active_storage (1.0.2)
4
+ administrate-field-active_storage (1.0.5)
5
5
  administrate (>= 0.2.2)
6
6
  rails (>= 7.0)
7
7
 
@@ -82,8 +82,8 @@ GEM
82
82
  minitest (>= 5.1)
83
83
  mutex_m
84
84
  tzinfo (~> 2.0)
85
- addressable (2.8.0)
86
- public_suffix (>= 2.0.2, < 5.0)
85
+ addressable (2.8.7)
86
+ public_suffix (>= 2.0.2, < 7.0)
87
87
  administrate (0.20.1)
88
88
  actionpack (>= 6.0, < 8.0)
89
89
  actionview (>= 6.0, < 8.0)
@@ -93,36 +93,37 @@ GEM
93
93
  sassc-rails (~> 2.1)
94
94
  selectize-rails (~> 0.6)
95
95
  base64 (0.2.0)
96
- bigdecimal (3.1.8)
96
+ benchmark (0.4.0)
97
+ bigdecimal (3.1.9)
97
98
  bindex (0.8.1)
98
- builder (3.2.4)
99
+ builder (3.3.0)
99
100
  byebug (11.1.3)
100
- capybara (3.36.0)
101
+ capybara (3.40.0)
101
102
  addressable
102
103
  matrix
103
104
  mini_mime (>= 0.1.3)
104
- nokogiri (~> 1.8)
105
+ nokogiri (~> 1.11)
105
106
  rack (>= 1.6.0)
106
107
  rack-test (>= 0.6.3)
107
108
  regexp_parser (>= 1.5, < 3.0)
108
109
  xpath (~> 3.2)
109
- childprocess (4.1.0)
110
- concurrent-ruby (1.2.3)
111
- connection_pool (2.4.1)
110
+ concurrent-ruby (1.3.5)
111
+ connection_pool (2.5.0)
112
112
  crass (1.0.6)
113
- date (3.3.4)
113
+ date (3.4.1)
114
114
  drb (2.2.1)
115
- erubi (1.12.0)
116
- ffi (1.16.3)
115
+ erubi (1.13.1)
116
+ ffi (1.17.1)
117
117
  globalid (1.2.1)
118
118
  activesupport (>= 6.1)
119
- i18n (1.14.5)
119
+ i18n (1.14.7)
120
120
  concurrent-ruby (~> 1.0)
121
- image_processing (1.12.2)
122
- mini_magick (>= 4.9.5, < 5)
121
+ image_processing (1.14.0)
122
+ mini_magick (>= 4.9.5, < 6)
123
123
  ruby-vips (>= 2.0.17, < 3)
124
- io-console (0.7.2)
125
- irb (1.13.1)
124
+ io-console (0.8.0)
125
+ irb (1.15.1)
126
+ pp (>= 0.6.0)
126
127
  rdoc (>= 4.0.0)
127
128
  reline (>= 0.4.2)
128
129
  jquery-rails (4.6.0)
@@ -141,7 +142,8 @@ GEM
141
142
  activerecord
142
143
  kaminari-core (= 1.2.2)
143
144
  kaminari-core (1.2.2)
144
- loofah (2.22.0)
145
+ logger (1.6.6)
146
+ loofah (2.24.0)
145
147
  crass (~> 1.0.2)
146
148
  nokogiri (>= 1.12.0)
147
149
  mail (2.8.1)
@@ -149,44 +151,50 @@ GEM
149
151
  net-imap
150
152
  net-pop
151
153
  net-smtp
152
- marcel (1.0.2)
154
+ marcel (1.0.4)
153
155
  matrix (0.4.2)
154
- mini_magick (4.12.0)
156
+ mini_magick (5.1.2)
157
+ benchmark
158
+ logger
155
159
  mini_mime (1.1.5)
156
- minitest (5.23.0)
157
- mutex_m (0.2.0)
158
- net-imap (0.4.5)
160
+ minitest (5.25.4)
161
+ mutex_m (0.3.0)
162
+ net-imap (0.4.19)
159
163
  date
160
164
  net-protocol
161
165
  net-pop (0.1.2)
162
166
  net-protocol
163
167
  net-protocol (0.2.2)
164
168
  timeout
165
- net-smtp (0.4.0)
169
+ net-smtp (0.5.1)
166
170
  net-protocol
167
- nio4r (2.6.0)
168
- nokogiri (1.16.5-arm64-darwin)
171
+ nio4r (2.7.4)
172
+ nokogiri (1.17.2-arm64-darwin)
169
173
  racc (~> 1.4)
170
- nokogiri (1.16.5-x86_64-darwin)
174
+ nokogiri (1.17.2-x86_64-darwin)
171
175
  racc (~> 1.4)
172
- nokogiri (1.16.5-x86_64-linux)
176
+ nokogiri (1.17.2-x86_64-linux)
173
177
  racc (~> 1.4)
174
- psych (5.1.2)
178
+ pp (0.6.2)
179
+ prettyprint
180
+ prettyprint (0.2.0)
181
+ psych (5.2.3)
182
+ date
175
183
  stringio
176
- public_suffix (4.0.6)
177
- puma (5.6.4)
184
+ public_suffix (6.0.1)
185
+ puma (6.6.0)
178
186
  nio4r (~> 2.0)
179
- racc (1.7.3)
180
- rack (3.0.11)
181
- rack-mini-profiler (2.3.3)
187
+ racc (1.8.1)
188
+ rack (3.1.10)
189
+ rack-mini-profiler (2.3.4)
182
190
  rack (>= 1.2.0)
183
- rack-session (2.0.0)
191
+ rack-session (2.1.0)
192
+ base64 (>= 0.1.0)
184
193
  rack (>= 3.0.0)
185
- rack-test (2.1.0)
194
+ rack-test (2.2.0)
186
195
  rack (>= 1.3)
187
- rackup (2.1.0)
196
+ rackup (2.2.1)
188
197
  rack (>= 3)
189
- webrick (~> 1.8)
190
198
  rails (7.1.2)
191
199
  actioncable (= 7.1.2)
192
200
  actionmailbox (= 7.1.2)
@@ -205,9 +213,9 @@ GEM
205
213
  activesupport (>= 5.0.0)
206
214
  minitest
207
215
  nokogiri (>= 1.6)
208
- rails-html-sanitizer (1.6.0)
216
+ rails-html-sanitizer (1.6.2)
209
217
  loofah (~> 2.21)
210
- nokogiri (~> 1.14)
218
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
211
219
  railties (7.1.2)
212
220
  actionpack (= 7.1.2)
213
221
  activesupport (= 7.1.2)
@@ -217,15 +225,16 @@ GEM
217
225
  thor (~> 1.0, >= 1.2.2)
218
226
  zeitwerk (~> 2.6)
219
227
  rake (13.2.1)
220
- rdoc (6.6.3.1)
228
+ rdoc (6.12.0)
221
229
  psych (>= 4.0.0)
222
- regexp_parser (2.2.0)
223
- reline (0.5.7)
230
+ regexp_parser (2.10.0)
231
+ reline (0.6.0)
224
232
  io-console (~> 0.5)
225
- rexml (3.2.5)
226
- ruby-vips (2.2.0)
233
+ rexml (3.4.1)
234
+ ruby-vips (2.2.3)
227
235
  ffi (~> 1.12)
228
- rubyzip (2.3.2)
236
+ logger
237
+ rubyzip (2.4.1)
229
238
  sass-rails (6.0.0)
230
239
  sassc-rails (~> 2.1, >= 2.1.1)
231
240
  sassc (2.4.0)
@@ -237,40 +246,44 @@ GEM
237
246
  sprockets-rails
238
247
  tilt
239
248
  selectize-rails (0.12.6)
240
- selenium-webdriver (4.1.0)
241
- childprocess (>= 0.5, < 5.0)
249
+ selenium-webdriver (4.26.0)
250
+ base64 (~> 0.2)
251
+ logger (~> 1.4)
242
252
  rexml (~> 3.2, >= 3.2.5)
243
- rubyzip (>= 1.2.2)
253
+ rubyzip (>= 1.2.2, < 3.0)
254
+ websocket (~> 1.0)
244
255
  sprockets (4.2.1)
245
256
  concurrent-ruby (~> 1.0)
246
257
  rack (>= 2.2.4, < 4)
247
- sprockets-rails (3.4.2)
248
- actionpack (>= 5.2)
249
- activesupport (>= 5.2)
258
+ sprockets-rails (3.5.2)
259
+ actionpack (>= 6.1)
260
+ activesupport (>= 6.1)
250
261
  sprockets (>= 3.0.0)
251
262
  sqlite3 (1.7.3-arm64-darwin)
252
263
  sqlite3 (1.7.3-x86_64-darwin)
253
264
  sqlite3 (1.7.3-x86_64-linux)
254
- stringio (3.1.0)
255
- thor (1.3.1)
256
- tilt (2.3.0)
257
- timeout (0.4.1)
265
+ stringio (3.1.3)
266
+ thor (1.3.2)
267
+ tilt (2.6.0)
268
+ timeout (0.4.3)
258
269
  tzinfo (2.0.6)
259
270
  concurrent-ruby (~> 1.0)
260
- web-console (4.2.0)
271
+ web-console (4.2.1)
261
272
  actionview (>= 6.0.0)
262
273
  activemodel (>= 6.0.0)
263
274
  bindex (>= 0.4.0)
264
275
  railties (>= 6.0.0)
265
- webrick (1.8.1)
266
- websocket-driver (0.7.6)
276
+ websocket (1.2.11)
277
+ websocket-driver (0.7.7)
278
+ base64
267
279
  websocket-extensions (>= 0.1.0)
268
280
  websocket-extensions (0.1.5)
269
281
  xpath (3.2.0)
270
282
  nokogiri (~> 1.8)
271
- zeitwerk (2.6.14)
283
+ zeitwerk (2.6.18)
272
284
 
273
285
  PLATFORMS
286
+ arm64-darwin-22
274
287
  arm64-darwin-23
275
288
  x86_64-darwin-20
276
289
  x86_64-darwin-21
@@ -282,7 +295,7 @@ DEPENDENCIES
282
295
  byebug
283
296
  capybara (>= 3.26)
284
297
  image_processing (~> 1.2)
285
- puma (~> 5.6)
298
+ puma (~> 6.0)
286
299
  rack-mini-profiler (~> 2.0)
287
300
  rails (= 7.1.2)
288
301
  sass-rails (>= 6)
@@ -44,7 +44,7 @@ module Admin
44
44
  }
45
45
  end
46
46
 
47
- assert_response :unprocessable_entity
47
+ assert_response 422
48
48
  end
49
49
  end
50
50
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: administrate-field-active_storage
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hamad AlGhanim
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-05-17 00:00:00.000000000 Z
11
+ date: 2025-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: administrate