From b4a071e0abba35915434e3178edae8570a12f4ea Mon Sep 17 00:00:00 2001 From: Katherine Thiessen Date: Fri, 13 Sep 2024 14:49:51 -0500 Subject: [PATCH] updating a file import translation (#757) --- app/services/samples/metadata/file_import_service.rb | 12 +++++++++--- config/locales/en.yml | 3 ++- config/locales/fr.yml | 3 ++- .../samples/metadata/file_import_service_test.rb | 12 +++++++++--- 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/app/services/samples/metadata/file_import_service.rb b/app/services/samples/metadata/file_import_service.rb index c4b811febe..58a93bc5a4 100644 --- a/app/services/samples/metadata/file_import_service.rb +++ b/app/services/samples/metadata/file_import_service.rb @@ -111,13 +111,19 @@ def perform_file_import metadata_changes = process_sample_metadata_row(sample_id, metadata) response[sample_id] = metadata_changes if metadata_changes rescue ActiveRecord::RecordNotFound - @namespace.errors.add(:sample, - I18n.t('services.samples.metadata.import_file.sample_not_found', - sample_name: sample_id, namespace_type: @namespace.type.downcase)) + @namespace.errors.add(:sample, error_message(sample_id)) end response end + def error_message(sample_id) + if @namespace.type == 'Group' + I18n.t('services.samples.metadata.import_file.sample_not_found_within_group', sample_puid: sample_id) + else + I18n.t('services.samples.metadata.import_file.sample_not_found_within_project', sample_puid: sample_id) + end + end + def process_sample_metadata_row(sample_id, metadata) sample = find_sample(sample_id) metadata_changes = UpdateService.new(sample.project, sample, current_user, { 'metadata' => metadata }).execute diff --git a/config/locales/en.yml b/config/locales/en.yml index 1de5fd303c..0e1513a6c1 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1485,7 +1485,8 @@ en: missing_metadata_row: The file does not have any metadata rows. Please add some rows of metadata to the file and retry uploading. missing_sample_id_column: The file is missing the sample id column. Please make sure the sample id column exists and retry uploading. sample_metadata_fields_not_updated: Sample '%{sample_name}' with field(s) '%{metadata_fields}' cannot be updated. - sample_not_found: Sample '%{sample_name}' is not found within this project + sample_not_found_within_group: Could not find sample with puid '%{sample_puid}' in this group. + sample_not_found_within_project: Could not find sample with puid or name '%{sample_puid}' in this project. sample_does_not_belong_to_project: Sample '%{sample_name}'' does not belong to project '%{project_name}' update_fields: key_exists: Sample already contains metadata field '%{key}'. diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 9af6e67b38..abf0f0dd23 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -1485,7 +1485,8 @@ fr: missing_metadata_row: The file does not have any metadata rows. Please add some rows of metadata to the file and retry uploading. missing_sample_id_column: The file is missing the sample id column. Please make sure the sample id column exists and retry uploading. sample_metadata_fields_not_updated: Sample '%{sample_name}' with field(s) '%{metadata_fields}' cannot be updated. - sample_not_found: Sample '%{sample_name}' is not found within this project + sample_not_found_within_group: Could not find sample with puid '%{sample_puid}' in this group. + sample_not_found_within_project: Could not find sample with puid or name '%{sample_puid}' in this project. sample_does_not_belong_to_project: Sample '%{sample_name}'' does not belong to project '%{project_name}' update_fields: key_exists: Sample already contains metadata field '%{key}'. diff --git a/test/services/samples/metadata/file_import_service_test.rb b/test/services/samples/metadata/file_import_service_test.rb index 4391043e64..eaf528b579 100644 --- a/test/services/samples/metadata/file_import_service_test.rb +++ b/test/services/samples/metadata/file_import_service_test.rb @@ -110,8 +110,10 @@ def setup assert_empty Samples::Metadata::FileImportService.new(@group, @john_doe, params).execute assert_equal(@group.errors.messages_for(:sample).first, - I18n.t('services.samples.metadata.import_file.sample_not_found', - sample_name: @sample1.name, namespace_type: @group.type.downcase)) + I18n.t( + 'services.samples.metadata.import_file.sample_not_found_within_group', + sample_puid: @sample1.name + )) end test 'import sample metadata via csv file using sample puids for group' do @@ -272,7 +274,11 @@ def setup response = Samples::Metadata::FileImportService.new(@project.namespace, @john_doe, params).execute assert_equal({ @sample1.name => { added: %w[metadatafield1 metadatafield2 metadatafield3], updated: [], deleted: [], not_updated: [], unchanged: [] } }, response) - assert_equal("Sample 'Project 2 Sample 3' is not found within this project", + + assert_equal(I18n.t( + 'services.samples.metadata.import_file.sample_not_found_within_project', + sample_puid: 'Project 2 Sample 3' + ), @project.namespace.errors.messages_for(:sample).first) assert_equal({ 'metadatafield1' => '10', 'metadatafield2' => '20', 'metadatafield3' => '30' }, @sample1.reload.metadata)