card-mod-carrierwave 0.16.0 → 0.18.0

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: f91d51960354436b85df108967757650bdd9713965eedd25f7f7e03092e2ae58
4
- data.tar.gz: aa239da9035dcb91b615dcd634981c22a8b061630f10f394e6776ff291b7ecc8
3
+ metadata.gz: af54c8d9b6dd92aa82b0c8c6c4bb628db93f587719f3f32d180186cdaea28b3d
4
+ data.tar.gz: fd615e28d1721b69180c89153088fab1649cda08faca0fc8c8ed82a42d612385
5
5
  SHA512:
6
- metadata.gz: 6d7fbddc2d23f057e739048afe54aa1793b3a6ee6cef889ff84978838b3bc55b1bd5b225654491c6dc85b14ab9fd75d56c3e94eceae1143fc9a375d8c5600705
7
- data.tar.gz: 7b7316b9ff90b00a3248d9bad5ca535509137bb44083465a5236d415d8fb65997408fe8d07e6223000b218aa0aebdbccfc25074509f314313401c372204f1585
6
+ metadata.gz: 4feb890ba0bbaa2150544e44bbc09295e0cc5acd0c67a910af1fdc10d60bcbfcc24151ab433e09af5178f8a4ed07392b39a04c093e0784aa1679cddb1ab30594
7
+ data.tar.gz: 53ca6ac88541efd2e576661c20f2c4fff8b79cc11990e43b6a2d9872d001e1d5a1e9d4e471e3678997c0aa90a2b94f13455a8765b29a55136f6cb665b16d6ebc
data/config/admin.yml ADDED
@@ -0,0 +1,4 @@
1
+ cardtypes:
2
+ upload:
3
+ - file
4
+ - image
@@ -1,7 +1,10 @@
1
1
  require "carrierwave"
2
2
 
3
3
  module CarrierWave
4
- # adapt carrierwave mount to cards
4
+ # Adapt carrierwave mount to cards.
5
+ # We translate the active record hooks in
6
+ # https://github.com/carrierwaveuploader/carrierwave/blob/v3.0.5/lib/carrierwave/orm/activerecord.rb
7
+ # to card events.
5
8
  module CardMount
6
9
  include CarrierWave::Mount
7
10
 
@@ -18,14 +21,12 @@ module CarrierWave
18
21
  super
19
22
 
20
23
  class_eval <<-RUBY, __FILE__, __LINE__ + 1
21
- event :store_#{column}_event, :finalize,
22
- on: :save, when: :store_#{column}_event? do
24
+ event :store_#{column}_event, :finalize, when: :store_#{column}_event? do
23
25
  store_#{column}!
24
26
  end
25
27
 
26
28
  # remove files only if card has no history
27
- event :remove_#{column}_event, :finalize,
28
- on: :delete, when: proc { |c| !c.history? } do
29
+ event :remove_#{column}_event, :finalize, on: :delete, when: :no_history? do
29
30
  remove_#{column}!
30
31
  end
31
32
 
@@ -33,13 +34,13 @@ module CarrierWave
33
34
  mark_remove_#{column}_false
34
35
  end
35
36
 
36
- event :store_previous_changes_for_#{column}_event, :store,
37
- on: :update, when: proc { |c| !c.history? } do
38
- store_previous_changes_for_#{column}
37
+ event :reset_previous_changes_for_#{column}_event, :finalize,
38
+ when: :no_history? do
39
+ reset_previous_changes_for_#{column}
39
40
  end
40
41
 
41
- event :remove_previously_stored_#{column}_event, :finalize,
42
- on: :update, when: proc { |c| !c.history?} do
42
+ event :remove_previously_stored_#{column}_event, :finalize, on: :update,
43
+ when: :no_history? do
43
44
  remove_previously_stored_#{column}
44
45
  end
45
46
 
@@ -61,13 +62,8 @@ module CarrierWave
61
62
  "#{column}".to_sym
62
63
  end
63
64
 
