Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Metadata Fields retrieval for Shared Groups and Shared Projects [DFCT0010073] #630

Merged
merged 3 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/controllers/concerns/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 14 additions & 0 deletions app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions app/models/namespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/namespaces/project_namespaces.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions test/fixtures/samples.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 %>

Expand Down
12 changes: 12 additions & 0 deletions test/models/group_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions test/system/groups/samples_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Loading