validator.rb 981 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class Service::Ticket::Update::Validator
  3. include Mixin::RequiredSubPaths
  4. def self.exceptions
  5. BaseError.descendants
  6. end
  7. attr_reader :user, :ticket, :ticket_data, :article_data, :skip_validators
  8. def initialize(user:, ticket:, ticket_data:, article_data:, skip_validators:)
  9. @user = user
  10. @ticket = ticket
  11. @ticket_data = ticket_data
  12. @article_data = article_data
  13. @skip_validators = skip_validators
  14. end
  15. def validate!
  16. validators.each do |validator|
  17. validator.new(
  18. user: user,
  19. ticket: ticket,
  20. ticket_data: ticket_data,
  21. article_data: article_data,
  22. ).valid!
  23. end
  24. end
  25. private
  26. def validators
  27. Service::Ticket::Update::Validator::Base.descendants.reject do |klass|
  28. skip_validators&.any? { |validator| validator.name.starts_with?(klass.name) }
  29. end
  30. end
  31. end