mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 21:55:20 +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
|
end
|
||||||
|
|
||||||
def copy_unknown_tiny_mce_images(user)
|
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
|
return unless asset_team_id
|
||||||
|
|
||||||
object_field = Extends::RICH_TEXT_FIELD_MAPPINGS[self.class.name]
|
object_field = Extends::RICH_TEXT_FIELD_MAPPINGS[self.class.name]
|
||||||
|
@ -193,7 +193,9 @@ module TinyMceImages
|
||||||
return unless sanitized_text
|
return unless sanitized_text
|
||||||
|
|
||||||
ActiveRecord::Base.transaction do
|
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_data_parts = base64_src.split('base64,')
|
||||||
base64_file_extension =
|
base64_file_extension =
|
||||||
MIME::Types[
|
MIME::Types[
|
||||||
|
@ -202,7 +204,7 @@ module TinyMceImages
|
||||||
base64_data = base64_data_parts.last
|
base64_data = base64_data_parts.last
|
||||||
|
|
||||||
tiny_image = TinyMceAsset.create!(
|
tiny_image = TinyMceAsset.create!(
|
||||||
team: Team.search_by_object(self),
|
team:,
|
||||||
object_id: id,
|
object_id: id,
|
||||||
object_type: self.class.name,
|
object_type: self.class.name,
|
||||||
saved: true
|
saved: true
|
||||||
|
@ -217,10 +219,8 @@ module TinyMceImages
|
||||||
|
|
||||||
encoded_id = Base62.encode(tiny_image.id)
|
encoded_id = Base62.encode(tiny_image.id)
|
||||||
|
|
||||||
sanitized_text.gsub!(
|
sanitized_text.gsub!("#{base64_src}\"", "\" data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\"")
|
||||||
"#{base64_src}\"",
|
sanitized_text.gsub!("#{base64_src}'", "' data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\"")
|
||||||
"\" data-mce-token=\"#{encoded_id}\" alt=\"description-#{encoded_id}\""
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
assign_attributes(object_field => sanitized_text)
|
assign_attributes(object_field => sanitized_text)
|
||||||
|
|
|
@ -12,6 +12,8 @@ class ResultText < ApplicationRecord
|
||||||
belongs_to :result, inverse_of: :result_texts, touch: true
|
belongs_to :result, inverse_of: :result_texts, touch: true
|
||||||
has_one :result_orderable_element, as: :orderable, dependent: :destroy
|
has_one :result_orderable_element, as: :orderable, dependent: :destroy
|
||||||
|
|
||||||
|
delegate :team, to: :result
|
||||||
|
|
||||||
def duplicate(result, position = nil)
|
def duplicate(result, position = nil)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
new_result_text = result.result_texts.create!(
|
new_result_text = result.result_texts.create!(
|
||||||
|
|
|
@ -16,6 +16,8 @@ class StepText < ApplicationRecord
|
||||||
belongs_to :step, inverse_of: :step_texts, touch: true
|
belongs_to :step, inverse_of: :step_texts, touch: true
|
||||||
has_one :step_orderable_element, as: :orderable, dependent: :destroy
|
has_one :step_orderable_element, as: :orderable, dependent: :destroy
|
||||||
|
|
||||||
|
delegate :team, to: :step
|
||||||
|
|
||||||
scope :asc, -> { order('step_texts.created_at ASC') }
|
scope :asc, -> { order('step_texts.created_at ASC') }
|
||||||
|
|
||||||
def duplicate(step, position = nil)
|
def duplicate(step, position = nil)
|
||||||
|
|
|
@ -193,21 +193,6 @@ class Team < ApplicationRecord
|
||||||
query
|
query
|
||||||
end
|
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
|
def number_of_task_shared
|
||||||
shareable_links.count
|
shareable_links.count
|
||||||
end
|
end
|
||||||
|
|
|
@ -169,7 +169,7 @@ class TinyMceAsset < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def clone_tinymce_asset(obj)
|
def clone_tinymce_asset(obj)
|
||||||
team_id = Team.search_by_object(obj)&.id
|
team_id = obj.team&.id
|
||||||
|
|
||||||
return false unless team_id
|
return false unless team_id
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue