From d6ca444f4aa621b38edd93c9c94f95219b969d49 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 13 Sep 2024 15:17:32 +0200 Subject: [PATCH 1/3] Fix position validation [SCI-11050] --- app/models/storage_location_repository_row.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/storage_location_repository_row.rb b/app/models/storage_location_repository_row.rb index cf3d9f6ce..28f94d9da 100644 --- a/app/models/storage_location_repository_row.rb +++ b/app/models/storage_location_repository_row.rb @@ -28,9 +28,9 @@ class StorageLocationRepositoryRow < ApplicationRecord end def ensure_uniq_position - if StorageLocationRepositoryRow.where(storage_location: storage_location) - .where('metadata @> ?', { position: metadata['position'] }.to_json) - .where.not(id: id).exists? + if storage_location.storage_location_repository_rows + .where("metadata->>'position' = ?", metadata['position'].to_json.gsub(',', ', ')) + .where.not(id: id).exists? errors.add(:base, I18n.t('activerecord.errors.models.storage_location.not_uniq_position')) end end From ddc7cf9bf60cab91ecde054330e4cccfd3f10e64 Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 13 Sep 2024 15:34:46 +0200 Subject: [PATCH 2/3] Remove obsolete logic from location importer [SCI-11050] --- app/controllers/storage_locations_controller.rb | 2 +- app/services/storage_locations/import_service.rb | 11 ++++------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 92d8a33de..2c14340bb 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -133,7 +133,7 @@ class StorageLocationsController < ApplicationController def import_container result = StorageLocations::ImportService.new(@storage_location, params[:file], current_user).import_items if result[:status] == :ok - if (result[:assigned_count] + result[:unassigned_count] + result[:updated_count]).positive? + if (result[:assigned_count] + result[:unassigned_count]).positive? log_activity( :storage_location_imported, { diff --git a/app/services/storage_locations/import_service.rb b/app/services/storage_locations/import_service.rb index 78216c45b..01a6a29fe 100644 --- a/app/services/storage_locations/import_service.rb +++ b/app/services/storage_locations/import_service.rb @@ -8,7 +8,6 @@ module StorageLocations @storage_location = storage_location @assigned_count = 0 @unassigned_count = 0 - @updated_count = 0 @sheet = SpreadsheetParser.open_spreadsheet(file) @user = user end @@ -73,12 +72,10 @@ module StorageLocations metadata: { position: row[:position] } ) - @assigned_count += 1 if storage_location_repository_row.new_record? - - storage_location_repository_row.update!( - repository_row_id: row[:repository_row_id], - created_by: storage_location_repository_row.created_by || @user - ) + if storage_location_repository_row.new_record? + @assigned_count += 1 + storage_location_repository_row.update!(created_by: @user) + end end def unassign_repository_rows! From dd2499a70c56a4a2b2fc59af8e3ee7497e27b03c Mon Sep 17 00:00:00 2001 From: Martin Artnik Date: Fri, 13 Sep 2024 15:34:54 +0200 Subject: [PATCH 3/3] Fix position validation [SCI-11050] --- app/models/storage_location_repository_row.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/storage_location_repository_row.rb b/app/models/storage_location_repository_row.rb index 28f94d9da..608b7d0e9 100644 --- a/app/models/storage_location_repository_row.rb +++ b/app/models/storage_location_repository_row.rb @@ -29,7 +29,7 @@ class StorageLocationRepositoryRow < ApplicationRecord def ensure_uniq_position if storage_location.storage_location_repository_rows - .where("metadata->>'position' = ?", metadata['position'].to_json.gsub(',', ', ')) + .where("metadata->'position' = ?", metadata['position'].to_json) .where.not(id: id).exists? errors.add(:base, I18n.t('activerecord.errors.models.storage_location.not_uniq_position')) end