123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- class Ticket::SharedDraftZoom < ApplicationModel
- include HasRichText
- include HasDefaultModelUserRelations
- include CanCloneAttachments
- include ChecksClientNotification
- include HasHistory
- belongs_to :ticket, touch: true
- store :new_article
- store :ticket_attributes
- history_attributes_ignored :new_article,
- :ticket_attributes
-
- def content_type
- 'text/html'
- end
-
- has_rich_text :body
-
-
- def body
- new_article[:body]
- end
-
-
- def body=(input)
- new_article[:body] = input
- end
-
- def body_with_base64
- scrubber = HtmlSanitizer::Scrubber::InsertInlineImages.new(attachments)
- sanitized = Loofah
- .fragment(body)
- .scrub!(scrubber)
- sanitized.to_s
- end
-
- def content_with_body_urls
-
- output = new_article.deep_dup
- output[:body] = body_with_urls
- output
- end
-
-
-
- def content_with_form_id_body_urls(form_id)
- cache = UploadCache.new(form_id)
- article = new_article.deep_dup
- article[:body] = HasRichText.insert_urls(article[:body], cache.attachments)
- {
- article: article,
- ticket: ticket_attributes,
- }
- end
- def history_log_attributes
- {
- related_o_id: self['ticket_id'],
- related_history_object: 'Ticket',
- }
- end
- def history_destroy
- history_log('removed', created_by_id)
- end
- def attributes_with_association_ids
- attrs = super
- attrs.delete 'body'
- attrs['new_article']['body'] = body_with_base64 if attrs.dig('new_article', 'body').present?
- attrs
- end
- end
|