curation_concerns 1.7.4 → 1.7.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0264d3ffe1409c035fd9849f11c7ade0dc92c3c1
4
- data.tar.gz: 912f6765b87b3ebe922ccc17ea4689925fe03acb
3
+ metadata.gz: 7cbc4d586d8a888783288ea71618e421913333e2
4
+ data.tar.gz: 4ed7bc09f54922ac00db7d241938468995f898a1
5
5
  SHA512:
6
- metadata.gz: 24a1f4ca059a85819570ea0d2df252ab03e340fccb56e33d342f9af452272d60ac43677adb4b5aa374391fc07b01b36c3b30b060739941bc64c66294937dc2aa
7
- data.tar.gz: a8ecc0679718f7c9f4f9e942c0fd2d97a25564a085e6bf7e5f6c1daf0714348a2ca95627af4218f61ea633dc8f4535ebc01fc83f5e8b05a560fa8fe71515691d
6
+ metadata.gz: 8c4172a085ae5540b7b771e33fb1633939ed428711a0512303ebdf4936d46b26c6dd15ed8bc666260a604078d56c875a9751740fd62173a938766a8550275637
7
+ data.tar.gz: 7260137bd947008030ac1c4786c623f31398903e8cfb7b0f811b3c12ea8a0b4d7018113ddb43656f4cd4d4ea72dcb30ab3ee798e34757dcefdd318c9573ccecd
@@ -13,6 +13,14 @@ module CurationConcerns
13
13
 
14
14
  private
15
15
 
16
+ def ability
17
+ ::Ability.new(user)
18
+ end
19
+
20
+ def can_edit_both_works?(work)
21
+ ability.can?(:edit, work) && ability.can?(:edit, curation_concern)
22
+ end
23
+
16
24
  def add_to_works(new_work_ids)
17
25
  return true if new_work_ids.nil?
18
26
  (curation_concern.in_works_ids - new_work_ids).each do |old_id|
@@ -22,13 +30,17 @@ module CurationConcerns
22
30
  work.save
23
31
  end
24
32
 
25
- # add to new
33
+ # add to new so long as the depositor for the parent and child matches, otherwise inject an error
26
34
  (new_work_ids - curation_concern.in_works_ids).each do |work_id|
27
35
  work = ::ActiveFedora::Base.find(work_id)
28
- work.ordered_members << curation_concern
29
- work.save
36
+ if can_edit_both_works?(work)
37
+ work.ordered_members << curation_concern
38
+ work.save
39
+ else
40
+ curation_concern.errors[:in_works_ids] << "Works can only be related to each other if user has ability to edit both."
41
+ end
30
42
  end
31
- true
43
+ curation_concern.errors[:in_works_ids].empty?
32
44
  end
33
45
  end
34
46
  end
@@ -3,12 +3,19 @@ module CurationConcerns
3
3
  class ApplyOrderActor < AbstractActor
4
4
  def update(attributes)
5
5
  ordered_member_ids = attributes.delete(:ordered_member_ids)
6
- sync_members(ordered_member_ids)
7
- apply_order(ordered_member_ids) && next_actor.update(attributes)
6
+ sync_members(ordered_member_ids) && apply_order(ordered_member_ids) && next_actor.update(attributes)
8
7
  end
9
8
 
10
9
  private
11
10
 
11
+ def ability
12
+ ::Ability.new(user)
13
+ end
14
+
15
+ def can_edit_both_works?(work)
16
+ ability.can?(:edit, work) && ability.can?(:edit, curation_concern)
17
+ end
18
+
12
19
  def sync_members(ordered_member_ids)
13
20
  return true if ordered_member_ids.nil?
14
21
  existing_members_ids = curation_concern.ordered_member_ids
@@ -20,10 +27,14 @@ module CurationConcerns
20
27
 
21
28
  (ordered_member_ids - existing_members_ids).each do |work_id|
22
29
  work = ::ActiveFedora::Base.find(work_id)
23
- curation_concern.ordered_members << work
30
+ if can_edit_both_works?(work)
31
+ curation_concern.ordered_members << work
32
+ curation_concern.save
33
+ else
34
+ curation_concern.errors[:ordered_member_ids] << "Works can only be related to each other if user has ability to edit both."
35
+ end
24
36
  end
25
- curation_concern.save
26
- true
37
+ curation_concern.errors[:ordered_member_ids].empty?
27
38
  end
28
39
 
29
40
  def apply_order(new_order)
@@ -20,7 +20,7 @@ module CurationConcerns
20
20
  private
21
21
 
22
22
  def member_presenter_factory
23
- MemberPresenterFactory.new(work, ability)
23
+ MemberPresenterFactory.new(model, current_ability)
24
24
  end
25
25
  end
26
26
  end
@@ -16,6 +16,10 @@ module CurationConcerns
16
16
  @agent = agent
17
17
  end
18
18
 
19
+ def responsibilities_present?
20
+ @agent.workflow_responsibilities.any?
21
+ end
22
+
19
23
  def responsibilities
20
24
  @agent.workflow_responsibilities.each do |responsibility|
21
25
  yield ResponsibilityPresenter.new(responsibility)
@@ -257,7 +257,10 @@ module CurationConcerns
257
257
  .and(entity_responsibilities[:entity_id].eq(entity.id))
258
258
  )
259
259
 
260
- sub_query_for_user = agent_table.project(agent_table[:proxy_for_id]).where(
260
+ # PostgreSQL requires an explicit cast from string to integer
261
+ cast = Arel::Nodes::NamedFunction.new "CAST", [agent_table[:proxy_for_id].as("integer")]
262
+
263
+ sub_query_for_user = agent_table.project(cast).where(
261
264
  agent_table[:id].in(workflow_agent_id_subquery)
262
265
  .or(agent_table[:id].in(entity_agent_id_subquery))
263
266
  ).where(
@@ -11,7 +11,7 @@
11
11
  <tr>
12
12
  <td><%= user.user_key %></td>
13
13
  <% agent_presenter = @presenter.presenter_for(user) %>
14
- <% if agent_presenter %>
14
+ <% if agent_presenter && agent_presenter.responsibilities_present? %>
15
15
  <td>
16
16
  <ul>
17
17
  <% agent_presenter.responsibilities do |responsibility_presenter| %>
@@ -42,4 +42,3 @@
42
42
  </div>
43
43
  </div>
44
44
  </div>
45
-
@@ -4,6 +4,8 @@
4
4
  <div class="alert alert-danger fade in">
5
5
  <strong>Wait don't go!</strong> There was a problem with your submission. Please review the errors below:
6
6
  <a class="close" data-dismiss="alert" href="#">&times;</a>
7
+ <%= render 'form_in_works_error', f: f %>
8
+ <%= render 'form_ordered_members_error', f: f %>
7
9
  </div>
8
10
  <% end %>
9
11
 
@@ -0,0 +1,3 @@
1
+ <% unless f.object.model.errors[:in_works_ids].empty? %>
2
+ <%= f.full_error(:in_works_ids) %>
3
+ <% end %>
@@ -0,0 +1,3 @@
1
+ <% unless f.object.model.errors[:ordered_member_ids].empty? %>
2
+ <%= f.full_error(:ordered_member_ids) %>
3
+ <% end %>
@@ -1,3 +1,3 @@
1
1
  module CurationConcerns
2
- VERSION = '1.7.4'.freeze
2
+ VERSION = '1.7.5'.freeze
3
3
  end
@@ -78,5 +78,25 @@ describe CurationConcerns::Actors::ApplyOrderActor do
78
78
  expect(curation_concern.ordered_member_ids.size).to eq(1)
79
79
  end
80
80
  end
81
+
82
+ context 'with ordered_member_ids that include a work owned by a different user' do
83
+ # set user not a non-admin for this test to ensure the actor disallows adding the child
84
+ let(:user) { create(:user) }
85
+ let(:other_user) { create(:user) }
86
+ let(:child) { create(:generic_work, user: other_user) }
87
+ let(:attributes) { { ordered_member_ids: [child.id] } }
88
+ let(:root_actor) { double }
89
+
90
+ before do
91
+ allow(CurationConcerns::Actors::RootActor).to receive(:new).and_return(root_actor)
92
+ allow(root_actor).to receive(:update).with({}).and_return(true)
93
+ curation_concern.apply_depositor_metadata(user.user_key)
94
+ curation_concern.save!
95
+ end
96
+
97
+ it "does not attach the work" do
98
+ expect(subject.update(attributes)).to be false
99
+ end
100
+ end
81
101
  end
82
102
  end
@@ -81,7 +81,7 @@ describe CurationConcerns::Actors::GenericWorkActor do
81
81
  end
82
82
 
83
83
  context 'with in_work_ids' do
84
- let(:parent) { FactoryGirl.create(:generic_work) }
84
+ let(:parent) { create(:generic_work, user: user) }
85
85
  let(:attributes) do
86
86
  FactoryGirl.attributes_for(:generic_work, visibility: visibility).merge(
87
87
  in_works_ids: [parent.id]
@@ -91,6 +91,11 @@ describe CurationConcerns::Actors::GenericWorkActor do
91
91
  expect(subject.create(attributes)).to be true
92
92
  expect(curation_concern.in_works).to eq [parent]
93
93
  end
94
+ it "does not attach the parent" do
95
+ allow(curation_concern).to receive(:depositor).and_return("blahblahblah")
96
+ expect(subject.create(attributes)).to be false
97
+ expect(curation_concern.in_works).to eq []
98
+ end
94
99
  end
95
100
 
96
101
  context 'with a file' do
@@ -190,23 +195,20 @@ describe CurationConcerns::Actors::GenericWorkActor do
190
195
  end
191
196
 
192
197
  context 'with in_works_ids' do
193
- let(:parent) { FactoryGirl.create(:generic_work) }
194
- let(:old_parent) { FactoryGirl.create(:generic_work) }
198
+ let(:parent) { create(:generic_work, user: user) }
199
+ let(:old_parent) { create(:generic_work, user: user) }
195
200
  let(:attributes) do
196
201
  FactoryGirl.attributes_for(:generic_work).merge(
197
202
  in_works_ids: [parent.id]
198
203
  )
199
204
  end
200
205
  before do
201
- curation_concern.apply_depositor_metadata(user.user_key)
202
- curation_concern.save!
203
206
  old_parent.ordered_members << curation_concern
204
207
  old_parent.save!
205
208
  end
206
209
  it "attaches the parent" do
207
210
  expect(subject.update(attributes)).to be true
208
211
  expect(curation_concern.in_works).to eq [parent]
209
-
210
212
  expect(old_parent.reload.members).to eq []
211
213
  end
212
214
  end
@@ -224,6 +226,7 @@ describe CurationConcerns::Actors::GenericWorkActor do
224
226
  old_parent.save!
225
227
  end
226
228
  it "removes the old parent" do
229
+ allow(curation_concern).to receive(:depositor).and_return(old_parent.depositor)
227
230
  expect(subject.update(attributes)).to be true
228
231
  expect(curation_concern.in_works).to eq []
229
232
  expect(old_parent.reload.members).to eq []
@@ -6,12 +6,12 @@ feature 'Creating a new child Work', :workflow do
6
6
  let!(:sipity_entity) do
7
7
  create(:sipity_entity, proxy_for_global_id: parent.to_global_id.to_s)
8
8
  end
9
- let(:redlock_client_stub) { # stub out redis connection
9
+ let(:redlock_client_stub) do # stub out redis connection
10
10
  client = double('redlock client')
11
11
  allow(client).to receive(:lock).and_yield(true)
12
12
  allow(Redlock::Client).to receive(:new).and_return(client)
13
13
  client
14
- }
14
+ end
15
15
  let!(:parent) { create(:generic_work, user: user, title: ["Parent First"]) }
16
16
 
17
17
  before do
@@ -64,5 +64,19 @@ feature 'Creating a new child Work', :workflow do
64
64
 
65
65
  expect(curation_concern.reload.in_works_ids.length).to eq 2
66
66
  end
67
+
68
+ context "with a parent that doesn't belong to this user" do
69
+ let(:new_user) { create(:user) }
70
+ let(:new_parent) { create(:generic_work, user: new_user) }
71
+ it "fails to update" do
72
+ visit "/concern/parent/#{parent.id}/generic_works/#{curation_concern.id}/edit"
73
+ first("input#generic_work_in_works_ids", visible: false).set new_parent.id
74
+ first("input#parent_id", visible: false).set new_parent.id
75
+ click_on "Update Generic work"
76
+
77
+ expect(new_parent.reload.ordered_members.to_a.length).to eq 0
78
+ expect(page).to have_content "Works can only be related to each other if user has ability to edit both."
79
+ end
80
+ end
67
81
  end
68
82
  end
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe CurationConcerns::Forms::FileManagerForm do
4
+ let(:work) { create(:work) }
5
+ let(:ability) { instance_double Ability }
6
+ let(:form) { described_class.new(work, ability) }
7
+
8
+ describe "#member_presenters" do
9
+ subject { form.member_presenters }
10
+ let(:factory) { instance_double(CurationConcerns::MemberPresenterFactory, member_presenters: result) }
11
+ let(:result) { double }
12
+ before do
13
+ allow(CurationConcerns::MemberPresenterFactory).to receive(:new).with(work, ability).and_return(factory)
14
+ end
15
+ it "is delegated to the MemberPresenterFactory" do
16
+ expect(subject).to eq result
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'curation_concerns/admin/workflow_roles/index.html.erb', type: :view do
4
+ let!(:user1) { create(:user) }
5
+ let!(:user2) { create(:user) }
6
+ let(:presenter) do
7
+ CurationConcerns::Admin::WorkflowRolePresenter.new
8
+ end
9
+
10
+ before do
11
+ assign(:presenter, presenter)
12
+ allow(view).to receive(:admin_workflow_roles_path).and_return('/admin/workflow_roles')
13
+ end
14
+
15
+ context 'with no users having workflow roles' do
16
+ it 'displays "No Roles" for each user' do
17
+ render
18
+ expect(rendered).to have_content('No roles', count: 2)
19
+ end
20
+ end
21
+
22
+ context 'with some users having workflow roles' do
23
+ before do
24
+ # Force user instances to have corresponding sipity agents
25
+ user1.to_sipity_agent
26
+ user2.to_sipity_agent
27
+ end
28
+ it 'displays roles for each user' do
29
+ render
30
+ expect(rendered.match(/<ul>\s+<\/ul>/m)).to be nil
31
+ end
32
+ end
33
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: curation_concerns
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Zumwalt
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2017-02-07 00:00:00.000000000 Z
13
+ date: 2017-03-02 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: hydra-head
@@ -1134,7 +1134,9 @@ files:
1134
1134
  - app/views/curation_concerns/base/_form_descriptive_fields.html.erb
1135
1135
  - app/views/curation_concerns/base/_form_files_and_links.html.erb
1136
1136
  - app/views/curation_concerns/base/_form_in_works.html.erb
1137
+ - app/views/curation_concerns/base/_form_in_works_error.html.erb
1137
1138
  - app/views/curation_concerns/base/_form_media.html.erb
1139
+ - app/views/curation_concerns/base/_form_ordered_members_error.html.erb
1138
1140
  - app/views/curation_concerns/base/_form_permission.html.erb
1139
1141
  - app/views/curation_concerns/base/_form_permission_embargo.html.erb
1140
1142
  - app/views/curation_concerns/base/_form_permission_lease.html.erb
@@ -1376,6 +1378,7 @@ files:
1376
1378
  - spec/features/work_generator_spec.rb
1377
1379
  - spec/features/workflow_roles_spec.rb
1378
1380
  - spec/forms/collection_edit_form_spec.rb
1381
+ - spec/forms/curation_concerns/forms/file_manager_form_spec.rb
1379
1382
  - spec/forms/curation_concerns/forms/workflow_action_form_spec.rb
1380
1383
  - spec/forms/curation_concerns/forms/workflow_responsibility_form_spec.rb
1381
1384
  - spec/forms/file_set_edit_form_spec.rb
@@ -1548,6 +1551,7 @@ files:
1548
1551
  - spec/views/curation_concerns/admin/_total_objects_charts.html.erb_spec.rb
1549
1552
  - spec/views/curation_concerns/admin/index.html.erb_spec.rb
1550
1553
  - spec/views/curation_concerns/admin/widgets/_pie.html.erb_spec.rb
1554
+ - spec/views/curation_concerns/admin/workflow_roles/index.html.erb_spec.rb
1551
1555
  - spec/views/curation_concerns/base/_attributes.html.erb_spec.rb
1552
1556
  - spec/views/curation_concerns/base/_form.html.erb_spec.rb
1553
1557
  - spec/views/curation_concerns/base/_form_rights_spec.rb
@@ -1597,7 +1601,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
1597
1601
  version: '0'
1598
1602
  requirements: []
1599
1603
  rubyforge_project:
1600
- rubygems_version: 2.6.8
1604
+ rubygems_version: 2.5.1
1601
1605
  signing_key:
1602
1606
  specification_version: 4
1603
1607
  summary: A Rails Engine that allows an application to CRUD CurationConcern objects
@@ -1673,6 +1677,7 @@ test_files:
1673
1677
  - spec/features/work_generator_spec.rb
1674
1678
  - spec/features/workflow_roles_spec.rb
1675
1679
  - spec/forms/collection_edit_form_spec.rb
1680
+ - spec/forms/curation_concerns/forms/file_manager_form_spec.rb
1676
1681
  - spec/forms/curation_concerns/forms/workflow_action_form_spec.rb
1677
1682
  - spec/forms/curation_concerns/forms/workflow_responsibility_form_spec.rb
1678
1683
  - spec/forms/file_set_edit_form_spec.rb
@@ -1845,6 +1850,7 @@ test_files:
1845
1850
  - spec/views/curation_concerns/admin/_total_objects_charts.html.erb_spec.rb
1846
1851
  - spec/views/curation_concerns/admin/index.html.erb_spec.rb
1847
1852
  - spec/views/curation_concerns/admin/widgets/_pie.html.erb_spec.rb
1853
+ - spec/views/curation_concerns/admin/workflow_roles/index.html.erb_spec.rb
1848
1854
  - spec/views/curation_concerns/base/_attributes.html.erb_spec.rb
1849
1855
  - spec/views/curation_concerns/base/_form.html.erb_spec.rb
1850
1856
  - spec/views/curation_concerns/base/_form_rights_spec.rb