From 8879314817e21347088fadfac7a84aea8692026e Mon Sep 17 00:00:00 2001 From: Eric Enns <492127+ericenns@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:10:11 -0500 Subject: [PATCH 1/3] fix: add metadata_fields methods to namespace model with override in group model and update metadata concern to use new method --- app/controllers/concerns/metadata.rb | 2 +- app/models/group.rb | 14 ++++++++++++++ app/models/namespace.rb | 4 ++++ test/fixtures/namespaces/project_namespaces.yml | 2 +- test/fixtures/samples.yml | 4 ++++ test/models/group_test.rb | 12 ++++++++++++ 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/app/controllers/concerns/metadata.rb b/app/controllers/concerns/metadata.rb index 78a2b3569d..6635552031 100644 --- a/app/controllers/concerns/metadata.rb +++ b/app/controllers/concerns/metadata.rb @@ -16,6 +16,6 @@ def pagy_with_metadata_sort(result) # rubocop:disable Metrics/AbcSize end def fields_for_namespace(namespace: nil, show_fields: false) - @fields = !show_fields || namespace.nil? ? [] : namespace.metadata_summary.keys + @fields = !show_fields || namespace.nil? ? [] : namespace.metadata_fields end end diff --git a/app/models/group.rb b/app/models/group.rb index 67fb768aaa..26cec304db 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -64,4 +64,18 @@ def self.sti_name def self.model_prefix 'GRP' end + + def metadata_fields + metadata_fields = metadata_summary.keys + + shared_groups.each do |shared_group| + metadata_fields.concat shared_group.metadata_summary.keys + end + + shared_project_namespaces.each do |shared_project_namespace| + metadata_fields.concat shared_project_namespace.metadata_summary.keys + end + + metadata_fields.uniq + end end diff --git a/app/models/namespace.rb b/app/models/namespace.rb index d5b3985e0f..e0bbbd0eae 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -305,4 +305,8 @@ def add_to_metadata_summary_count(namespaces, metadata, update_by_one) end end end + + def metadata_fields + metadata_summary.keys + end end diff --git a/test/fixtures/namespaces/project_namespaces.yml b/test/fixtures/namespaces/project_namespaces.yml index c524cc2be1..eebe931856 100644 --- a/test/fixtures/namespaces/project_namespaces.yml +++ b/test/fixtures/namespaces/project_namespaces.yml @@ -375,7 +375,7 @@ projectBravo_namespace: description: Project Bravo description type: Project parent_id: <%= ActiveRecord::FixtureSet.identify(:group_bravo, :uuid) %> - metadata_summary: {} + metadata_summary: {'metadatafield1': 1, 'metadatafield2': 1} puid: INXT_PRJ_AAAAAAAABF projectCharlie_namespace: diff --git a/test/fixtures/samples.yml b/test/fixtures/samples.yml index 5984eb1a69..6660281e2b 100644 --- a/test/fixtures/samples.yml +++ b/test/fixtures/samples.yml @@ -177,6 +177,10 @@ sampleBravo: description: Sample Bravo description. project_id: <%= ActiveRecord::FixtureSet.identify(:projectBravo, :uuid) %> puid: INXT_SAM_AAAAAAAABH + metadata: { 'metadatafield1': 'value1', 'metadatafield2': 'value2' } + metadata_provenance: { 'metadatafield1': { 'id': 1, 'source': 'analysis', + 'updated_at': <%= DateTime.new(2000,1,1) %> }, + 'metadatafield2': { 'id': 1, 'source': 'analysis', 'updated_at': <%= DateTime.new(2000,1,1) %> }} created_at: <%= 36.week.ago %> updated_at: <%= 36.day.ago %> diff --git a/test/models/group_test.rb b/test/models/group_test.rb index d0f78007f4..d791d2a5fe 100644 --- a/test/models/group_test.rb +++ b/test/models/group_test.rb @@ -194,4 +194,16 @@ def setup test '#model_prefix' do assert_equal 'GRP', Group.model_prefix end + + test '#metadata_summary' do + assert_equal %w[metadatafield1 metadatafield2], @group.metadata_fields + end + + test '#metadata_summary incorporates fields from shared groups' do + assert_equal %w[metadatafield1 metadatafield2], groups(:david_doe_group_four).metadata_fields + end + + test '#metadata_summary incorporates fields from shared projects' do + assert_equal %w[metadatafield1 metadatafield2], groups(:group_alpha).metadata_fields + end end From db9ee4168aef9531750ce070ab9ae00dd4c49db2 Mon Sep 17 00:00:00 2001 From: Eric Enns <492127+ericenns@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:32:10 -0500 Subject: [PATCH 2/3] chore: move metadat_fields in namespace outside of private --- app/models/namespace.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/namespace.rb b/app/models/namespace.rb index e0bbbd0eae..4f7feafaf2 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -245,6 +245,10 @@ def self.model_prefix raise NotImplementedError, 'The underlying class should implement this method to set the model prefix.' end + def metadata_fields + metadata_summary.keys + end + private # Method to restore namespace routes when the namespace is restored @@ -305,8 +309,4 @@ def add_to_metadata_summary_count(namespaces, metadata, update_by_one) end end end - - def metadata_fields - metadata_summary.keys - end end From e7c9566849b6912553f552dbe008dc4cca81301a Mon Sep 17 00:00:00 2001 From: Eric Enns <492127+ericenns@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:46:52 -0500 Subject: [PATCH 3/3] chore: fix some flaky group samples tests --- test/system/groups/samples_test.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/system/groups/samples_test.rb b/test/system/groups/samples_test.rb index f1b3ea348e..a185db5c1a 100644 --- a/test/system/groups/samples_test.rb +++ b/test/system/groups/samples_test.rb @@ -99,6 +99,7 @@ def retrieve_puids test 'can search the list of samples by name' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' within '#group_samples_list' do assert_selector 'table tbody tr', count: 20 assert_text @sample1.name @@ -119,6 +120,7 @@ def retrieve_puids test 'can sort the list of samples' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' # Because PUIDs are not always generated the same, issues regarding order have occurred when hard testing # the expected ordering of samples based on PUID. To resolve this, we will gather the first 4 PUIDs and ensure # they are ordered as expected against one another. @@ -169,6 +171,7 @@ def retrieve_puids test 'can filter by name and then sort the list of samples' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' within '#group_samples_list' do assert_selector 'table tbody tr', count: 20 within first('table tbody tr td') do @@ -207,6 +210,7 @@ def retrieve_puids test 'can filter by puid and then sort the list of samples' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' within '#group_samples_list' do assert_selector 'table tbody tr', count: 20 within first('table tbody tr td') do @@ -328,6 +332,7 @@ def retrieve_puids test 'can sort samples by metadata column' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' assert_selector 'label', text: I18n.t('groups.samples.index.search.metadata'), count: 1 assert_selector 'table thead tr th', count: 6 find('label', text: I18n.t('groups.samples.index.search.metadata')).click @@ -368,6 +373,7 @@ def retrieve_puids test 'filtering samples by list of sample puids' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' within 'tbody#group-samples-table-body' do assert_selector 'tr', count: 20 assert_selector 'tr td', text: @sample1.puid @@ -405,6 +411,7 @@ def retrieve_puids test 'selecting / deselecting all samples' do visit group_samples_url(@group) + assert_text 'Displaying items 1-20 of 26 in total' within 'tbody' do assert_selector 'input[name="sample_ids[]"]', count: 20 assert_selector 'input[name="sample_ids[]"]:checked', count: 0