ticket_article_validator.rb 687 B

12345678910111213141516171819202122232425262728293031323334
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Validations::TicketArticleValidator < ActiveModel::Validator
  3. include ::Mixin::HasBackends
  4. def validate(record)
  5. return if ApplicationHandleInfo.postmaster?
  6. backend(record)
  7. .new(record)
  8. .validate
  9. end
  10. private
  11. def backend(record)
  12. backend_by_type(record) || backend_default
  13. end
  14. def backend_by_type(record)
  15. type = Ticket::Article::Type.lookup(id: record.type_id)
  16. backends.find do |elem|
  17. next if !elem.const_defined?(:MATCHING_TYPES)
  18. elem::MATCHING_TYPES.include? type.name
  19. end
  20. end
  21. def backend_default
  22. self.class::Default
  23. end
  24. end