mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-11-10 16:31:22 +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
|
module MyModules
|
||||||
class CopyContentJob < ApplicationJob
|
class CopyContentJob < ApplicationJob
|
||||||
def perform(user, source_my_module_id, target_my_module_id)
|
def perform(user, source_my_module_id, target_my_module_id)
|
||||||
|
target_my_module = MyModule.find(target_my_module_id)
|
||||||
MyModule.transaction do
|
MyModule.transaction do
|
||||||
target_my_module = MyModule.find(target_my_module_id)
|
|
||||||
MyModule.find(source_my_module_id).copy_content(user, target_my_module)
|
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)
|
create_copy_my_module_activity(user, source_my_module_id, target_my_module_id)
|
||||||
target_my_module.update!(provisioning_status: :done)
|
target_my_module.update!(provisioning_status: :done)
|
||||||
end
|
end
|
||||||
rescue StandardError => _e
|
rescue StandardError => e
|
||||||
|
Rails.logger.error e.message
|
||||||
target_my_module.update(provisioning_status: :failed)
|
target_my_module.update(provisioning_status: :failed)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -402,7 +402,7 @@ class MyModule < ApplicationRecord
|
||||||
|
|
||||||
# Update the cloned protocol if neccesary
|
# Update the cloned protocol if neccesary
|
||||||
clone_tinymce_assets(target_my_module, target_my_module.experiment.project.team)
|
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
|
target_my_module.reload
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -16,7 +16,6 @@ class Protocol < ApplicationRecord
|
||||||
include PermissionCheckableModel
|
include PermissionCheckableModel
|
||||||
include TinyMceImages
|
include TinyMceImages
|
||||||
|
|
||||||
after_create :set_linked_at, if: -> { linked? && linked_at.blank? }
|
|
||||||
after_create :update_automatic_user_assignments, if: -> { visible? && in_repository? && parent.blank? }
|
after_create :update_automatic_user_assignments, if: -> { visible? && in_repository? && parent.blank? }
|
||||||
before_update :change_visibility, if: :default_public_user_role_id_changed?
|
before_update :change_visibility, if: :default_public_user_role_id_changed?
|
||||||
after_update :update_automatic_user_assignments,
|
after_update :update_automatic_user_assignments,
|
||||||
|
|
@ -349,7 +348,7 @@ class Protocol < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def newer_than_parent?
|
def newer_than_parent?
|
||||||
linked? && updated_at > parent.published_on
|
linked? && updated_at > linked_at
|
||||||
end
|
end
|
||||||
|
|
||||||
def parent_newer?
|
def parent_newer?
|
||||||
|
|
@ -490,11 +489,11 @@ class Protocol < ApplicationRecord
|
||||||
# Lastly, update the metadata
|
# Lastly, update the metadata
|
||||||
reload
|
reload
|
||||||
self.record_timestamps = false
|
self.record_timestamps = false
|
||||||
self.updated_at = source.published_on
|
|
||||||
self.added_by = current_user
|
self.added_by = current_user
|
||||||
self.last_modified_by = current_user
|
self.last_modified_by = current_user
|
||||||
self.parent = source
|
self.parent = source
|
||||||
self.linked_at = Time.zone.now
|
self.updated_at = Time.zone.now
|
||||||
|
self.linked_at = updated_at
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -511,12 +510,12 @@ class Protocol < ApplicationRecord
|
||||||
reload
|
reload
|
||||||
self.name = source.name
|
self.name = source.name
|
||||||
self.record_timestamps = false
|
self.record_timestamps = false
|
||||||
self.updated_at = source.published_on
|
|
||||||
self.parent = source
|
self.parent = source
|
||||||
self.added_by = current_user
|
self.added_by = current_user
|
||||||
self.last_modified_by = current_user
|
self.last_modified_by = current_user
|
||||||
self.linked_at = Time.zone.now
|
|
||||||
self.protocol_type = Protocol.protocol_types[:linked]
|
self.protocol_type = Protocol.protocol_types[:linked]
|
||||||
|
self.updated_at = Time.zone.now
|
||||||
|
self.linked_at = updated_at
|
||||||
save!
|
save!
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -577,12 +576,17 @@ class Protocol < ApplicationRecord
|
||||||
clone.parent = parent
|
clone.parent = parent
|
||||||
end
|
end
|
||||||
|
|
||||||
deep_clone(clone, current_user)
|
ActiveRecord::Base.no_touching do
|
||||||
end
|
clone = deep_clone(clone, current_user)
|
||||||
|
end
|
||||||
|
|
||||||
def set_linked_at
|
if linked?
|
||||||
self.linked_at = created_at
|
clone.updated_at = Time.zone.now
|
||||||
self.save!
|
clone.linked_at = clone.updated_at
|
||||||
|
clone.save
|
||||||
|
end
|
||||||
|
|
||||||
|
clone
|
||||||
end
|
end
|
||||||
|
|
||||||
def deep_clone_repository(current_user)
|
def deep_clone_repository(current_user)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue