diff --git a/app/models/work.rb b/app/models/work.rb index 8cfb4da80..58ac3025d 100644 --- a/app/models/work.rb +++ b/app/models/work.rb @@ -78,8 +78,8 @@ def editable_by?(user) end def editable_in_current_state?(user) - # anyone with edit privleges can edit a work while it is in draft or awaiting approval - return editable_by?(user) if draft? || awaiting_approval? + # anyone with edit privleges can edit a work while it is in draft + return editable_by?(user) if draft? # Only admisitrators can edit a work in other states administered_by?(user) diff --git a/spec/models/work_spec.rb b/spec/models/work_spec.rb index 0bf1f9375..3c088e8a4 100644 --- a/spec/models/work_spec.rb +++ b/spec/models/work_spec.rb @@ -1306,4 +1306,37 @@ end end end + + describe "#editable_in_current_state?" do + it "is editable by the depositor" do + expect(work.editable_in_current_state?(work.created_by_user)).to be_truthy + end + + it "is editable by a moderator" do + expect(work.editable_in_current_state?(curator_user)).to be_truthy + end + + it "is not editable by a random user" do + expect(work.editable_in_current_state?(rd_user)).to be_falsey + end + + context "it is awaiting approval" do + let(:work) { FactoryBot.create :awaiting_approval_work } + before do + stub_s3 data: [FactoryBot.build(:s3_readme)] + end + + it "is not editable by the depositor" do + expect(work.editable_in_current_state?(work.created_by_user)).to be_falsey + end + + it "is editable by a moderator" do + expect(work.editable_in_current_state?(curator_user)).to be_truthy + end + + it "is not editable by a random user" do + expect(work.editable_in_current_state?(rd_user)).to be_falsey + end + end + end end diff --git a/spec/system/authz_submitter_spec.rb b/spec/system/authz_submitter_spec.rb index 86f29f7e6..843cfb4fe 100644 --- a/spec/system/authz_submitter_spec.rb +++ b/spec/system/authz_submitter_spec.rb @@ -48,9 +48,9 @@ page.find(:xpath, "//input[@value='file_other']").choose click_on "Next" click_on "Next" - click_on "Complete" + click_on "Cancel" # we don't want to complete becuase we can not edit after - expect(page).to have_content "awaiting_approval" + expect(page).to have_content "draft" work = Work.last # Submitter can edit their own work diff --git a/spec/system/view_data_in_s3_spec.rb b/spec/system/view_data_in_s3_spec.rb index 63cbb7f71..fbab7fd76 100644 --- a/spec/system/view_data_in_s3_spec.rb +++ b/spec/system/view_data_in_s3_spec.rb @@ -25,7 +25,7 @@ work.save work.reload - work.state = "awaiting_approval" + work.state = "draft" work.save visit work_path(work) @@ -33,7 +33,8 @@ expect(page).to have_content file1.filename_display expect(page).to have_content file2.filename_display - click_on "Edit" + click_on "Edit" # takes you to the wizard where no files are shown + visit edit_work_path(work) expect(page).to have_content file1.filename_display expect(page).to have_content file2.filename_display end diff --git a/spec/system/work_edit_spec.rb b/spec/system/work_edit_spec.rb index 88747fca2..8166843f5 100644 --- a/spec/system/work_edit_spec.rb +++ b/spec/system/work_edit_spec.rb @@ -193,7 +193,7 @@ end context "for PPPL works" do - let(:work) { FactoryBot.create(:tokamak_work_awaiting_approval) } + let(:work) { FactoryBot.create(:tokamak_work, state: "draft") } let(:user) { work.created_by_user } it "allows user to select a subcommunity" do diff --git a/spec/system/work_spec.rb b/spec/system/work_spec.rb index 356df2d3a..1752b589d 100644 --- a/spec/system/work_spec.rb +++ b/spec/system/work_spec.rb @@ -191,7 +191,7 @@ def value_for(label) it "does not use the wizard if the work once the work is not in draft" do sign_in user visit work_path(awaiting_approval_work) - expect(page.html.include?("/works/#{awaiting_approval_work.id}/edit")).to be true + expect(page.html.include?("/works/#{awaiting_approval_work.id}/edit")).to be false end end