64
- def read_uploader *args
65
- read_attribute *args
66
- end
67
-
68
- def write_uploader *args
69
- write_attribute *args
70
- end
65
+ def read_uploader *args; read_attribute *args; end
66
+ def write_uploader *args; write_attribute *args; end
71
67
 
72
68
  def #{column}=(new_file)
73
69
  return if new_file.blank?
@@ -128,7 +124,20 @@ module CarrierWave
128
124
  end
129
125
  end
130
126
  end
127
+
128
+ def reload(*)
129
+ @_mounters = nil
130
+ super
131
+ end
131
132
  RUBY
132
133
  end
133
134
  end
135
+
136
+ # The temporary identifiers from Carrierwave's mounters kill CardMount;
137
+ # We don't seem to need them.
138
+ class Mounter
139
+ def write_temporary_identifier
140
+ # noop
141
+ end
142
+ end
134
143
  end
@@ -175,6 +175,10 @@ module CarrierWave
175
175
  end
176
176
  end
177
177
 
178
+ def temporary_identifier
179
+ db_content
180
+ end
181
+
178
182
  # @option opts [Symbol] :absolute - return absolute url
179
183
  def url opts={}
180
184
  if model.cloud?
@@ -234,13 +238,26 @@ module CarrierWave
234
238
  class SanitizedFile
235
239
  def content_type
236
240
  # the original content_type method doesn't seem to be very reliable
237
- # It uses mime_magic_content_type - which returns invalid/invalid for css files
238
- # that start with a comment - as the second option. (we switch the order and
239
- # use it as the third option)
241
+ # It uses declared_content_type - which sometimes returns "text/plain" for asset
242
+ # files for unknown reasons. (we switch the order and use it as the third option)
240
243
  @content_type ||=
241
- existing_content_type ||
242
- mini_mime_content_type ||
243
- mime_magic_content_type
244
+ guessed_safe_content_type ||
245
+ identified_content_type ||
246
+ declared_content_type ||
247
+ Marcel::MimeType::BINARY
248
+ end
249
+
250
+ def guessed_safe_content_type
251
+ # overrides the default method which was returning "application/javascript" instead
252
+ # of "text/javascript" for our .js files.
253
+ return unless path
254
+
255
+ type = Marcel::Magic.by_path(original_filename).to_s
256
+ if type.start_with? "text/", "application/json'"
257
+ type
258
+ elsif type == "application/javascript"
259
+ "text/javascript"
260
+ end
244
261
  end
245
262
  end
246
263
 
@@ -254,6 +271,8 @@ module CarrierWave
254
271
  # put version at the end of the filename
255
272
  def full_filename for_file
256
273
  name = super(for_file)
274
+ return unless name.present?
275
+
257
276
  parts = name.split "."
258
277
  basename = [parts.shift, version_name].compact.join("-")
259
278
  "#{basename}.#{parts.join('.')}"
@@ -3,7 +3,7 @@ require "mini_magick"
3
3
  module CarrierWave
4
4
  # Adds image specific version handling to {FileCardUploader}.
5
5
  # The ImageCardUploader creates five versions of different sizes when it
6
- # uploads an imagae file:
6
+ # uploads an image file:
7
7
  # icon (16x16), small (75x75), medium (200X200), large (500x500) and
8
8
  # the original size.
9
9
  class ImageCardUploader < FileCardUploader
@@ -48,7 +48,7 @@ module CarrierWave
48
48
  # add 'original' if no version is given
49
49
  def full_filename for_file
50
50
  name = super(for_file)
51
- if version_name
51
+ if name.blank? || version_name
52
52
  name
53
53
  else
54
54
  parts = name.split "."
@@ -29,13 +29,17 @@ def storage_type_error error_name
29
29
  end
30
30
 
31
31
  def mod_from_content
32
- if (m = content&.match %r{^:[^/]+/([^.]+)})
32
+ if (m = mod_name_match content)
33
33
  m[1] # current mod_file format
34
34
  else
35
35
  mod_from_deprecated_content
36
36
  end
37
37
  end
38
38
 
39
+ def mod_name_match cont
40
+ cont&.match %r{^:[^/]+/([^.]+)}
41
+ end
42
+
39
43
  # place for files of mod file cards
