mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-02-02 13:12:13 +08:00
Merge pull request #2855 from okriuchykhin/ok_SCI_5030
Fix task archiving and moving [SCI-5030]
This commit is contained in:
commit
9fda2dd97e
3 changed files with 12 additions and 19 deletions
|
@ -15,7 +15,7 @@ module ArchivableModel
|
|||
# Helper for archiving project. Timestamp of archiving is handler by
|
||||
# before_save callback.
|
||||
# Sets the archived_by value to the current user.
|
||||
def archive (current_user)
|
||||
def archive(current_user)
|
||||
self.archived = true
|
||||
self.archived_by = current_user
|
||||
save
|
||||
|
@ -29,7 +29,7 @@ module ArchivableModel
|
|||
|
||||
# Helper for restoring project from archive.
|
||||
# Sets the restored_by value to the current user.
|
||||
def restore (current_user)
|
||||
def restore(current_user)
|
||||
self.archived = false
|
||||
self.restored_by = current_user
|
||||
save
|
||||
|
|
|
@ -256,12 +256,6 @@ class Experiment < ApplicationRecord
|
|||
|
||||
private
|
||||
|
||||
# Archive all modules. Receives an array of module integer IDs.
|
||||
def archive_modules(module_ids)
|
||||
my_modules.where(id: module_ids).each(&:archive!)
|
||||
my_modules.reload
|
||||
end
|
||||
|
||||
# Archive all modules. Receives an array of module integer IDs
|
||||
# and current user.
|
||||
def archive_modules(module_ids, current_user)
|
||||
|
|
|
@ -26,9 +26,7 @@ class MyModule < ApplicationRecord
|
|||
|
||||
validate :check_status, if: :my_module_status_id_changed?
|
||||
validate :check_status_conditions, if: :my_module_status_id_changed?
|
||||
validate :check_status_implications, unless: proc { |mm|
|
||||
(mm.changed_attributes.keys - %w(my_module_status_id x y my_module_group_id workflow_order status_changing)).blank?
|
||||
}
|
||||
validate :check_status_implications
|
||||
|
||||
belongs_to :created_by,
|
||||
foreign_key: 'created_by_id',
|
||||
|
@ -164,18 +162,19 @@ class MyModule < ApplicationRecord
|
|||
# Remove association with module group.
|
||||
self.my_module_group = nil
|
||||
|
||||
was_archived = false
|
||||
|
||||
MyModule.transaction do
|
||||
archived = super
|
||||
was_archived = super
|
||||
# Unassociate all samples from module.
|
||||
archived = SampleMyModule.where(my_module: self).destroy_all if archived
|
||||
was_archived = SampleMyModule.where(my_module: self).destroy_all if was_archived
|
||||
# Remove all connection between modules.
|
||||
archived = Connection.where(input_id: id).delete_all if archived
|
||||
archived = Connection.where(output_id: id).delete_all if archived
|
||||
unless archived
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
was_archived = Connection.where(input_id: id).destroy_all if was_archived
|
||||
was_archived = Connection.where(output_id: id).destroy_all if was_archived
|
||||
|
||||
raise ActiveRecord::Rollback unless was_archived
|
||||
end
|
||||
archived
|
||||
was_archived
|
||||
end
|
||||
|
||||
# Similar as super restore, but also calculate new module position
|
||||
|
|
Loading…
Reference in a new issue