-
Notifications
You must be signed in to change notification settings - Fork 729
/
content.rb
62 lines (45 loc) · 1.44 KB
/
content.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
class KnowledgeBase::Answer::Translation::Content < ApplicationModel
include HasAgentAllowedParams
include HasRichText
include HasKnowledgeBaseAttachmentPermissions
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
def visible_internally?
translation.answer.visible_internally?
end
delegate :created_by_id, to: :translation
def attributes_with_association_ids
attrs = super
add_attachments_to_attributes(attrs)
end
def attributes_with_association_names
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
def search_index_attribute_lookup
attrs = super
attrs['body'] = ActionController::Base.helpers.strip_tags attrs['body']
attrs
end
private
def touch_translation
translation&.touch # rubocop:disable Rails/SkipsModelValidations
end
after_save :touch_translation
after_touch :touch_translation
def sanitize_body
self.body = HtmlSanitizer.dynamic_image_size(body)
end
before_save :sanitize_body
end