40
44
  def coded_dir new_mod=nil
41
45
  dir = File.join mod_dir(new_mod), MOD_FILE_DIR, codename.to_s
@@ -12,7 +12,10 @@ end
12
12
 
13
13
  # we need a card id for the path so we have to update db_content when we have
14
14
  # an id
15
- event :correct_identifier, :finalize, on: :create, when: proc { |c| !c.web? } do
15
+ event :correct_identifier, :finalize, on: :save, when: proc { |c| !c.web? } do
16
+ correct_id = attachment.db_content
17
+ return if db_content == correct_id
18
+
16
19
  update_column :db_content, attachment.db_content
17
20
  expire
18
21
  end
@@ -20,7 +23,7 @@ end
20
23
  event :save_original_filename, :prepare_to_store, on: :save, when: :file_ready_to_save? do
21
24
  return unless @current_action
22
25
 
23
- @current_action.update! comment: original_filename
26
+ @current_action.comment = original_filename
24
27
  end
25
28
 
26
29
  event :validate_file_exist, :validate, on: :create, skip: :allowed do
@@ -101,10 +104,10 @@ def duplicate?
101
104
  end
102
105
 
103
106
  def delete_files_for_action action
104
- with_selected_action_id(action.id) do
107
+ with_selected_action_id action.id do
105
108
  attachment.file.delete
106
109
  attachment.versions.each_value do |version|
107
- version.file.delete
110
+ version.file&.delete
108
111
  end
109
112
  end
110
113
  end
data/set/type/file.rb CHANGED
@@ -9,15 +9,15 @@ module SelectedAction
9
9
 
10
10
  def last_content_action_id
11
11
  # find action id from content (saves lookups)
12
- db_content.to_s.split(%r{[/.]})[-2]
12
+ aid = db_content.to_s.split(%r{[/.]})[-2]
13
+ aid.number? ? aid.to_i : nil
13
14
  end
14
15
  end
15
16
  include SelectedAction
16
17
 
17
18
  format do
18
19
  view :source do
19
- file = card.attachment
20
- file.valid? ? contextualize_path(file.url) : ""
20
+ source
21
21
  end
22
22
 
23
23
  view :core do
@@ -32,17 +32,22 @@ format do
32
32
 
33
33
  def handle_source
34
34
  rescuing_file_source_error do
35
- source = _render_source
36
- if source.blank?
35
+ src = source
36
+ if src.blank?
37
37
  ""
38
38
  elsif block_given?
39
- yield source
39
+ yield src
40
40
  else
41
- source
41
+ src
42
42
  end
43
43
  end
44
44
  end
45
45
 
46
+ def source
47
+ file = card.attachment
48
+ file.valid? ? contextualize_path(file.url) : ""
49
+ end
50
+
46
51
  def selected_version
47
52
  card.attachment
48
53
  end
@@ -69,12 +74,24 @@ format :file do
69
74
  args_for_send_file
70
75
  end
71
76
 
77
+ private
78
+
72
79
  def args_for_send_file
73
80
  file = selected_version
74
81
  [file.path, { type: file.content_type,
75
82
  filename: "#{card.name.safe_key}#{file.extension}",
76
83
  x_sendfile: true,
77
- disposition: (params[:format] == "file" ? "attachment" : "inline") }]
84
+ disposition: disposition }]
85
+ end
86
+
87
+ def disposition
88
+ if params[:disposition]
89
+ params[:disposition]
90
+ elsif params[:format] == "file"
91
+ "attachment"
92
+ else
93
+ "inline"
94
+ end
78
95
  end
79
96
 
80
97
  def set_response_headers
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.0
4
+ version: 0.18.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2023-11-18 00:00:00.000000000 Z
13
+ date: 2024-10-31 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,84 +18,98 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.106.0
21
+ version: 1.108.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.106.0
28
+ version: 1.108.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: carrierwave
31
31
  requirement: !ruby/object:Gem::Requirement
32
32
  requirements:
33
33
  - - "~>"
34
34
  - !ruby/object:Gem::Version
