Skip to content

Commit

Permalink
Ensuring the submitters can edit approved Works
Browse files Browse the repository at this point in the history
  • Loading branch information
jrgriffiniii committed Jan 18, 2023
1 parent d896c22 commit 1925d1f
Show file tree
Hide file tree
Showing 2 changed files with 93 additions and 2 deletions.
2 changes: 0 additions & 2 deletions app/controllers/works_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ def update
if current_user.blank? || !@work.editable_by?(current_user)
Rails.logger.warn("Unauthorized attempt to update work #{@work.id} by user #{current_user.uid}")
redirect_to root_path
elsif @work.approved? && @work.submitted_by?(current_user)
redirect_to root_path, notice: I18n.t("works.approved.uneditable")
else
update_work
end
Expand Down
93 changes: 93 additions & 0 deletions spec/requests/works_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,99 @@
expect { get work_url(work) }.to raise_error(Work::InvalidCollectionError, "The Work test-id does not belong to any Collection")
end
end

context "when the work has been approved" do
let(:work) { FactoryBot.create(:approved_work) }
let(:collection) { work.collection }

context "when appending a second title" do
let(:params) do
{
id: work.id,
title_main: work.title,
collection_id: collection.id,
new_title_1: "the subtitle",
new_title_type_1: "Subtitle",
existing_title_count: "1",
new_title_count: "1",
given_name_1: "Toni",
family_name_1: "Morrison",
sequence_1: "1",
given_name_2: "Sonia",
family_name_2: "Sotomayor",
sequence_2: "1",
orcid_2: "1234-1234-1234-1234",
creator_count: "1",
new_creator_count: "1",
rights_identifier: "CC BY",
description: "a new description"
}
end

before do
patch work_url(work), params: params
end

context "when authenticated as a super admin user" do
let(:user) { FactoryBot.create(:super_admin_user) }

it "updates the title" do
expect(response.status).to eq(302)
work.reload

expect(work.metadata).to be_a(Hash)
expect(work.metadata).to include("titles")
titles = work.metadata["titles"]
expect(titles.length).to eq(2)

subtitle = titles.last
expect(subtitle).to be_a(Hash)
expect(subtitle).to include("title" => "the subtitle")
expect(subtitle).to include("title_type" => "Subtitle")
end
end

context "when authenticated as the submitter of the Work" do
let(:user) { work.created_by_user }

it "updates the title" do
expect(response.status).to eq(302)
work.reload

expect(work.metadata).to be_a(Hash)
expect(work.metadata).to include("titles")
titles = work.metadata["titles"]
expect(titles.length).to eq(2)

subtitle = titles.last
expect(subtitle).to be_a(Hash)
expect(subtitle).to include("title" => "the subtitle")
expect(subtitle).to include("title_type" => "Subtitle")
end
end

context "when authenticated as the curator for the Work" do
let(:user) do
FactoryBot.create :user, collections_to_admin: [collection]
end

it "updates the title" do
expect(response.status).to eq(302)
work.reload

expect(work.metadata).to be_a(Hash)
expect(work.metadata).to include("titles")
titles = work.metadata["titles"]
expect(titles.length).to eq(2)

subtitle = titles.last
expect(subtitle).to be_a(Hash)
expect(subtitle).to include("title" => "the subtitle")
expect(subtitle).to include("title_type" => "Subtitle")
end
end
end
end
end
end
end

0 comments on commit 1925d1f

Please sign in to comment.