card-mod-carrierwave 0.11.4 → 0.11.5

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: 4db88ba4c61088ed0c4b4f7f449391c40989dc9e65dab9351ba39adbca478ab3
4
- data.tar.gz: 00eeb5ca66fcc328ab975537e1412c6321fe9698830ef0118b627f81e88a1a9f
3
+ metadata.gz: b3189d4e4979c66b05d69e7b09a602098410d5df3faa5cdd19a96b7b026a69bb
4
+ data.tar.gz: 774a0049c1c77d4373d5769a965734b797e916606f8ebd959ed97c39315f5646
5
5
  SHA512:
6
- metadata.gz: a9c4885adefd2d41ebbc579a427c06431b3b88539fba3723a27cccefe18603853ee21f8cce4423f7f4c52acbe83173b94bee094833d3db21b47ce46349b94ad9
7
- data.tar.gz: c67f091d70fed1c80f7a842ac69f4f620547ef9b4679e9c48f036021f255be0c2a88b6ee81940c09c25b63b17056fca344b60d47b6c8d77bd437c655efd49f70
6
+ metadata.gz: 2091526b0eb3da1d50ec833d7d990848a4bd6968b4595a235debccd6b5d802dcb5b32bf20a2abe6b2d0ba2679ad1d8564c755ea2d06f435563cdb08bf76e46e1
7
+ data.tar.gz: d10af461b8cc1ef9d0eaf8147274ab8e40f9a0106f87e8f153ccd2b4884ff73667fc53c6dfab8391f541dd3e80a552b06fc1d3eb03fd42d3174fdbd150653632
@@ -125,16 +125,17 @@ module CarrierWave
125
125
  #
126
126
  class FileCardUploader < Uploader::Base
127
127
  attr_accessor :mod
128
+
128
129
  include Card::Env::Location
129
130
  include Path
130
131
 
131
- STORAGE_TYPES = [:cloud, :web, :coded, :local].freeze
132
- CONFIG_OPTIONS = [:provider, :attributes, :directory, :public, :credentials,
133
- :authenticated_url_expiration, :use_ssl_for_aws].freeze
134
- CONFIG_CREDENTIAL_OPTIONS = [
135
- :provider,
136
- :aws_access_key_id, :aws_secret_access_key, :region, :host, :endpoint,
137
- :google_access_key_id, :google_secret_access_key
132
+ STORAGE_TYPES = %i[cloud web coded local].freeze
133
+ CONFIG_OPTIONS = %i[provider attributes directory public credentials
134
+ authenticated_url_expiration use_ssl_for_aws].freeze
135
+ CONFIG_CREDENTIAL_OPTIONS = %i[
136
+ provider
137
+ aws_access_key_id aws_secret_access_key region host endpoint
138
+ google_access_key_id google_secret_access_key
138
139
  ].freeze
139
140
  delegate :store_dir, :retrieve_dir, :file_dir, :mod, :bucket, to: :model
140
141
 
@@ -170,6 +171,7 @@ module CarrierWave
170
171
  model.with_storage_options opts do
171
172
  return model.content if model.web?
172
173
  return "" unless file.present?
174
+
173
175
  "%s/%s" % [file_dir, url_filename]
174
176
  end
175
177
  end
@@ -20,7 +20,7 @@ module CarrierWave
20
20
  end
21
21
 
22
22
  def cache_dir
23
- @model.files_base_dir + "/cache"
23
+ "#{@model.files_base_dir}/cache"
24
24
  end
25
25
 
26
26
  # Carrierwave calls store_path without argument when it stores the file
@@ -10,7 +10,7 @@ module CarrierWave
10
10
  include CarrierWave::MiniMagick
11
11
 
12
12
  def path version=nil
13
- (version && version != :original) ? versions[version].path : super()
13
+ version && version != :original ? versions[version].path : super()
14
14
  end
15
15
 
16
16
  version :icon, if: :create_versions?, from_version: :small do
@@ -17,11 +17,13 @@ end
17
17
 
18
18
  event :save_original_filename, :prepare_to_store, on: :save, when: :file_ready_to_save? do
19
19
  return unless @current_action
20
+
20
21
  @current_action.update! comment: original_filename
21
22
  end
22
23
 
23
24
  event :validate_file_exist, :validate, on: :create do
24
25
  return if empty_ok?
26
+
25
27
  if will_be_stored_as == :web
26
28
  errors.add "url is missing" if content.blank?
27
29
  elsif !attachment.file.present?
@@ -40,12 +42,14 @@ def file_ready_to_save?
40
42
  attachment_is_changing?
41
43
  end
42
44
 
43
- def item_names _args={} # needed for flexmail attachments. hacky.
45
+ # needed for flexmail attachments. hacky.
46
+ def item_names _args={}
44
47
  [name]
45
48
  end
46
49
 
47
50
  def original_filename
48
51
  return content.split("/").last if web?
52
+
49
53
  attachment.original_filename
50
54
  end
51
55
 
@@ -90,6 +94,7 @@ end
90
94
 
91
95
  def revision action, before_action=false
92
96
  return unless (result = super)
97
+
93
98
  result[:empty_ok] = true
94
99
  result
95
100
  end
@@ -20,6 +20,7 @@ end
20
20
 
21
21
  def new_card_bucket
22
22
  return unless new_card?
23
+
23
24
  # If the file is assigned before the bucket option we have to
24
25
  # check if there is a bucket options in set_specific.
25
26
  # That happens for exmaple when the file appears before the bucket in the
@@ -34,6 +35,7 @@ end
34
35
 
35
36
  def load_bucket_config
36
37
  return {} unless bucket
38
+
37
39
  bucket_config = Cardio.config.file_buckets&.dig(bucket.to_sym) || {}
38
40
  bucket_config.symbolize_keys!
39
41
  bucket_config[:credentials]&.symbolize_keys!
@@ -96,6 +98,7 @@ def each_credential_from_env
96
98
  regexp = credential_from_env_regexp
97
99
  ENV.each_key do |env_key|
98
100
  next unless (m = regexp.match env_key)
101
+
99
102
  yield m[:option].downcase.to_sym
100
103
  end
101
104
  end
@@ -112,6 +115,7 @@ end
112
115
 
113
116
  def bucket_from_content
114
117
  return unless content
118
+
115
119
  content.match(/^\((?<bucket>[^)]+)\)/) { |m| m[:bucket] }
116
120
  end
117
121
 
@@ -1,6 +1,7 @@
1
1
  event :lose_coded_status_on_update, :initialize, on: :update, when: :coded? do
2
2
  # unless explicit
3
3
  return if @new_mod
4
+
4
5
  @new_storage_type ||= storage_type_from_config
5
6
  end
6
7
 
@@ -1,4 +1,3 @@
1
-
2
1
  event :update_public_link_on_create, :integrate, on: :create, when: :local? do
3
2
  update_public_link
4
3
  end
@@ -9,6 +8,7 @@ end
9
8
 
10
9
  event :update_public_link, after: :update_read_rule, when: :local? do
11
10
  return if content.blank?
11
+
12
12
  if who_can(:read).include? Card::AnyoneID
13
13
  create_public_links
14
14
  else
@@ -21,6 +21,7 @@ private
21
21
  def create_public_links
22
22
  path = attachment.public_path
23
23
  return if File.exist? path
24
+
24
25
  FileUtils.mkdir_p File.dirname(path)
25
26
  File.symlink attachment.path, path unless File.symlink? path
26
27
  create_versions_public_links
@@ -29,6 +30,7 @@ end
29
30
  def create_versions_public_links
30
31
  attachment.versions.each_value do |version|
31
32
  next if File.symlink? version.public_path
33
+
32
34
  File.symlink version.path, version.public_path
33
35
  end
34
36
  end
@@ -36,5 +38,6 @@ end
36
38
  def remove_public_links
37
39
  symlink_dir = File.dirname attachment.public_path
38
40
  return unless Dir.exist? symlink_dir
41
+
39
42
  FileUtils.rm_rf symlink_dir
40
43
  end
@@ -25,6 +25,7 @@ def mod_dir new_mod=nil
25
25
  dir = Cardio::Mod.dirs.path(mod_name) || (mod_name.to_sym == :test && "test")
26
26
 
27
27
  raise Error, "can't find mod \"#{mod_name}\"" unless dir
28
+
28
29
  dir
29
30
  end
30
31
 
@@ -61,8 +61,8 @@ def mod
61
61
  end
62
62
 
63
63
  def mod_from_content
64
- if content =~ %r{^:[^/]+/([^.]+)}
65
- Regexp.last_match(1) # current mod_file format
64
+ if (m = content.match %r{^:[^/]+/([^.]+)})
65
+ m[1] # current mod_file format
66
66
  else
67
67
  mod_from_deprecated_content
68
68
  end
@@ -70,8 +70,9 @@ end
70
70
 
71
71
  # old format is still used in card_changes
72
72
  def mod_from_deprecated_content
73
- return if content =~ /^\~/
73
+ return if content.match?(/^~/)
74
74
  return unless (lines = content.split("\n")) && lines.size == 4
75
+
75
76
  lines.last
76
77
  end
77
78
 
@@ -95,10 +96,10 @@ end
95
96
 
96
97
  def storage_type_from_content
97
98
  case content
98
- when /^\(/ then :cloud
99
- when %r{/^https?\:/} then :web
100
- when /^~/ then :local
101
- when /^\:/ then :coded
99
+ when /^\(/ then :cloud
100
+ when %r{/^https?:/} then :web
101
+ when /^~/ then :local
102
+ when /^:/ then :coded
102
103
  else
103
104
  if deprecated_mod_file?
104
105
  :coded
@@ -120,7 +121,7 @@ end
120
121
 
121
122
  def storage_type= value
122
123
  known_storage_type? value
123
- if @action == :update #&& storage_type != value
124
+ if @action == :update # && storage_type != value
124
125
  # we cant update the storage type directly here
125
126
  # if we do then the uploader doesn't find the file we want to update
126
127
  @new_storage_type = value
@@ -142,6 +143,7 @@ end
142
143
  def stash_and_set_storage_options opts
143
144
  %i[storage_type mod bucket].each_with_object({}) do |opt_name, old_values|
144
145
  next unless opts[opt_name]
146
+
145
147
  old_values[opt_name] = instance_variable_get "@#{opt_name}"
146
148
  instance_variable_set "@#{opt_name}", opts[opt_name]
147
149
  old_values
@@ -153,7 +155,7 @@ def temporary_storage_type_change?
153
155
  end
154
156
 
155
157
  def validate_temporary_storage_type_change type=nil
156
- return unless (type ||= @new_storage_type)
158
+ return unless type ||= @new_storage_type
157
159
  raise Error, unknown_storage_type(type) unless known_storage_type? type
158
160
  if type == :coded && codename.blank?
159
161
  raise Error, "codename needed for storage type :coded"
@@ -27,6 +27,7 @@ end
27
27
  event :assign_attachment_on_create, :initialize,
28
28
  after: :assign_action, on: :create, when: :save_preliminary_upload? do
29
29
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
30
+
30
31
  upload_cache_card.selected_action_id = action.id
31
32
  upload_cache_card.select_file_revision
32
33
  assign_attachment upload_cache_card.attachment.file, action.comment
@@ -35,6 +36,7 @@ end
35
36
  event :assign_attachment_on_update, :initialize,
36
37
  after: :assign_action, on: :update, when: :save_preliminary_upload? do
37
38
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
39
+
38
40
  uploaded_file = with_selected_action_id(action.id) { attachment.file }
39
41
  assign_attachment uploaded_file, action.comment
40
42
  end
@@ -48,6 +50,7 @@ end
48
50
  event :delete_cached_upload_file_on_create, :integrate,
49
51
  on: :create, when: :save_preliminary_upload? do
50
52
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
53
+
51
54
  upload_cache_card.delete_files_for_action action
52
55
  action.delete
53
56
  end
@@ -61,6 +64,7 @@ end
61
64
  event :delete_cached_upload_file_on_update, :integrate,
62
65
  on: :update, when: :save_preliminary_upload? do
63
66
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
67
+
64
68
  delete_files_for_action action
65
69
  action.delete
66
70
  end
data/set/self/favicon.rb CHANGED
@@ -6,6 +6,7 @@ format :html do
6
6
 
7
7
  view :link_tag, perms: :none do
8
8
  return unless (source = render :source, size: :small)
9
+
9
10
  tag :link, rel: "shortcut icon", href: source
10
11
  end
11
12
 
data/set/type/file.rb CHANGED
@@ -9,8 +9,9 @@ module SelectedAction
9
9
 
10
10
  def last_content_action_id
11
11
  return super if temporary_storage_type_change?
12
+
12
13
  # find action id from content (saves lookups)
13
- db_content.to_s.split(%r{[/\.]})[-2]
14
+ db_content.to_s.split(%r{[/.]})[-2]
14
15
  end
15
16
  end
16
17
  include SelectedAction
@@ -19,6 +20,7 @@ format do
19
20
  view :source do
20
21
  file = card.attachment
21
22
  return "" unless file.valid?
23
+
22
24
  contextualize_path file.url
23
25
  end
24
26
 
@@ -33,17 +35,26 @@ format do
33
35
  end
34
36
 
35
37
  def handle_source
36
- source = _render_source
37
- return "" if source.blank?
38
- block_given? ? yield(source) : source
39
- rescue => e
40
- Rails.logger.info "Error with file source: #{e.message}"
41
- t :carrierwave_file_error
38
+ rescuing_file_source_error do
39
+ source = _render_source
40
+ return "" if source.blank?
41
+
42
+ block_given? ? yield(source) : source
43
+ end
42
44
  end
43
45
 
44
46
  def selected_version
45
47
  card.attachment
46
48
  end
49
+
50
+ private
51
+
52
+ def rescuing_file_source_error
53
+ yield
54
+ rescue StandardError => e
55
+ Rails.logger.info "Error with file source: #{e.message}"
56
+ t :carrierwave_file_error
57
+ end
47
58
  end
48
59
 
49
60
  format :file do
@@ -53,6 +64,7 @@ format :file do
53
64
  attachment_format = card.attachment_format(params[:format])
54
65
  return _render_not_found unless attachment_format
55
66
  return card.format(:html).render_core if card.remote_storage?
67
+
56
68
  set_response_headers
57
69
  args_for_send_file
58
70
  end
@@ -60,13 +72,14 @@ format :file do
60
72
  def args_for_send_file
61
73
  file = selected_version
62
74
  [file.path, { type: file.content_type,
63
- filename: "#{card.name.safe_key}#{file.extension}",
75
+ filename: "#{card.name.safe_key}#{file.extension}",
64
76
  x_sendfile: true,
65
77
  disposition: (params[:format] == "file" ? "attachment" : "inline") }]
66
78
  end
67
79
 
68
80
  def set_response_headers
69
81
  return unless params[:explicit_file] && (response = controller&.response)
82
+
70
83
  response.headers["Expires"] = 1.year.from_now.httpdate
71
84
  # currently using default "private", because proxy servers could block
72
85
  # needed permission checks
@@ -74,6 +87,10 @@ format :file do
74
87
  end
75
88
  end
76
89
 
90
+ format :json do
91
+ view(:content) { render_core }
92
+ end
93
+
77
94
  format :html do
78
95
  view :core do
79
96
  handle_source do |source|
data/set/type/image.rb CHANGED
@@ -23,8 +23,10 @@ format do
23
23
 
24
24
  view :source do
25
25
  return card.content if card.web?
26
+
26
27
  image = selected_version
27
28
  return "" unless image.valid?
29
+
28
30
  contextualize_path image.url
29
31
  end
30
32
 
@@ -37,10 +39,6 @@ format do
37
39
  end
38
40
  end
39
41
 
40
- def handle_source
41
- super
42
- end
43
-
44
42
  def closed_size
45
43
  :icon
46
44
  end
@@ -70,11 +68,16 @@ format do
70
68
  end
71
69
  end
72
70
 
71
+ format :json do
72
+ include File::JsonFormat
73
+ end
74
+
73
75
  format :email_html do
74
76
  view :inline, cache: :never do
75
77
  handle_source do |source|
76
78
  return source unless (mail = inherit :active_mail) &&
77
79
  ::File.exist?(path = selected_version.path)
80
+
78
81
  url = attach_image mail, path
79
82
  image_tag url
80
83
  end
@@ -4,6 +4,7 @@ format :html do
4
4
  # core HTML image view.
5
5
  view :core do
6
6
  return card.attachment.read if card.svg?
7
+
7
8
  with_valid_source do |source|
8
9
  image_tag source, alt: card.name
9
10
  end
@@ -34,6 +35,7 @@ format :html do
34
35
 
35
36
  def preview
36
37
  return if card.new_card? && !card.preliminary_upload?
38
+
37
39
  wrap_with :div, class: "attachment-preview",
38
40
  id: "#{card.attachment.filename}-preview" do
39
41
  _render_core size: :medium
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.11.4
4
+ version: 0.11.5
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: 2021-05-05 00:00:00.000000000 Z
13
+ date: 2021-05-10 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.101.4
21
+ version: 1.101.5
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.101.4
28
+ version: 1.101.5
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: carrierwave
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -60,28 +60,28 @@ dependencies:
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.11.4
63
+ version: 0.11.5
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: 0.11.4
70
+ version: 0.11.5
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: card-mod-permissions
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.11.4
77
+ version: 0.11.5
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.11.4
84
+ version: 0.11.5
85
85
  description: ''
86
86
  email:
87
87
  - info@decko.org