35
- version: '2.2'
35
+ version: '3.0'
36
36
  type: :runtime
37
37
  prerelease: false
38
38
  version_requirements: !ruby/object:Gem::Requirement
39
39
  requirements:
40
40
  - - "~>"
41
41
  - !ruby/object:Gem::Version
42
- version: '2.2'
42
+ version: '3.0'
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: mini_magick
45
45
  requirement: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: '4.2'
49
+ version: '4.12'
50
50
  type: :runtime
51
51
  prerelease: false
52
52
  version_requirements: !ruby/object:Gem::Requirement
53
53
  requirements:
54
54
  - - "~>"
55
55
  - !ruby/object:Gem::Version
56
- version: '4.2'
56
+ version: '4.12'
57
57
  - !ruby/object:Gem::Dependency
58
58
  name: ssrf_filter
59
59
  requirement: !ruby/object:Gem::Requirement
60
60
  requirements:
61
61
  - - "~>"
62
62
  - !ruby/object:Gem::Version
63
- version: 1.0.7
63
+ version: '1.1'
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - "~>"
69
69
  - !ruby/object:Gem::Version
70
- version: 1.0.7
70
+ version: '1.1'
71
+ - !ruby/object:Gem::Dependency
72
+ name: marcel
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - '='
76
+ - !ruby/object:Gem::Version
77
+ version: 1.0.2
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - '='
83
+ - !ruby/object:Gem::Version
84
+ version: 1.0.2
71
85
  - !ruby/object:Gem::Dependency
72
86
  name: card-mod-history
73
87
  requirement: !ruby/object:Gem::Requirement
74
88
  requirements:
75
89
  - - '='
76
90
  - !ruby/object:Gem::Version
77
- version: 0.16.0
91
+ version: 0.18.0
78
92
  type: :runtime
79
93
  prerelease: false
80
94
  version_requirements: !ruby/object:Gem::Requirement
81
95
  requirements:
82
96
  - - '='
83
97
  - !ruby/object:Gem::Version
84
- version: 0.16.0
98
+ version: 0.18.0
85
99
  - !ruby/object:Gem::Dependency
86
100
  name: card-mod-permissions
87
101
  requirement: !ruby/object:Gem::Requirement
88
102
  requirements:
89
103
  - - '='
90
104
  - !ruby/object:Gem::Version
91
- version: 0.16.0
105
+ version: 0.18.0
92
106
  type: :runtime
93
107
  prerelease: false
94
108
  version_requirements: !ruby/object:Gem::Requirement
95
109
  requirements:
96
110
  - - '='
97
111
  - !ruby/object:Gem::Version
98
- version: 0.16.0
112
+ version: 0.18.0
99
113
  description: ''
100
114
  email:
101
115
  - info@decko.org
@@ -107,6 +121,7 @@ files:
107
121
  - README.md
108
122
  - assets/script/upload.js.coffee
109
123
  - assets/style/file.scss
124
+ - config/admin.yml
110
125
  - config/early/carrierwave.rb
111
126
  - config/early/mini_magick.rb
112
127
  - config/locales/de.yml
@@ -156,7 +171,7 @@ files:
156
171
  - set/type/image/html_views.rb
157
172
  homepage: https://decko.org
158
173
  licenses:
159
- - GPL-3.0
174
+ - GPL-3.0-or-later
160
175
  metadata:
161
176
  source_code_uri: https://github.com/decko-commons/decko
162
177
  homepage_uri: https://decko.org
@@ -173,14 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
173
188
  requirements:
174
189
  - - ">="
175
190
  - !ruby/object:Gem::Version
176
- version: '2.5'
191
+ version: '3.0'
177
192
  required_rubygems_version: !ruby/object:Gem::Requirement
178
193
  requirements:
179
194
  - - ">="
180
195
  - !ruby/object:Gem::Version
181
196
  version: '0'
182
197
  requirements: []
183
- rubygems_version: 3.4.10
198
+ rubygems_version: 3.5.7
184
199
  signing_key:
185
200
  specification_version: 4
186
201
  summary: File and Image handling