mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-06 21:24:23 +08:00
Fix text with tiny_mce objects [SCI-11069] (#8087)
This commit is contained in:
parent
6b59ab6067
commit
fc620e1a18
5 changed files with 12 additions and 23 deletions
|
@ -109,7 +109,7 @@ module TinyMceImages
|
|||
end
|
||||
|
||||
def copy_unknown_tiny_mce_images(user)
|
||||
asset_team_id = Team.search_by_object(self).id
|
||||
asset_team_id = team.id
|
||||
return unless asset_team_id
|
||||
|
||||
object_field = Extends::RICH_TEXT_FIELD_MAPPINGS[self.class.name]
|
||||
|
@ -193,7 +193,9 @@ module TinyMceImages
|
|||
return unless sanitized_text
|
||||
|
||||
ActiveRecord::Base.transaction do
|
||||
sanitized_text.scan(/src="(data:image\/[^;]+;base64[^"]+)"/i).flatten.each do |base64_src|
|
||||
sanitized_text.scan(%r{src=['"](data:image/[^;]+;base64[^"]+)['"]}i).flatten.each do |base64_src|
|
||||
next unless team.id
|
||||
|
||||
base64_data_parts = base64_src.split('base64,')
|
||||
base64_file_extension =
|
||||
MIME::Types[
|
||||
|
@ -202,7 +204,7 @@ module TinyMceImages
|
|||
base64_data = base64_data_parts.last
|
||||
|
||||
tiny_image = TinyMceAsset.create!(
|
||||
team: Team.search_by_object(self),
|
||||
team:,
|
||||
object_id: id,
|
||||
object_type: self.class.name,
|
||||
saved: true
|
||||
|
@ -217,10 +219,8 @@ module TinyMceImages
|
|||
|
||||
encoded_id = Base62.encode(tiny_image.id)
|
||||
|
||||
sanitized_text.gsub!(
|
||||
"#{base64_src}\"",
|
||||
"\" data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\""
|
||||
)
|
||||
sanitized_text.gsub!("#{base64_src}\"", "\" data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\"")
|
||||
sanitized_text.gsub!("#{base64_src}'", "' data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\"")
|
||||
end
|
||||
|
||||
assign_attributes(object_field => sanitized_text)
|
||||
|
|
|
@ -12,6 +12,8 @@ class ResultText < ApplicationRecord
|
|||
belongs_to :result, inverse_of: :result_texts, touch: true
|
||||
has_one :result_orderable_element, as: :orderable, dependent: :destroy
|
||||
|
||||
delegate :team, to: :result
|
||||
|
||||
def duplicate(result, position = nil)
|
||||
ActiveRecord::Base.transaction do
|
||||
new_result_text = result.result_texts.create!(
|
||||
|
|
|
@ -16,6 +16,8 @@ class StepText < ApplicationRecord
|
|||
belongs_to :step, inverse_of: :step_texts, touch: true
|
||||
has_one :step_orderable_element, as: :orderable, dependent: :destroy
|
||||
|
||||
delegate :team, to: :step
|
||||
|
||||
scope :asc, -> { order('step_texts.created_at ASC') }
|
||||
|
||||
def duplicate(step, position = nil)
|
||||
|
|
|
@ -193,21 +193,6 @@ class Team < ApplicationRecord
|
|||
query
|
||||
end
|
||||
|
||||
def self.search_by_object(obj)
|
||||
find(
|
||||
case obj.class.name
|
||||
when 'Protocol'
|
||||
obj.team_id
|
||||
when 'StepText'
|
||||
obj.step.protocol.team_id
|
||||
when 'MyModule', 'Step'
|
||||
obj.protocol.team_id
|
||||
when 'ResultText'
|
||||
obj.result.my_module.protocol.team_id
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
def number_of_task_shared
|
||||
shareable_links.count
|
||||
end
|
||||
|
|
|
@ -169,7 +169,7 @@ class TinyMceAsset < ApplicationRecord
|
|||
end
|
||||
|
||||
def clone_tinymce_asset(obj)
|
||||
team_id = Team.search_by_object(obj)&.id
|
||||
team_id = obj.team&.id
|
||||
|
||||
return false unless team_id
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue