Skip to content

Commit

Permalink
Adds support for communities and subcommunities (#1235)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
hectorcorrea and carolyncole committed Jun 2, 2023
1 parent 3955d42 commit 6bab432
Show file tree
Hide file tree
Showing 11 changed files with 179 additions and 3 deletions.
44 changes: 44 additions & 0 deletions app/models/group.rb
Expand Up @@ -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
8 changes: 7 additions & 1 deletion app/models/pdc_metadata/resource.rb
Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -196,4 +201,5 @@ def set_funders(resource, hash)
end
end
end
# rubocop:enable Metrics/ClassLength
end
8 changes: 7 additions & 1 deletion app/services/form_to_resource_service.rb
Expand Up @@ -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)
Expand All @@ -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?
Expand Down
2 changes: 2 additions & 0 deletions app/views/works/_additional_form.html.erb
Expand Up @@ -23,3 +23,5 @@
<%= render(partial: 'works/organizational_contributors_table') %>
<%= render(partial: 'works/domains') %>
<%= render(partial: 'works/communities') %>
46 changes: 46 additions & 0 deletions app/views/works/_communities.html.erb
@@ -0,0 +1,46 @@
<div class="section-title">
<% if @work.group.communities.count == 1 %>
<!-- Special case for PPPL that has a single community -->
<details>
<summary>Community</summary>
The community for this dataset.
</details>
<select id="communities" name="communities[]" class="form-select" >
<option selected><%= @work.group.communities.first %></option>
</select>
<% else %>
<details>
<summary>Communities</summary>
Select one or more communities for this dataset.
</details>
<select id="communities" name="communities[]" class="form-select" multiple >
<% @work.group.communities.each do |community| %>
<% if @work.resource.communities.include?(community) %>
<option selected><%= community %></option>
<% else %>
<option><%= community %></option>
<% end %>
<% end %>
</select>
<% end %>
<% if @work.group.subcommunities.count > 0 %>
<br/>
<!-- Display subcommunities only for those groups that have them. -->
<details>
<summary>Subcommunities</summary>
Select one or more subcommunities for this dataset.
</details>

<select id="subcommunities" name="subcommunities[]" class="form-select" multiple >
<% @work.group.subcommunities.each do |subcommunity| %>
<% if @work.resource.subcommunities.include?(subcommunity) %>
<option selected><%= subcommunity %></option>
<% else %>
<option><%= subcommunity %></option>
<% end %>
<% end %>
</select>
<% end %>
</div>

14 changes: 14 additions & 0 deletions app/views/works/show.html.erb
Expand Up @@ -231,6 +231,20 @@
<dt><%= t("work.group") %></dt>
<dd><%= @work.group.title %></dd>

<% if @work.resource.communities.count > 0 %>
<dt>Communities</dt>
<% @work.resource.communities.each do |community| %>
<dd><%= community %></dd>
<% end %>
<% if @work.resource.subcommunities.count > 0 %>
<dt>Subcommunities</dt>
<% @work.resource.subcommunities.each do |subcommunity| %>
<dd><%= subcommunity %></dd>
<% end %>
<% end %>
<% end %>
<% if @work.resource.funders.count > 0 %>
<dt>Funders</dt>
<% @work.resource.funders.each do |funder| %>
Expand Down
21 changes: 21 additions & 0 deletions spec/factories/work.rb
Expand Up @@ -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 }
Expand Down
2 changes: 2 additions & 0 deletions spec/models/pdc_metadata/resource_spec.rb
Expand Up @@ -162,6 +162,8 @@
"award_uri" => nil
}],
"domains" => ["Humanities"],
"communities" => [],
"subcommunities" => [],
"migrated" => true
}
end
Expand Down
4 changes: 4 additions & 0 deletions spec/models/work_spec.rb
Expand Up @@ -58,6 +58,8 @@
"contributors" => [],
"funders" => [],
"domains" => [],
"communities" => [],
"subcommunities" => [],
"migrated" => false
},
"files" => [],
Expand Down Expand Up @@ -894,6 +896,8 @@
}
],
"domains":[],
"communities":[],
"subcommunities":[],
"migrated": false
}'
end
Expand Down
4 changes: 3 additions & 1 deletion spec/services/resource_compare_service_spec.rb
Expand Up @@ -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: "" }],
Expand Down
29 changes: 29 additions & 0 deletions spec/system/work_edit_spec.rb
Expand Up @@ -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 }
Expand Down

0 comments on commit 6bab432

Please sign in to comment.