mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-10 15:14:33 +08:00
Merge pull request #7914 from aignatov-bio/ai-sci-11136-change-creator-after-duplicate-locations
Change create by on location duplicate [SCI-11136]
This commit is contained in:
commit
ac57267140
2 changed files with 7 additions and 5 deletions
|
@ -86,7 +86,7 @@ class StorageLocationsController < ApplicationController
|
||||||
|
|
||||||
def duplicate
|
def duplicate
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
new_storage_location = @storage_location.duplicate!
|
new_storage_location = @storage_location.duplicate!(current_user)
|
||||||
if new_storage_location
|
if new_storage_location
|
||||||
@storage_location = new_storage_location
|
@storage_location = new_storage_location
|
||||||
log_activity('storage_location_created')
|
log_activity('storage_location_created')
|
||||||
|
|
|
@ -60,13 +60,14 @@ class StorageLocation < ApplicationRecord
|
||||||
storage_location_repository_rows.count.zero?
|
storage_location_repository_rows.count.zero?
|
||||||
end
|
end
|
||||||
|
|
||||||
def duplicate!
|
def duplicate!(user)
|
||||||
ActiveRecord::Base.transaction do
|
ActiveRecord::Base.transaction do
|
||||||
new_storage_location = dup
|
new_storage_location = dup
|
||||||
new_storage_location.name = next_clone_name
|
new_storage_location.name = next_clone_name
|
||||||
|
new_storage_location.created_by = user
|
||||||
new_storage_location.save!
|
new_storage_location.save!
|
||||||
copy_image(self, new_storage_location)
|
copy_image(self, new_storage_location)
|
||||||
recursive_duplicate(id, new_storage_location.id)
|
recursive_duplicate(id, new_storage_location.id, user)
|
||||||
new_storage_location
|
new_storage_location
|
||||||
rescue ActiveRecord::RecordInvalid
|
rescue ActiveRecord::RecordInvalid
|
||||||
false
|
false
|
||||||
|
@ -142,13 +143,14 @@ class StorageLocation < ApplicationRecord
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def recursive_duplicate(old_parent_id = nil, new_parent_id = nil)
|
def recursive_duplicate(old_parent_id = nil, new_parent_id = nil, user = nil)
|
||||||
StorageLocation.where(parent_id: old_parent_id).find_each do |child|
|
StorageLocation.where(parent_id: old_parent_id).find_each do |child|
|
||||||
new_child = child.dup
|
new_child = child.dup
|
||||||
new_child.parent_id = new_parent_id
|
new_child.parent_id = new_parent_id
|
||||||
|
new_child.created_by = user
|
||||||
new_child.save!
|
new_child.save!
|
||||||
copy_image(child, new_child)
|
copy_image(child, new_child)
|
||||||
recursive_duplicate(child.id, new_child.id)
|
recursive_duplicate(child.id, new_child.id, user)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue