attachment.rb 742 B

12345678910111213141516171819202122232425262728
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FormUpdater::ApplyValue::Attachment < FormUpdater::ApplyValue::Base
  3. def can_handle_field?(field:, field_attribute:)
  4. field == 'attachments'
  5. end
  6. def map_value(field:, config:)
  7. Rails.logger.error "#{field} - config['value'] is #{config['value']}"
  8. return if config['value'].nil? || !config['value'].is_a?(Array)
  9. result['attachments'][:value] = Array(config['value']).map do |elem|
  10. resolve_attachment(elem)
  11. end
  12. end
  13. private
  14. def resolve_attachment(attachment)
  15. {
  16. id: attachment.id,
  17. name: attachment.filename,
  18. size: attachment.size,
  19. type: attachment.preferences['Content-Type'],
  20. }
  21. end
  22. end