2021-06-01 12:20:20 +00:00
|
|
|
# Copyright (C) 2012-2021 Zammad Foundation, http://zammad-foundation.org/
|
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
class KnowledgeBase::Translation < ApplicationModel
|
|
|
|
include HasAgentAllowedParams
|
|
|
|
include HasSearchIndexBackend
|
|
|
|
include KnowledgeBase::Search
|
|
|
|
|
|
|
|
AGENT_ALLOWED_ATTRIBUTES = %i[title footer_note kb_locale_id].freeze
|
|
|
|
|
|
|
|
belongs_to :knowledge_base, inverse_of: :translations, touch: true
|
|
|
|
belongs_to :kb_locale, inverse_of: :knowledge_base_translations, class_name: 'KnowledgeBase::Locale'
|
|
|
|
|
|
|
|
validates :title, presence: true, length: { maximum: 250 }
|
|
|
|
validates :kb_locale_id, uniqueness: { scope: :knowledge_base_id }
|
|
|
|
|
|
|
|
def assets(data)
|
|
|
|
return data if assets_added_to?(data)
|
|
|
|
|
|
|
|
data = super(data)
|
|
|
|
knowledge_base.assets(data)
|
|
|
|
end
|
|
|
|
|
2021-01-27 09:58:35 +00:00
|
|
|
def search_index_attribute_lookup(include_references: true)
|
2019-06-04 03:40:48 +00:00
|
|
|
attrs = super
|
|
|
|
|
|
|
|
attrs['title'] = ActionController::Base.helpers.strip_tags attrs['title']
|
|
|
|
|
|
|
|
attrs
|
|
|
|
end
|
|
|
|
|
|
|
|
class << self
|
2020-08-05 13:48:41 +00:00
|
|
|
def search_fallback(query, scope = nil, options: {})
|
2019-06-04 03:40:48 +00:00
|
|
|
fields = %w[title]
|
|
|
|
|
|
|
|
output = where_or_cis(fields, query)
|
|
|
|
|
|
|
|
if scope.present?
|
|
|
|
output = output.where(id: 0) # KB cannot be in any scope
|
|
|
|
end
|
|
|
|
|
|
|
|
output
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|