translation.rb 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class KnowledgeBase::Translation < ApplicationModel
  3. include HasAgentAllowedParams
  4. include HasSearchIndexBackend
  5. AGENT_ALLOWED_ATTRIBUTES = %i[title footer_note kb_locale_id].freeze
  6. belongs_to :knowledge_base, inverse_of: :translations, touch: true
  7. belongs_to :kb_locale, inverse_of: :knowledge_base_translations, class_name: 'KnowledgeBase::Locale'
  8. validates :title, presence: true, length: { maximum: 250 }
  9. validates :kb_locale_id, uniqueness: { case_sensitive: true, scope: :knowledge_base_id }
  10. def assets(data)
  11. return data if assets_added_to?(data)
  12. data = super
  13. knowledge_base.assets(data)
  14. end
  15. def search_index_attribute_lookup(include_references: true)
  16. attrs = super
  17. attrs['title'] = ActionController::Base.helpers.strip_tags attrs['title']
  18. attrs
  19. end
  20. scope :search_sql_text_fallback, lambda { |query|
  21. where_or_cis(%w[title], query)
  22. }
  23. scope :apply_kb_scope, lambda { |scope|
  24. none if scope.present?
  25. }
  26. end