translation.rb 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # Copyright (C) 2012-2016 Zammad Foundation, http://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: { 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
  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)
  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