From e092e31d88bf7afe008863d512926ad777a2a403 Mon Sep 17 00:00:00 2001 From: Anton Date: Fri, 16 May 2025 13:38:42 +0200 Subject: [PATCH] Fix redirect for storage locations in activities [SCI-11917] --- .../storage_location_repository_rows_controller.rb | 4 ++-- app/controllers/storage_locations_controller.rb | 4 +++- app/helpers/global_activities_helper.rb | 6 +++--- app/models/storage_location_repository_row.rb | 4 ++++ 4 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/controllers/storage_location_repository_rows_controller.rb b/app/controllers/storage_location_repository_rows_controller.rb index 1aeb6ded7..69e6030a2 100644 --- a/app/controllers/storage_location_repository_rows_controller.rb +++ b/app/controllers/storage_location_repository_rows_controller.rb @@ -29,7 +29,7 @@ class StorageLocationRepositoryRowsController < ApplicationController end storage_location_repository_row = StorageLocationRepositoryRow.new( repository_row: @repository_row, - storage_location: @storage_location, + container_storage_location: @storage_location, metadata: { position: position[0..1] }, created_by: current_user ) @@ -41,7 +41,7 @@ class StorageLocationRepositoryRowsController < ApplicationController else storage_location_repository_row = StorageLocationRepositoryRow.new( repository_row: @repository_row, - storage_location: @storage_location, + container_storage_location: @storage_location, created_by: current_user ) storage_location_repository_row.with_lock do diff --git a/app/controllers/storage_locations_controller.rb b/app/controllers/storage_locations_controller.rb index 7dfaa437b..088fb1a7f 100644 --- a/app/controllers/storage_locations_controller.rb +++ b/app/controllers/storage_locations_controller.rb @@ -38,7 +38,9 @@ class StorageLocationsController < ApplicationController end end - def show; end + def show + redirect_to storage_locations_path(parent_id: @storage_location.id) and return unless @storage_location.container + end def create ActiveRecord::Base.transaction do diff --git a/app/helpers/global_activities_helper.rb b/app/helpers/global_activities_helper.rb index e4d2770e7..ee8f758e4 100644 --- a/app/helpers/global_activities_helper.rb +++ b/app/helpers/global_activities_helper.rb @@ -115,10 +115,10 @@ module GlobalActivitiesHelper project_folder_path(obj, team: obj.team.id) end when StorageLocation - path = if obj.new_record? - storage_locations_path(team: activity.team.id) + path = if obj.container + storage_location_path(obj, team: obj.team_id) else - storage_location_path(obj, team: activity.team.id) + storage_locations_path(parent_id: obj.id, team: obj.team_id) end when Form path = form_path(obj, team: obj.team.id) diff --git a/app/models/storage_location_repository_row.rb b/app/models/storage_location_repository_row.rb index fd69fea25..5d3769301 100644 --- a/app/models/storage_location_repository_row.rb +++ b/app/models/storage_location_repository_row.rb @@ -7,6 +7,10 @@ class StorageLocationRepositoryRow < ApplicationRecord default_scope -> { kept } belongs_to :storage_location, inverse_of: :storage_location_repository_rows + belongs_to :container_storage_location, -> { where(container: true) }, + class_name: 'StorageLocation', + foreign_key: 'storage_location_id', + inverse_of: :storage_location_repository_rows belongs_to :repository_row, inverse_of: :storage_location_repository_rows belongs_to :created_by, class_name: 'User'