Skip to content

Commit

Permalink
allow superusers to withdraw any dataset
Browse files Browse the repository at this point in the history
  • Loading branch information
alinvetian committed Nov 26, 2024
1 parent b2ce37f commit d14aed7
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 12 deletions.
4 changes: 2 additions & 2 deletions app/controllers/stash_engine/admin_dashboard_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,10 @@ def load
end

def curation_activity_change
return publishing_error if @resource.id != @identifier.last_submitted_resource.id &&
return publishing_error if @resource.id != @identifier.last_submitted_resource&.id &&
%w[embargoed published].include?(params.dig(:curation_activity, :status))

return state_error unless CurationActivity.allowed_states(@last_state).include?(@status)
return state_error unless CurationActivity.allowed_states(@last_state, current_user).include?(@status)

decipher_curation_activity
@note = params.dig(:curation_activity, :note)
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/stash_engine/admin_datasets_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def status_select(statuses = [])
end

def filter_status_select(current_status)
statuses = StashEngine::CurationActivity.allowed_states(current_status)
statuses = StashEngine::CurationActivity.allowed_states(current_status, current_user)

statuses.delete(current_status) # because we don't show the current state as an option, it is implied by leaving state blank

Expand Down
6 changes: 4 additions & 2 deletions app/models/stash_engine/curation_activity.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,10 @@ def first_time_in_status?
resource.curation_activities.where('id < ?', id).where(status: status).empty?
end

def self.allowed_states(current_state)
CURATOR_ALLOWED_STATES[current_state].dup
def self.allowed_states(current_state, current_user)
statuses = CURATOR_ALLOWED_STATES[current_state].dup
statuses << 'withdrawn' if current_user.superuser? # superusers can withdraw a datasets from any status
statuses.uniq
end

# Private methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<p>Edit curation status of <em><%= @resource.title %></em></p>
<%= hidden_field_tag :identifier_id, @resource.identifier_id %>
<%# Users cannot change the status or publication date once the files are published %>
<% if @resource.curatable? && filter_status_select(@resource.current_curation_status) %>
<% if (@resource.curatable? || current_user.superuser?) && filter_status_select(@resource.current_curation_status) %>
<%= form.fields_for :curation_activity, @curation_activity do |ca| %>
<div class="c-input">
<%= ca.label :status, 'Status', class: 'c-input__label' %>
Expand Down
27 changes: 21 additions & 6 deletions spec/models/stash_engine/curation_activity_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,14 +186,29 @@ module StashEngine
end

describe 'self.allowed_states(current_state)' do
it 'indicates the states that are allowed from each' do
expect(CurationActivity.allowed_states('curation')).to \
eq(%w[processing peer_review curation action_required withdrawn embargoed published])
context 'when user is an admin' do
let(:user) { create(:user, role: 'admin') }

expect(CurationActivity.allowed_states('withdrawn')).to \
eq(%w[withdrawn curation])
it 'indicates the states that are allowed from each' do
expect(CurationActivity.allowed_states('in_progress', user)).to eq(%w[in_progress])

expect(CurationActivity.allowed_states('curation', user)).to \
eq(%w[processing peer_review curation action_required withdrawn embargoed published])

expect(CurationActivity.allowed_states('withdrawn', user)).to \
eq(%w[withdrawn curation])
end
end
end

context 'when user is an superuser' do
let(:user) { create(:user, role: 'superuser') }

CurationActivity::CURATOR_ALLOWED_STATES.keys.each do |status|
it "allows withdrawn for #{status} status" do
expect(CurationActivity.allowed_states(status, user)).to include('withdrawn')
end
end
end
end
end
end

0 comments on commit d14aed7

Please sign in to comment.