attachment.rb 668 B

123456789101112131415161718192021222324252627
  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. return if config['value'].nil? || !config['value'].is_a?(Array)
  8. result['attachments'][:value] = Array(config['value']).map do |elem|
  9. resolve_attachment(elem)
  10. end
  11. end
  12. private
  13. def resolve_attachment(attachment)
  14. {
  15. id: attachment.id,
  16. name: attachment.filename,
  17. size: attachment.size,
  18. type: attachment.preferences['Content-Type'],
  19. }
  20. end
  21. end