translation.rb 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # Copyright (C) 2012-2023 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::Translation < ApplicationModel
  3. include HasAgentAllowedParams
  4. include HasSearchIndexBackend
  5. include KnowledgeBase::Search
  6. AGENT_ALLOWED_ATTRIBUTES = %i[title footer_note kb_locale_id].freeze
  7. belongs_to :knowledge_base, inverse_of: :translations, touch: true
  8. belongs_to :kb_locale, inverse_of: :knowledge_base_translations, class_name: 'KnowledgeBase::Locale'
  9. validates :title, presence: true, length: { maximum: 250 }
  10. validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :knowledge_base_id }
  11. def assets(data)
  12. return data if assets_added_to?(data)
  13. data = super(data)
  14. knowledge_base.assets(data)
  15. end
  16. def search_index_attribute_lookup(include_references: true)
  17. attrs = super
  18. attrs['title'] = ActionController::Base.helpers.strip_tags attrs['title']
  19. attrs
  20. end
  21. class << self
  22. def search_fallback(query, scope = nil, options: {})
  23. fields = %w[title]
  24. output = where_or_cis(fields, query)
  25. if scope.present?
  26. output = output.where(id: 0) # KB cannot be in any scope
  27. end
  28. output
  29. end
  30. end
  31. end