123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 |
- class Ticket::SharedDraftStart < ApplicationModel
- include HasRichText
- include HasDefaultModelUserRelations
- include CanCloneAttachments
- include ChecksClientNotification
- belongs_to :group
- validates :name, presence: true
- before_validation :clear_group_id
- after_commit :trigger_subscriptions
- store :content
-
-
-
- def filter_attributes(attributes)
- super.except! 'content'
- end
-
- def content_type
- 'text/html'
- end
-
- has_rich_text :body
-
-
- def body
- content[:body]
- end
-
-
- def body=(input)
- content[: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_base64
- output = content.deep_dup
- output[:body] = body_with_base64
- output
- end
-
- def content_with_body_urls
- output = content.deep_dup
- output[:body] = body_with_urls
- output
- end
-
-
-
- def content_with_form_id_body_urls(form_id)
- cache = UploadCache.new(form_id)
- output = content.deep_dup
- output[:body] = HasRichText.insert_urls(output[:body], cache.attachments)
- output
- end
- private
- def clear_group_id
- content.delete :group_id
- end
- def trigger_subscriptions
- [group_id, group_id_previously_was]
- .compact
- .uniq
- .each do |elem|
- Gql::Subscriptions::Ticket::SharedDraft::Start::UpdateByGroup
- .trigger(nil, arguments: { group_id: Gql::ZammadSchema.id_from_internal_id('Group', elem) })
- end
- end
- end
|