Skip to content

Commit

Permalink
Merge pull request #1155 from projecthydra/depositor-authority-1_7
Browse files Browse the repository at this point in the history
prevents child relationship when parent is owned by a different depositor
  • Loading branch information
revgum committed Feb 27, 2017
2 parents 1bbdab6 + a2e941d commit e6dbe04
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/actors/curation_concerns/actors/add_to_work_actor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,17 @@ def add_to_works(new_work_ids)
work.save
end

# add to new
# add to new so long as the depositor for the parent and child matches, otherwise inject an error
(new_work_ids - curation_concern.in_works_ids).each do |work_id|
work = ::ActiveFedora::Base.find(work_id)
work.ordered_members << curation_concern
work.save
if work.depositor != curation_concern.depositor
curation_concern.errors[:in_works_ids] << "Works can only be related to each other if they were deposited by the same user."
else
work.ordered_members << curation_concern
work.save
end
end
true
curation_concern.errors[:in_works_ids].empty?
end
end
end
Expand Down
1 change: 1 addition & 0 deletions app/views/curation_concerns/base/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<div class="alert alert-danger fade in">
<strong>Wait don't go!</strong> There was a problem with your submission. Please review the errors below:
<a class="close" data-dismiss="alert" href="#">&times;</a>
<%= render 'form_in_works_error', f: f %>
</div>
<% end %>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<% unless f.object.model.errors[:in_works_ids].empty? %>
<%= f.full_error(:in_works_ids) %>
<% end %>
8 changes: 8 additions & 0 deletions spec/actors/curation_concerns/work_actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,15 @@
)
end
it "attaches the parent" do
allow(curation_concern).to receive(:depositor).and_return(parent.depositor)
expect(subject.create(attributes)).to be true
expect(curation_concern.in_works).to eq [parent]
end
it "does not attach the parent" do
allow(curation_concern).to receive(:depositor).and_return("blahblahblah")
expect(subject.create(attributes)).to be false
expect(curation_concern.in_works).to eq []
end
end

context 'with a file' do
Expand Down Expand Up @@ -204,6 +210,7 @@
old_parent.save!
end
it "attaches the parent" do
allow(curation_concern).to receive(:depositor).and_return(parent.depositor)
expect(subject.update(attributes)).to be true
expect(curation_concern.in_works).to eq [parent]

Expand All @@ -224,6 +231,7 @@
old_parent.save!
end
it "removes the old parent" do
allow(curation_concern).to receive(:depositor).and_return(old_parent.depositor)
expect(subject.update(attributes)).to be true
expect(curation_concern.in_works).to eq []
expect(old_parent.reload.members).to eq []
Expand Down
14 changes: 14 additions & 0 deletions spec/features/create_child_work_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,5 +64,19 @@

expect(curation_concern.reload.in_works_ids.length).to eq 2
end

context "with a parent that doesn't belong to this user" do
let(:new_user) { create(:user) }
let(:new_parent) { create(:generic_work, user: new_user) }
it "fails to update" do
visit "/concern/parent/#{parent.id}/generic_works/#{curation_concern.id}/edit"
first("input#generic_work_in_works_ids", visible: false).set new_parent.id
first("input#parent_id", visible: false).set new_parent.id
click_on "Update Generic work"

expect(new_parent.reload.ordered_members.to_a.length).to eq 0
expect(page).to have_content "Works can only be related to each other if they were deposited by the same user."
end
end
end
end

0 comments on commit e6dbe04

Please sign in to comment.