mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-09 16:01:30 +08:00
Refactor the solution [SCI-8227]
Co-Author okriuchykhin <oleksii@scinote.net>
This commit is contained in:
parent
aa75782766
commit
a1c1b6e5a7
3 changed files with 19 additions and 14 deletions
|
|
@ -3,13 +3,14 @@
|
|||
module MyModules
|
||||
class CopyContentJob < ApplicationJob
|
||||
def perform(user, source_my_module_id, target_my_module_id)
|
||||
target_my_module = MyModule.find(target_my_module_id)
|
||||
MyModule.transaction do
|
||||
target_my_module = MyModule.find(target_my_module_id)
|
||||
MyModule.find(source_my_module_id).copy_content(user, target_my_module)
|
||||
create_copy_my_module_activity(user, source_my_module_id, target_my_module_id)
|
||||
target_my_module.update!(provisioning_status: :done)
|
||||
end
|
||||
rescue StandardError => _e
|
||||
rescue StandardError => e
|
||||
Rails.logger.error e.message
|
||||
target_my_module.update(provisioning_status: :failed)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -402,7 +402,7 @@ class MyModule < ApplicationRecord
|
|||
|
||||
# Update the cloned protocol if neccesary
|
||||
clone_tinymce_assets(target_my_module, target_my_module.experiment.project.team)
|
||||
target_my_module.protocols << protocol.deep_clone_my_module(self, current_user)
|
||||
protocol.deep_clone_my_module(target_my_module, current_user)
|
||||
target_my_module.reload
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ class Protocol < ApplicationRecord
|
|||
include PermissionCheckableModel
|
||||
include TinyMceImages
|
||||
|
||||
after_create :set_linked_at, if: -> { linked? && linked_at.blank? }
|
||||
after_create :update_automatic_user_assignments, if: -> { visible? && in_repository? && parent.blank? }
|
||||
before_update :change_visibility, if: :default_public_user_role_id_changed?
|
||||
after_update :update_automatic_user_assignments,
|
||||
|
|
@ -349,7 +348,7 @@ class Protocol < ApplicationRecord
|
|||
end
|
||||
|
||||
def newer_than_parent?
|
||||
linked? && updated_at > parent.published_on
|
||||
linked? && updated_at > linked_at
|
||||
end
|
||||
|
||||
def parent_newer?
|
||||
|
|
@ -490,11 +489,11 @@ class Protocol < ApplicationRecord
|
|||
# Lastly, update the metadata
|
||||
reload
|
||||
self.record_timestamps = false
|
||||
self.updated_at = source.published_on
|
||||
self.added_by = current_user
|
||||
self.last_modified_by = current_user
|
||||
self.parent = source
|
||||
self.linked_at = Time.zone.now
|
||||
self.updated_at = Time.zone.now
|
||||
self.linked_at = updated_at
|
||||
save!
|
||||
end
|
||||
|
||||
|
|
@ -511,12 +510,12 @@ class Protocol < ApplicationRecord
|
|||
reload
|
||||
self.name = source.name
|
||||
self.record_timestamps = false
|
||||
self.updated_at = source.published_on
|
||||
self.parent = source
|
||||
self.added_by = current_user
|
||||
self.last_modified_by = current_user
|
||||
self.linked_at = Time.zone.now
|
||||
self.protocol_type = Protocol.protocol_types[:linked]
|
||||
self.updated_at = Time.zone.now
|
||||
self.linked_at = updated_at
|
||||
save!
|
||||
end
|
||||
|
||||
|
|
@ -577,12 +576,17 @@ class Protocol < ApplicationRecord
|
|||
clone.parent = parent
|
||||
end
|
||||
|
||||
deep_clone(clone, current_user)
|
||||
end
|
||||
ActiveRecord::Base.no_touching do
|
||||
clone = deep_clone(clone, current_user)
|
||||
end
|
||||
|
||||
def set_linked_at
|
||||
self.linked_at = created_at
|
||||
self.save!
|
||||
if linked?
|
||||
clone.updated_at = Time.zone.now
|
||||
clone.linked_at = clone.updated_at
|
||||
clone.save
|
||||
end
|
||||
|
||||
clone
|
||||
end
|
||||
|
||||
def deep_clone_repository(current_user)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue