fix(sentry/3394049118): apparently there is an attached_file without content_type nor file_size validation...
This commit is contained in:
parent
0ef7a8b9b0
commit
ddd67f1df2
1 changed files with 29 additions and 12 deletions
|
@ -11,13 +11,6 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
|
|
||||||
attr_reader :template, :form
|
attr_reader :template, :form
|
||||||
|
|
||||||
def allowed_extensions
|
|
||||||
content_type_validator.options[:in]
|
|
||||||
.flat_map { |content_type| MIME::Types[content_type].map(&:extensions) }
|
|
||||||
.reject(&:blank?)
|
|
||||||
.flatten
|
|
||||||
end
|
|
||||||
|
|
||||||
def max_file_size
|
def max_file_size
|
||||||
file_size_validator.options[:less_than]
|
file_size_validator.options[:less_than]
|
||||||
end
|
end
|
||||||
|
@ -51,17 +44,16 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
end
|
end
|
||||||
|
|
||||||
def file_field_options
|
def file_field_options
|
||||||
|
track_issue_with_missing_validators if missing_validators?
|
||||||
{
|
{
|
||||||
class: "attachment-input #{attachment_input_class} #{'hidden' if persisted?}",
|
class: "attachment-input #{attachment_input_class} #{'hidden' if persisted?}",
|
||||||
accept: content_type_validator.options[:in].join(', '),
|
|
||||||
direct_upload: @direct_upload,
|
direct_upload: @direct_upload,
|
||||||
id: input_id(@id),
|
id: input_id(@id),
|
||||||
aria: { describedby: champ&.describedby_id },
|
aria: { describedby: champ&.describedby_id },
|
||||||
data: {
|
data: {
|
||||||
auto_attach_url: helpers.auto_attach_url(form.object),
|
auto_attach_url: helpers.auto_attach_url(form.object)
|
||||||
max_file_size: max_file_size
|
}.merge(has_file_size_validator? ? { max_file_size: max_file_size } : {})
|
||||||
}
|
}.merge(has_content_type_validator? ? { accept: content_type_validator.options[:in].join(', ') } : {})
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def input_id(given_id)
|
def input_id(given_id)
|
||||||
|
@ -107,4 +99,29 @@ class Attachment::EditComponent < ApplicationComponent
|
||||||
._validators[file_field_name.to_sym]
|
._validators[file_field_name.to_sym]
|
||||||
.find { |validator| validator.class == ActiveStorageValidations::ContentTypeValidator }
|
.find { |validator| validator.class == ActiveStorageValidations::ContentTypeValidator }
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def has_content_type_validator?
|
||||||
|
!content_type_validator.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def has_file_size_validator?
|
||||||
|
!file_size_validator.nil?
|
||||||
|
end
|
||||||
|
|
||||||
|
def missing_validators?
|
||||||
|
return true if !has_file_size_validator?
|
||||||
|
return true if !has_content_type_validator?
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
def track_issue_with_missing_validators
|
||||||
|
Sentry.capture_message(
|
||||||
|
"Strange case of missing validator",
|
||||||
|
extra: {
|
||||||
|
champ: champ,
|
||||||
|
file_field_name: file_field_name,
|
||||||
|
attachment_id: attachment_id
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue