From 6bab4324bbbf8a5ba4ee2fb3bfbaca360521d4e8 Mon Sep 17 00:00:00 2001 From: Hector Correa Date: Fri, 2 Jun 2023 15:36:18 -0400 Subject: [PATCH] Adds support for communities and subcommunities (#1235) * First pass at allowing users to set the community and subcommunity of a dataset. * Minor tweaks * Adjust tests to pass the new fields * Added a few tests --------- Co-authored-by: carolyncole <1599081+carolyncole@users.noreply.github.com> --- app/models/group.rb | 44 ++++++++++++++++++ app/models/pdc_metadata/resource.rb | 8 +++- app/services/form_to_resource_service.rb | 8 +++- app/views/works/_additional_form.html.erb | 2 + app/views/works/_communities.html.erb | 46 +++++++++++++++++++ app/views/works/show.html.erb | 14 ++++++ spec/factories/work.rb | 21 +++++++++ spec/models/pdc_metadata/resource_spec.rb | 2 + spec/models/work_spec.rb | 4 ++ .../services/resource_compare_service_spec.rb | 4 +- spec/system/work_edit_spec.rb | 29 ++++++++++++ 11 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 app/views/works/_communities.html.erb diff --git a/app/models/group.rb b/app/models/group.rb index 66caf58cc..7bbec512f 100644 --- a/app/models/group.rb +++ b/app/models/group.rb @@ -153,4 +153,48 @@ def delete_permission(current_user, removed_user) errors.add(:delete_permission, "Unauthorized") end end + + def communities + values = [] + if code == "PPPL" + values << "Princeton Plasma Physics Laboratory" + else + values << "Princeton Neuroscience Institute" + values << "Department of Geosciences" + values << "Mechanical and Aerospace Engineering" + values << "Astrophysical Sciences" + values << "Civil and Environmental Engineering" + values << "Chemical and Biological Engineering" + values << "Digital Humanities" + values << "Music and Arts" + values << "Princeton School of Public and International Affairs" + end + values + end + + # rubocop:disable Metrics/MethodLength + def subcommunities + values = [] + if code == "PPPL" + values << "Spherical Torus" + values << "Advanced Projects" + values << "ITER and Tokamaks" + values << "Theory" + values << "NSTX-U" + values << "NSTX" + values << "Plasma Science & Technology" + values << "Theory and Computation" + values << "Stellarators" + values << "PPPL Collaborations" + values << "MAST-U" + values << "Other Projects" + values << "System Studies" + end + values + end + # rubocop:enable Metrics/MethodLength + + def default_community + return communities.first if code == "PPPL" + end end diff --git a/app/models/pdc_metadata/resource.rb b/app/models/pdc_metadata/resource.rb index 88c579774..9289e8ef5 100644 --- a/app/models/pdc_metadata/resource.rb +++ b/app/models/pdc_metadata/resource.rb @@ -7,10 +7,11 @@ def self.fuzzy_match(obj, value) obj.key.to_s == value or obj.value.casecmp(value).zero? end + # rubocop:disable Metrics/ClassLength class Resource attr_accessor :creators, :titles, :publisher, :publication_year, :resource_type, :resource_type_general, :description, :doi, :ark, :rights, :version_number, :collection_tags, :keywords, :related_objects, - :funders, :organizational_contributors, :domains, :migrated + :funders, :organizational_contributors, :domains, :migrated, :communities, :subcommunities # rubocop:disable Metrics/MethodLength def initialize(doi: nil, title: nil, resource_type: nil, resource_type_general: nil, creators: [], description: nil) @@ -33,6 +34,8 @@ def initialize(doi: nil, title: nil, resource_type: nil, resource_type_general: @organizational_contributors = [] @funders = [] @domains = [] + @communities = [] + @subcommunities = [] @migrated = false end # rubocop:enable Metrics/MethodLength @@ -136,6 +139,8 @@ def set_curator_controlled_metadata(resource, hash) def set_additional_metadata(resource, hash) resource.keywords = hash["keywords"] || [] + resource.communities = hash["communities"] || [] + resource.subcommunities = hash["subcommunities"] || [] end def set_titles(resource, hash) @@ -196,4 +201,5 @@ def set_funders(resource, hash) end end end + # rubocop:enable Metrics/ClassLength end diff --git a/app/services/form_to_resource_service.rb b/app/services/form_to_resource_service.rb index d0ed11dec..e3e78ed61 100644 --- a/app/services/form_to_resource_service.rb +++ b/app/services/form_to_resource_service.rb @@ -15,8 +15,8 @@ def convert(params, work) resource.publication_year = params["publication_year"] if params["publication_year"].present? resource.rights = PDCMetadata::Rights.find(params["rights_identifier"]) resource.keywords = (params["keywords"] || "").split(",").map(&:strip) - resource.domains = params["domains"] || [] + add_additional_metadata(params, resource) add_curator_controlled(params, resource) add_titles(params, resource) add_related_objects(params, resource) @@ -40,6 +40,12 @@ def reset_resource_to_work(work) resource end + def add_additional_metadata(params, resource) + resource.domains = params["domains"] || [] + resource.communities = params["communities"] || [] + resource.subcommunities = params["subcommunities"] || [] + end + def add_curator_controlled(params, resource) resource.doi = params["doi"] if params["doi"].present? resource.ark = params["ark"] if params["ark"].present? diff --git a/app/views/works/_additional_form.html.erb b/app/views/works/_additional_form.html.erb index 4bee74fa1..489bd2614 100644 --- a/app/views/works/_additional_form.html.erb +++ b/app/views/works/_additional_form.html.erb @@ -23,3 +23,5 @@ <%= render(partial: 'works/organizational_contributors_table') %> <%= render(partial: 'works/domains') %> + +<%= render(partial: 'works/communities') %> diff --git a/app/views/works/_communities.html.erb b/app/views/works/_communities.html.erb new file mode 100644 index 000000000..a08df22c4 --- /dev/null +++ b/app/views/works/_communities.html.erb @@ -0,0 +1,46 @@ +
+ <% if @work.group.communities.count == 1 %> + +
+ Community + The community for this dataset. +
+ + <% else %> +
+ Communities + Select one or more communities for this dataset. +
+ + <% end %> + + <% if @work.group.subcommunities.count > 0 %> +
+ +
+ Subcommunities + Select one or more subcommunities for this dataset. +
+ + + <% end %> +
+ diff --git a/app/views/works/show.html.erb b/app/views/works/show.html.erb index 6a885a1bb..53f023829 100644 --- a/app/views/works/show.html.erb +++ b/app/views/works/show.html.erb @@ -231,6 +231,20 @@
<%= t("work.group") %>
<%= @work.group.title %>
+ <% if @work.resource.communities.count > 0 %> +
Communities
+ <% @work.resource.communities.each do |community| %> +
<%= community %>
+ <% end %> + + <% if @work.resource.subcommunities.count > 0 %> +
Subcommunities
+ <% @work.resource.subcommunities.each do |subcommunity| %> +
<%= subcommunity %>
+ <% end %> + <% end %> + <% end %> + <% if @work.resource.funders.count > 0 %>
Funders
<% @work.resource.funders.each do |funder| %> diff --git a/spec/factories/work.rb b/spec/factories/work.rb index 8814cb4ce..2992be081 100644 --- a/spec/factories/work.rb +++ b/spec/factories/work.rb @@ -77,6 +77,27 @@ created_by_user_id { FactoryBot.create(:pppl_submitter).id } end + factory :tokamak_work_awaiting_approval do + group { Group.plasma_laboratory } + state { "awaiting_approval" } + resource do + PDCMetadata::Resource.new_from_jsonb({ + "doi" => "10.34770/not_yet_assigned", + "ark" => "ark:/88435/dsp015d86p342b", + "identifier_type" => "DOI", + "titles" => [{ "title" => "Electron Temperature Gradient Driven Transport Model for Tokamak Plasmas" }], + "description" => "A new model for electron temperature gradient (ETG) modes is developed as a component of the Multi-Mode anomalous transport module.", + "creators" => [ + { "value" => "Rafiq, Tariq", "name_type" => "Personal", "given_name" => "Tariq", "family_name" => "Rafiq", "affiliations" => [], "sequence" => "1" } + ], + "resource_type" => "Dataset", "publisher" => "Princeton University", "publication_year" => "2022", + "version_number" => "1", + "rights" => { "identifier" => "CC BY" } + }) + end + created_by_user_id { FactoryBot.create(:pppl_submitter).id } + end + factory :sowing_the_seeds_work do title { "Sowing the Seeds for More Usable Web Archives: A Usability Study of Archive-It" } group { Group.research_data } diff --git a/spec/models/pdc_metadata/resource_spec.rb b/spec/models/pdc_metadata/resource_spec.rb index f5abefcec..f88d5d629 100644 --- a/spec/models/pdc_metadata/resource_spec.rb +++ b/spec/models/pdc_metadata/resource_spec.rb @@ -162,6 +162,8 @@ "award_uri" => nil }], "domains" => ["Humanities"], + "communities" => [], + "subcommunities" => [], "migrated" => true } end diff --git a/spec/models/work_spec.rb b/spec/models/work_spec.rb index 782abd887..c303d067b 100644 --- a/spec/models/work_spec.rb +++ b/spec/models/work_spec.rb @@ -58,6 +58,8 @@ "contributors" => [], "funders" => [], "domains" => [], + "communities" => [], + "subcommunities" => [], "migrated" => false }, "files" => [], @@ -894,6 +896,8 @@ } ], "domains":[], + "communities":[], + "subcommunities":[], "migrated": false }' end diff --git a/spec/services/resource_compare_service_spec.rb b/spec/services/resource_compare_service_spec.rb index 022e3d470..d5f0f9599 100644 --- a/spec/services/resource_compare_service_spec.rb +++ b/spec/services/resource_compare_service_spec.rb @@ -70,7 +70,9 @@ individual_contributors: [], organizational_contributors: [], creators: [], - domains: ["Humanities"] + domains: ["Humanities"], + communities: [], + subcommunities: [] } expected_diff = { doi: [{ action: :changed, from: "10.34770/pe9w-x904", to: "" }], diff --git a/spec/system/work_edit_spec.rb b/spec/system/work_edit_spec.rb index 2a054dba7..1bf704c91 100644 --- a/spec/system/work_edit_spec.rb +++ b/spec/system/work_edit_spec.rb @@ -168,6 +168,35 @@ end end + context "for PRDS works" do + let(:work) { FactoryBot.create(:distinct_cytoskeletal_proteins_work) } + let(:user) { work.created_by_user } + + it "allows user to select a community (but not subcommunities)" do + sign_in user + visit edit_work_path(work) + click_on "Additional Metadata" + select "Department of Geosciences", from: "communities" + expect(page).to_not have_content("Subcommunities") + click_on "Save Work" + expect(page).to have_content("Department of Geosciences") + end + end + + context "for PPPL works" do + let(:work) { FactoryBot.create(:tokamak_work_awaiting_approval) } + let(:user) { work.created_by_user } + + it "allows user to select a subcommunity" do + sign_in user + visit edit_work_path(work) + click_on "Additional Metadata" + select "Spherical Torus", from: "subcommunities" + click_on "Save Work" + expect(page).to have_content("Spherical Torus") + end + end + context "change log" do let(:work) { FactoryBot.create(:distinct_cytoskeletal_proteins_work) } let(:user) { work.created_by_user }