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

Automatically publish minor version changes #1688

Merged
merged 1 commit into from
Jun 17, 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
10 changes: 2 additions & 8 deletions app/controllers/stash_datacite/peer_review_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,13 @@ def release
begin
@resource = StashEngine::Resource.find(peer_review_params[:id])
@error_list = StashDatacite::Resource::DatasetValidations.new(resource: @resource).errors
@resource.hold_for_peer_review = false
@resource.peer_review_end_date = nil
@resource.update(hold_for_peer_review: false, peer_review_end_date: nil)
@resource.reload

if @error_list.empty?
@resource.curation_activities << StashEngine::CurationActivity.create(user_id: current_user.id,
status: 'submitted',
note: 'Release from PPR')
end

@resource.save
@resource.reload

if @error_list.empty?
redirect_to dashboard_path, notice: 'Dataset released from private for peer review and submitted for curation'
else
duplicate_resource
Expand Down
42 changes: 28 additions & 14 deletions app/models/stash_engine/resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ def previous_curated_resource
.order(id: :desc).first
end

def previous_resource_published?
%w[published embargoed].include?(previous_resource&.last_curation_activity&.status)
end

# ------------------------------------------------------------
# Ownership

Expand Down Expand Up @@ -1053,6 +1057,9 @@ def prepare_for_curation

target_status = create_post_submission_status(prior_cur_act)

# If it's auto-published, we're done
return if %w[published embargoed].include?(target_status)

# Warn curators if this is potentially a duplicate
completions = StashDatacite::Resource::Completions.new(self)
if prior_version.blank? && completions.duplicate_submission
Expand All @@ -1061,17 +1068,15 @@ def prepare_for_curation
note: "System noticed possible duplicate dataset #{dup_id}")
end

# if it's the first version, or the prior version was in the submitter's control, we're done
# If it's the first version, or the prior version was in the submitter's control, we're done
return if prior_version.blank? || prior_version.current_curation_status.blank?
return unless identifier.date_last_curated.present?

# If we get here, the previous status was *not* controlled by the submitter,
# meaning there was a curator
# If we get here, the previous version was *not* controlled by the submitter, but a curator
# so assign it to the previous curator, with a fallback process
auto_assign_curator(target_status: target_status)

# If the last user to edit it was the current_editor
# return it to curation status
# If the last user to edit it was the current_editor return it to curation status
return unless last_curation_activity.user_id == current_editor_id

curation_activities << StashEngine::CurationActivity.create(user_id: 0, status: 'curation',
Expand All @@ -1080,27 +1085,36 @@ def prepare_for_curation

def create_post_submission_status(prior_cur_act)
attribution = (prior_cur_act.nil? ? (current_editor_id || user_id) : prior_cur_act.user_id)
curation_note = ''
target_status = 'submitted'

# Determine whether to auto-publish
if previous_resource_published?
changes = changed_fields(previous_resource)
changes = changes.delete_if { |c| c.is_a?(Array) }
if (changes - %w[related_identifiers subjects funders]).empty?
# create submitted status
curation_activities << StashEngine::CurationActivity.create(user_id: attribution, status: target_status, note: curation_note)
# immediately create published status
target_status = previous_resource.last_curation_activity.status
curation_note = "Auto-published with minimal changes to #{changes.join(', ')}"
end
# Determine which submission status to use, :submitted or :peer_review status
publication_accepted = identifier.has_accepted_manuscript? || identifier.publication_article_doi
if hold_for_peer_review?
elsif hold_for_peer_review? && previous_curated_resource.blank? && curation_start_date.blank?
# Moving this logic to user facing, will not allow PPR selection by user
publication_accepted = identifier.has_accepted_manuscript? || identifier.publication_article_doi
if publication_accepted
manuscript = identifier.manuscript_number || identifier.publication_article_doi
curation_note = "Private for peer review was requested, but associated manuscript #{manuscript} has " \
'already been accepted, so automatically moving to submitted status'
curation_note = "Private for peer review was requested, but associated manuscript #{manuscript} has already been accepted"
target_status = 'submitted'
update(hold_for_peer_review: false, peer_review_end_date: nil)
else
curation_note = "Set to Private for peer review at author's request"
target_status = 'peer_review'
update(peer_review_end_date: Time.now.utc + 6.months)
end
else
curation_note = ''
target_status = 'submitted'
end

# Generate the :submitted or :peer_review status
# Generate the status
# This will usually have the side effect of sending out notification emails to the author/journal
curation_activities << StashEngine::CurationActivity.create(user_id: attribution, status: target_status, note: curation_note)
target_status
Expand Down
66 changes: 66 additions & 0 deletions spec/features/stash_datacite/dataset_versioning_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,48 @@
expect(@resource.current_editor_id).to eql(@curator.id)
end

it 'does not go to ppr when prior version was curated', js: true do
@resource = create(
:resource, :submitted, identifier: @identifier, user_id: @author.id, tenant_id: @author.tenant_id,
current_editor_id: @curator.id, hold_for_peer_review: true
)
create(:curation_activity, user_id: @curator.id, resource_id: @resource.id, status: 'curation')
create(:curation_activity, user_id: @curator.id, resource_id: @resource.id, status: 'action_required')
@resource.reload

sign_in(@author)
click_link 'My datasets'
within(:css, "form[action=\"/stash/metadata_entry_pages/new_version?resource_id=#{@resource.id}\"]") do
find('button[name="update"]').click
end
update_dataset
@resource.reload
expect(@resource.current_curation_status).to eql('submitted')
expect(@resource.current_editor_id).to eql(@curator.id)
end

it 'is automatically published with simple changes', js: true do
sign_in(@author)
click_link 'My datasets'
create_dataset
@resource.current_state = 'submitted'
@resource.publication_date { Date.today.to_s }
@resource.save
@resource.reload
create(:curation_activity, :curation, user: @resource.user, resource: @resource)
create(
:curation_activity, :published, resource: @resource,
user: create(:user, role: 'admin', role_object: @resource.user.tenant, tenant_id: @resource.user.tenant_id)
)
click_link 'My datasets'
within(:css, "form[action=\"/stash/metadata_entry_pages/new_version?resource_id=#{@resource.id}\"]") do
find('button[name="update"]').click
end
minor_update
@resource.reload
expect(@resource.current_curation_status).to eql('published')
end

context :curator_workflow do

before(:each) do
Expand Down Expand Up @@ -376,6 +418,30 @@

end

def create_dataset
start_new_dataset
fill_required_fields
navigate_to_review
check 'agree_to_license'
check 'agree_to_tos'
check 'agree_to_payment'
click_button 'submit_dataset'
@resource = StashEngine::Resource.last
mock_successfull_merritt_submission!(@resource)
end

def minor_update
navigate_to_metadata
fill_in_keywords
fill_in_funder
# Submit the changes
navigate_to_review
agree_to_everything
click_button 'Submit'
@resource = StashEngine::Resource.last
mock_successfull_merritt_submission!(@resource)
end

def update_dataset(curator: false)
# Add a value to the dataset, submit it and then mock a successful submission
navigate_to_metadata
Expand Down