mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-08 22:24:23 +08:00
Change create by on location duplicate [SCI-11136]
This commit is contained in:
parent
5ab1fbbab9
commit
714b7e85ea
2 changed files with 7 additions and 5 deletions
|
@ -86,7 +86,7 @@ class StorageLocationsController < ApplicationController
|
|||
|
||||
def duplicate
|
||||
ActiveRecord::Base.transaction do
|
||||
new_storage_location = @storage_location.duplicate!
|
||||
new_storage_location = @storage_location.duplicate!(current_user)
|
||||
if new_storage_location
|
||||
@storage_location = new_storage_location
|
||||
log_activity('storage_location_created')
|
||||
|
|
|
@ -59,13 +59,14 @@ class StorageLocation < ApplicationRecord
|
|||
storage_location_repository_rows.count.zero?
|
||||
end
|
||||
|
||||
def duplicate!
|
||||
def duplicate!(user)
|
||||
ActiveRecord::Base.transaction do
|
||||
new_storage_location = dup
|
||||
new_storage_location.name = next_clone_name
|
||||
new_storage_location.created_by = user
|
||||
new_storage_location.save!
|
||||
copy_image(self, new_storage_location)
|
||||
recursive_duplicate(id, new_storage_location.id)
|
||||
recursive_duplicate(id, new_storage_location.id, user)
|
||||
new_storage_location
|
||||
rescue ActiveRecord::RecordInvalid
|
||||
false
|
||||
|
@ -141,13 +142,14 @@ class StorageLocation < ApplicationRecord
|
|||
|
||||
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|
|
||||
new_child = child.dup
|
||||
new_child.parent_id = new_parent_id
|
||||
new_child.created_by = user
|
||||
new_child.save!
|
||||
copy_image(child, new_child)
|
||||
recursive_duplicate(child.id, new_child.id)
|
||||
recursive_duplicate(child.id, new_child.id, user)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue