Skip to content

Commit

Permalink
Only allow the user to edit their work before it is awaiting approval (
Browse files Browse the repository at this point in the history
  • Loading branch information
carolyncole authored Apr 23, 2024
1 parent 18847c1 commit c36b9cd
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/models/work.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
33 changes: 33 additions & 0 deletions spec/models/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions spec/system/authz_submitter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions spec/system/view_data_in_s3_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@

work.save
work.reload
work.state = "awaiting_approval"
work.state = "draft"
work.save

visit work_path(work)
expect(page).to have_content work.title
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
Expand Down
2 changes: 1 addition & 1 deletion spec/system/work_edit_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/system/work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c36b9cd

Please sign in to comment.