2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
class KnowledgeBase::Answer::Translation::Content < ApplicationModel
|
|
|
|
include HasAgentAllowedParams
|
|
|
|
include HasRichText
|
|
|
|
|
|
|
|
AGENT_ALLOWED_ATTRIBUTES = %i[body].freeze
|
|
|
|
|
|
|
|
has_one :translation, class_name: 'KnowledgeBase::Answer::Translation', inverse_of: :content, dependent: :nullify
|
|
|
|
|
|
|
|
has_rich_text :body
|
|
|
|
|
|
|
|
attachments_cleanup!
|
|
|
|
|
|
|
|
def visible?
|
|
|
|
translation.answer.visible?
|
|
|
|
end
|
|
|
|
|
2019-11-12 14:08:00 +00:00
|
|
|
def visible_internally?
|
|
|
|
translation.answer.visible_internally?
|
|
|
|
end
|
|
|
|
|
2019-06-04 03:40:48 +00:00
|
|
|
delegate :created_by_id, to: :translation
|
|
|
|
|
|
|
|
def attributes_with_association_ids
|
|
|
|
attrs = super
|
|
|
|
add_attachments_to_attributes(attrs)
|
|
|
|
end
|
|
|
|
|
2021-08-18 12:38:34 +00:00
|
|
|
def attributes_with_association_names(empty_keys: false)
|
2019-06-04 03:40:48 +00:00
|
|
|
attrs = super
|
|
|
|
add_attachments_to_attributes(attrs)
|
|
|
|
end
|
|
|
|
|
|
|
|
def add_attachments_to_attributes(attributes)
|
|
|
|
attributes['attachments'] = attachments
|
|
|
|
.reject { |file| HasRichText.attachment_inline?(file) }
|
|
|
|
.map(&:attributes_for_display)
|
|
|
|
|
|
|
|
attributes
|
|
|
|
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['body'] = ActionController::Base.helpers.strip_tags attrs['body']
|
|
|
|
attrs
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def touch_translation
|
|
|
|
translation&.touch # rubocop:disable Rails/SkipsModelValidations
|
|
|
|
end
|
|
|
|
|
2020-09-30 09:07:01 +00:00
|
|
|
before_save :sanitize_body
|
2019-06-04 03:40:48 +00:00
|
|
|
after_save :touch_translation
|
|
|
|
after_touch :touch_translation
|
|
|
|
|
|
|
|
def sanitize_body
|
|
|
|
self.body = HtmlSanitizer.dynamic_image_size(body)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|