hyrax 2.3.3 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +1 -1
  3. data/.github/stale.yml +19 -0
  4. data/README.md +2 -2
  5. data/app/actors/hyrax/actors/apply_permission_template_actor.rb +2 -4
  6. data/app/actors/hyrax/actors/create_with_files_ordered_members_actor.rb +45 -0
  7. data/app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb +96 -0
  8. data/app/actors/hyrax/actors/file_set_ordered_members_actor.rb +16 -0
  9. data/app/actors/hyrax/actors/ordered_members_actor.rb +28 -0
  10. data/app/assets/javascripts/hyrax/collections.js +2 -0
  11. data/app/assets/stylesheets/hyrax/_file-listing.scss +2 -1
  12. data/app/assets/stylesheets/hyrax/_work-show.scss +4 -0
  13. data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +1 -1
  14. data/app/controllers/concerns/hyrax/works_controller_behavior.rb +5 -2
  15. data/app/controllers/hyrax/dashboard/nest_collections_controller.rb +2 -9
  16. data/app/helpers/hyrax/batch_edits_helper.rb +0 -1
  17. data/app/helpers/hyrax/hyrax_helper_behavior.rb +1 -0
  18. data/app/helpers/hyrax/iiif_helper.rb +12 -0
  19. data/app/jobs/attach_files_to_work_with_ordered_members_job.rb +41 -0
  20. data/app/presenters/hyrax/work_show_presenter.rb +29 -2
  21. data/app/services/hyrax/permission_template_applicator.rb +48 -0
  22. data/app/views/hyrax/admin/collection_types/_form_settings.html.erb +1 -1
  23. data/app/views/hyrax/admin/collection_types/index.html.erb +1 -1
  24. data/app/views/hyrax/base/_form_rendering.html.erb +7 -5
  25. data/app/views/hyrax/base/_form_representative.html.erb +4 -2
  26. data/app/views/hyrax/base/_form_thumbnail.html.erb +4 -2
  27. data/app/views/hyrax/base/_member.html.erb +1 -1
  28. data/app/views/hyrax/base/_representative_media.html.erb +1 -4
  29. data/app/views/hyrax/base/_show_actions.html.erb +6 -4
  30. data/app/views/hyrax/base/iiif_viewers/_universal_viewer.html.erb +4 -0
  31. data/app/views/hyrax/base/show.html.erb +2 -2
  32. data/app/views/hyrax/dashboard/works/_default_group.html.erb +1 -1
  33. data/app/views/hyrax/file_sets/_file_set_title.erb +2 -2
  34. data/app/views/hyrax/homepage/_featured.html.erb +0 -3
  35. data/app/views/hyrax/my/_collection_action_menu.html.erb +1 -0
  36. data/app/views/hyrax/my/collections/_default_group.html.erb +1 -9
  37. data/app/views/hyrax/my/collections/_list_collections.html.erb +1 -1
  38. data/app/views/hyrax/users/_activity_log.html.erb +1 -1
  39. data/config/locales/hyrax.de.yml +2 -0
  40. data/config/locales/hyrax.en.yml +2 -0
  41. data/config/locales/hyrax.es.yml +2 -0
  42. data/config/locales/hyrax.fr.yml +2 -0
  43. data/config/locales/hyrax.it.yml +2 -0
  44. data/config/locales/hyrax.pt-BR.yml +2 -0
  45. data/config/locales/hyrax.zh.yml +2 -0
  46. data/hyrax.gemspec +1 -0
  47. data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
  48. data/lib/generators/hyrax/templates/config/locales/hyrax.de.yml +1 -1
  49. data/lib/generators/hyrax/templates/config/locales/hyrax.en.yml +1 -1
  50. data/lib/generators/hyrax/templates/config/locales/hyrax.es.yml +1 -1
  51. data/lib/generators/hyrax/templates/config/locales/hyrax.fr.yml +1 -1
  52. data/lib/generators/hyrax/templates/config/locales/hyrax.it.yml +1 -1
  53. data/lib/generators/hyrax/templates/config/locales/hyrax.zh.yml +1 -1
  54. data/lib/hyrax/configuration.rb +1 -1
  55. data/lib/hyrax/transactions.rb +23 -0
  56. data/lib/hyrax/transactions/container.rb +63 -0
  57. data/lib/hyrax/transactions/create_work.rb +47 -0
  58. data/lib/hyrax/transactions/steps/apply_permission_template.rb +29 -0
  59. data/lib/hyrax/transactions/steps/ensure_admin_set.rb +23 -0
  60. data/lib/hyrax/transactions/steps/ensure_permission_template.rb +27 -0
  61. data/lib/hyrax/transactions/steps/save_work.rb +35 -0
  62. data/lib/hyrax/transactions/steps/set_default_admin_set.rb +25 -0
  63. data/lib/hyrax/transactions/steps/set_modified_date.rb +25 -0
  64. data/lib/hyrax/transactions/steps/set_uploaded_date.rb +28 -0
  65. data/lib/hyrax/version.rb +1 -1
  66. data/spec/actors/hyrax/actors/create_with_files_ordered_members_actor_spec.rb +41 -0
  67. data/spec/actors/hyrax/actors/create_with_remote_files_ordered_members_actor_spec.rb +49 -0
  68. data/spec/actors/hyrax/actors/file_set_ordered_members_actor_spec.rb +35 -0
  69. data/spec/actors/hyrax/actors/ordered_members_actor_spec.rb +59 -0
  70. data/spec/controllers/hyrax/embargoes_controller_spec.rb +2 -0
  71. data/spec/controllers/hyrax/generic_works_controller_spec.rb +6 -1
  72. data/spec/factories/generic_works.rb +6 -0
  73. data/spec/features/collection_multi_membership_spec.rb +6 -6
  74. data/spec/features/work_show_spec.rb +58 -5
  75. data/spec/helpers/hyrax/batch_edits_helper_spec.rb +4 -2
  76. data/spec/helpers/hyrax/iiif_helper_spec.rb +44 -0
  77. data/spec/hyrax/transactions/create_work_spec.rb +155 -0
  78. data/spec/hyrax/transactions/steps/apply_permission_template_spec.rb +72 -0
  79. data/spec/hyrax/transactions/steps/ensure_admin_set_spec.rb +25 -0
  80. data/spec/hyrax/transactions/steps/ensure_permission_template_spec.rb +33 -0
  81. data/spec/hyrax/transactions/steps/save_work_spec.rb +32 -0
  82. data/spec/hyrax/transactions/steps/set_default_admin_set_spec.rb +38 -0
  83. data/spec/hyrax/transactions/steps/set_modified_date_spec.rb +22 -0
  84. data/spec/hyrax/transactions/steps/set_uploaded_date_spec.rb +32 -0
  85. data/spec/jobs/attach_files_to_work_with_ordered_members_job_spec.rb +13 -0
  86. data/spec/presenters/hyrax/presenter_renderer_spec.rb +4 -2
  87. data/spec/presenters/hyrax/work_show_presenter_spec.rb +46 -2
  88. data/spec/services/hyrax/permission_template_applicator_spec.rb +69 -0
  89. data/spec/spec_helper.rb +13 -2
  90. data/spec/views/catalog/index.html.erb_spec.rb +7 -4
  91. data/spec/views/hyrax/admin/admin_sets/_show_actions.html.erb_spec.rb +2 -0
  92. data/spec/views/hyrax/admin/admin_sets/_show_document_list_row.html.erb_spec.rb +4 -1
  93. data/spec/views/hyrax/admin/admin_sets/index.html.erb_spec.rb +6 -2
  94. data/spec/views/hyrax/admin/admin_sets/index.json.erb_spec.rb +1 -2
  95. data/spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb +1 -1
  96. data/spec/views/hyrax/admin/collection_types/_form_settings.html.erb_spec.rb +5 -26
  97. data/spec/views/hyrax/admin/collection_types/index.html.erb_spec.rb +26 -5
  98. data/spec/views/hyrax/admin/stats/show.html.erb_spec.rb +1 -0
  99. data/spec/views/hyrax/base/_attribute_rows.html.erb_spec.rb +5 -1
  100. data/spec/views/hyrax/base/_attributes.html.erb_spec.rb +1 -0
  101. data/spec/views/hyrax/base/_form_rendering.html.erb_spec.rb +5 -1
  102. data/spec/views/hyrax/base/_items.html.erb_spec.rb +2 -0
  103. data/spec/views/hyrax/base/_relationships.html.erb_spec.rb +2 -1
  104. data/spec/views/hyrax/base/_show_actions.html.erb_spec.rb +71 -0
  105. data/spec/views/hyrax/base/file_manager.html.erb_spec.rb +11 -14
  106. data/spec/views/hyrax/base/show.html.erb_spec.rb +2 -2
  107. data/spec/views/hyrax/base/show.json.jbuilder_spec.rb +3 -1
  108. data/spec/views/hyrax/collections/_show_document_list_row.html.erb_spec.rb +6 -1
  109. data/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb +5 -5
  110. data/spec/views/hyrax/collections/_subcollection_list.html.erb_spec.rb +1 -1
  111. data/spec/views/hyrax/collections/show.html.erb_spec.rb +3 -2
  112. data/spec/views/hyrax/dashboard/collections/_form_share.erb_spec.rb +1 -1
  113. data/spec/views/hyrax/dashboard/collections/_form_share_table.html.erb_spec.rb +1 -1
  114. data/spec/views/hyrax/dashboard/collections/_show_document_list_row.html.erb_spec.rb +6 -1
  115. data/spec/views/hyrax/dashboard/collections/_subcollection_list.html.erb_spec.rb +1 -1
  116. data/spec/views/hyrax/dashboard/collections/edit.html.erb_spec.rb +3 -1
  117. data/spec/views/hyrax/dashboard/profiles/show.html.erb_spec.rb +2 -3
  118. data/spec/views/hyrax/file_sets/_show_characterization_details.html.erb_spec.rb +1 -2
  119. data/spec/views/hyrax/file_sets/_single_use_links.html.erb_spec.rb +1 -2
  120. data/spec/views/hyrax/homepage/_sortable_featured.html.erb_spec.rb +1 -1
  121. data/spec/views/hyrax/my/_collection_action_menu.html.erb_spec.rb +5 -5
  122. data/spec/views/hyrax/my/collections/_list_collections.html.erb_spec.rb +11 -8
  123. data/spec/views/hyrax/users/index.html.erb_spec.rb +1 -0
  124. data/spec/views/hyrax/users/show.html.erb_spec.rb +3 -0
  125. data/template.rb +1 -1
  126. metadata +65 -3
  127. data/app/views/hyrax/dashboard/collections/_form_default_group_delt.html.erb +0 -27
@@ -609,9 +609,14 @@ RSpec.describe Hyrax::GenericWorksController do
609
609
  .and_return(manifest_factory)
610
610
  end
611
611
 
612
- it "produces a manifest" do
612
+ it "produces a manifest for a json request" do
613
613
  get :manifest, params: { id: work, format: :json }
614
614
  expect(response.body).to eq "{\"test\":\"manifest\"}"
615
615
  end
616
+
617
+ it "produces a manifest for a html request" do
618
+ get :manifest, params: { id: work, format: :html }
619
+ expect(response.body).to eq "{\"test\":\"manifest\"}"
620
+ end
616
621
  end
617
622
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  FactoryBot.define do
2
4
  factory :work, aliases: [:generic_work, :private_generic_work], class: GenericWork do
3
5
  transient do
@@ -34,6 +36,10 @@ FactoryBot.define do
34
36
  visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
35
37
  end
36
38
 
39
+ factory :invalid_generic_work do
40
+ title { nil }
41
+ end
42
+
37
43
  factory :private_work do
38
44
  # private is default
39
45
  # visibility { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE }
@@ -18,7 +18,7 @@ RSpec.describe 'Adding a work to multiple collections', type: :feature, clean_re
18
18
  let!(:new_collection) { create(:collection_lw, user: admin_user, collection_type_gid: multi_membership_type_2.gid, title: ['NewCollectionTitle']) }
19
19
 
20
20
  it 'then the work is added to both collections' do
21
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
21
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
22
22
  # Add to second multi-membership collection of a different type
23
23
  visit '/dashboard/my/works'
24
24
  check 'check_all'
@@ -38,7 +38,7 @@ RSpec.describe 'Adding a work to multiple collections', type: :feature, clean_re
38
38
  let!(:new_collection) { create(:collection_lw, user: admin_user, collection_type_gid: multi_membership_type_1.gid, title: ['NewCollectionTitle']) }
39
39
 
40
40
  it 'then the work is added to both collections' do
41
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
41
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
42
42
  # Add to second multi-membership collection of a different type
43
43
  visit '/dashboard/my/works'
44
44
  check 'check_all'
@@ -70,7 +70,7 @@ RSpec.describe 'Adding a work to multiple collections', type: :feature, clean_re
70
70
  let!(:new_collection) { create(:collection_lw, user: admin_user, collection_type_gid: single_membership_type_2.gid, title: ['NewCollectionTitle']) }
71
71
 
72
72
  it 'then the work is added to both collections' do
73
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
73
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
74
74
  # Add to second single-membership collection of a different type
75
75
  visit '/dashboard/my/works'
76
76
  check 'check_all'
@@ -91,7 +91,7 @@ RSpec.describe 'Adding a work to multiple collections', type: :feature, clean_re
91
91
 
92
92
  context 'then the work fails to add to the second collection' do
93
93
  it 'from the dashboard->works batch add to collection' do
94
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
94
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
95
95
  # Attempt to add to second single-membership collection of the same type
96
96
  visit '/dashboard/my/works'
97
97
  check 'check_all'
@@ -165,7 +165,7 @@ RSpec.describe 'Adding a work to multiple collections', type: :feature, clean_re
165
165
  let!(:new_collection) { old_collection }
166
166
 
167
167
  it 'then the add is treated as a success' do
168
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
168
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
169
169
  # Re-add to same multi-membership collection
170
170
  visit '/dashboard/my/works'
171
171
  check 'check_all'
@@ -186,7 +186,7 @@ RSpec.describe 'Adding a work to multiple collections', type: :feature, clean_re
186
186
  let!(:new_collection) { old_collection }
187
187
 
188
188
  it 'then the add is treated as a success' do
189
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
189
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
190
190
  # Re-add to same single-membership collection
191
191
  visit '/dashboard/my/works'
192
192
  check 'check_all'
@@ -1,4 +1,4 @@
1
- RSpec.describe "display a work as its owner" do
1
+ RSpec.describe "work show view" do
2
2
  include Selectors::Dashboard
3
3
 
4
4
  let(:work_path) { "/concern/generic_works/#{work.id}" }
@@ -29,13 +29,17 @@ RSpec.describe "display a work as its owner" do
29
29
  visit work_path
30
30
  end
31
31
 
32
- it "shows a work" do
32
+ it "shows work content and all editor buttons and links" do
33
33
  expect(page).to have_selector 'h2', text: 'Magnificent splendor'
34
34
  expect(page).to have_selector 'h2', text: 'Happy little trees'
35
35
  expect(page).to have_selector 'li', text: 'The Internet'
36
36
  expect(page).to have_selector 'dt', text: 'Location'
37
37
  expect(page).not_to have_selector 'dt', text: 'Based near'
38
38
  expect(page).to have_selector 'button', text: 'Attach Child', count: 1
39
+ expect(page).to have_link 'Analytics'
40
+ expect(page).to have_link 'Edit'
41
+ expect(page).to have_link 'Delete'
42
+ expect(page).to have_selector 'button', text: 'Add to collection', count: 1
39
43
 
40
44
  # Displays FileSets already attached to this work
41
45
  within '.related-files' do
@@ -43,11 +47,60 @@ RSpec.describe "display a work as its owner" do
43
47
  end
44
48
 
45
49
  # IIIF manifest does not include locale query param
46
- expect(find('div.viewer:first')['data-uri']).to eq "/concern/generic_works/#{work.id}/manifest"
50
+ expect(find('div.viewer:first')['data-uri']).to eq "http://www.example.com/concern/generic_works/#{work.id}/manifest"
51
+ end
52
+
53
+ it "allows adding work to a collection", clean_repo: true, js: true do
54
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
55
+ click_button "Add to collection" # opens the modal
56
+ select_member_of_collection(collection)
57
+ click_button 'Save changes'
58
+
59
+ # forwards to collection show page
60
+ expect(page).to have_content collection.title.first
61
+ expect(page).to have_content work.title.first
62
+ expect(page).to have_selector '.alert-success', text: 'Collection was successfully updated.'
63
+ end
64
+ end
65
+
66
+ context "as the work viewer" do
67
+ let(:work) do
68
+ create(:public_work,
69
+ with_admin_set: true,
70
+ title: ["Magnificent splendor", "Happy little trees"],
71
+ source: ["The Internet"],
72
+ based_near: ["USA"],
73
+ user: user,
74
+ ordered_members: [file_set],
75
+ representative_id: file_set.id)
76
+ end
77
+ let(:user) { create(:user) }
78
+ let(:viewer) { create(:user) }
79
+ let(:file_set) { create(:file_set, user: user, title: ['A Contained FileSet'], content: file) }
80
+ let(:file) { File.open(fixture_path + '/world.png') }
81
+ let(:multi_membership_type_1) { create(:collection_type, :allow_multiple_membership, title: 'Multi-membership 1') }
82
+ let!(:collection) { create(:collection_lw, user: viewer, collection_type_gid: multi_membership_type_1.gid) }
83
+
84
+ before do
85
+ sign_in viewer
86
+ visit work_path
87
+ end
88
+
89
+ it "shows work content and only Analytics and Add to collection buttons" do
90
+ expect(page).to have_selector 'h2', text: 'Magnificent splendor'
91
+ expect(page).to have_selector 'h2', text: 'Happy little trees'
92
+ expect(page).to have_selector 'li', text: 'The Internet'
93
+ expect(page).to have_selector 'dt', text: 'Location'
94
+ expect(page).not_to have_selector 'dt', text: 'Based near'
95
+ expect(page).not_to have_selector 'button', text: 'Attach Child', count: 1
96
+ expect(page).to have_link 'Analytics'
97
+ expect(page).not_to have_link 'Edit'
98
+ expect(page).not_to have_link 'Delete'
99
+ expect(page).to have_selector 'button', text: 'Add to collection', count: 1
47
100
  end
48
101
 
49
- it "add work to a collection", clean_repo: true, js: true do
50
- optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ENV['TRAVIS']
102
+ it "allows adding work to a collection", clean_repo: true, js: true do
103
+ optional 'ability to get capybara to find css select2-result (see Issue #3038)' if ci_build?
51
104
  click_button "Add to collection" # opens the modal
52
105
  select_member_of_collection(collection)
53
106
  click_button 'Save changes'
@@ -40,8 +40,10 @@ RSpec.describe Hyrax::BatchEditsHelper, type: :helper do
40
40
  context "with my collections" do
41
41
  let(:controller_path) { "hyrax/my/collections" }
42
42
 
43
- it "does not show the check all dropdown" do
44
- expect(subject).to be_nil
43
+ it "show the check all dropdown" do
44
+ expect(subject).to have_css("span.caret")
45
+ expect(subject).to have_content t("hyrax.dashboard.my.action.select_all")
46
+ expect(subject).to have_content t("hyrax.dashboard.my.action.select_none")
45
47
  end
46
48
  end
47
49
 
@@ -0,0 +1,44 @@
1
+ RSpec.describe Hyrax::IiifHelper, type: :helper do
2
+ let(:solr_document) { SolrDocument.new }
3
+ let(:request) { double }
4
+ let(:ability) { nil }
5
+ let(:presenter) { Hyrax::WorkShowPresenter.new(solr_document, ability, request) }
6
+ let(:uv_partial_path) { 'hyrax/base/iiif_viewers/universal_viewer' }
7
+
8
+ describe '#iiif_viewer_display' do
9
+ before do
10
+ allow(helper).to receive(:iiif_viewer_display_partial).with(presenter)
11
+ .and_return(uv_partial_path)
12
+ end
13
+
14
+ it "renders a partial" do
15
+ expect(helper).to receive(:render)
16
+ .with(uv_partial_path, presenter: presenter)
17
+ helper.iiif_viewer_display(presenter)
18
+ end
19
+
20
+ it "takes options" do
21
+ expect(helper).to receive(:render)
22
+ .with(uv_partial_path, presenter: presenter, transcript_id: '123')
23
+ helper.iiif_viewer_display(presenter, transcript_id: '123')
24
+ end
25
+ end
26
+
27
+ describe '#iiif_viewer_display_partial' do
28
+ subject { helper.iiif_viewer_display_partial(presenter) }
29
+
30
+ it 'defaults to universal viewer' do
31
+ expect(subject).to eq uv_partial_path
32
+ end
33
+
34
+ context "with #iiif_viewer override" do
35
+ let(:iiif_viewer) { :mirador }
36
+
37
+ before do
38
+ allow(presenter).to receive(:iiif_viewer).and_return(iiif_viewer)
39
+ end
40
+
41
+ it { is_expected.to eq 'hyrax/base/iiif_viewers/mirador' }
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,155 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require 'hyrax/transactions'
4
+
5
+ RSpec.describe Hyrax::Transactions::CreateWork do
6
+ subject(:transaction) { described_class.new }
7
+ let(:template) { Hyrax::PermissionTemplate.find_by!(source_id: work.admin_set_id) }
8
+ let(:work) { build(:generic_work) }
9
+ let(:xmas) { DateTime.parse('2018-12-25 11:30').iso8601 }
10
+
11
+ before do
12
+ Hyrax::PermissionTemplate
13
+ .find_or_create_by(source_id: AdminSet.find_or_create_default_admin_set_id)
14
+ end
15
+
16
+ describe '#call' do
17
+ context 'with an invalid work' do
18
+ let(:work) { build(:invalid_generic_work) }
19
+
20
+ it 'is a failure' do
21
+ expect(transaction.call(work)).to be_failure
22
+ end
23
+
24
+ it 'does not save the work' do
25
+ expect { transaction.call(work) }.not_to change { work.new_record? }.from true
26
+ end
27
+
28
+ it 'gives useful errors' do
29
+ expect(transaction.call(work).failure).to eq work.errors
30
+ end
31
+ end
32
+
33
+ it 'is a success' do
34
+ expect(transaction.call(work)).to be_success
35
+ end
36
+
37
+ it 'persists the work' do
38
+ expect { transaction.call(work) }
39
+ .to change { work.persisted? }
40
+ .to true
41
+ end
42
+
43
+ it 'sets visibility to restricted by default' do
44
+ expect { transaction.call(work) }
45
+ .not_to change { work.visibility }
46
+ .from Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
47
+ end
48
+
49
+ it 'sets the default admin set' do
50
+ expect { transaction.call(work) }
51
+ .to change { work.admin_set&.id }
52
+ .to AdminSet.find_or_create_default_admin_set_id
53
+ end
54
+
55
+ it 'sets the modified time using Hyrax::TimeService' do
56
+ allow(Hyrax::TimeService).to receive(:time_in_utc).and_return(xmas)
57
+
58
+ expect { transaction.call(work) }.to change { work.date_modified }.to xmas
59
+ end
60
+
61
+ it 'sets the created time using Hyrax::TimeService' do
62
+ allow(Hyrax::TimeService).to receive(:time_in_utc).and_return(xmas)
63
+
64
+ expect { transaction.call(work) }.to change { work.date_uploaded }.to xmas
65
+ end
66
+
67
+ it 'grants edit permission to depositor' do
68
+ transaction.call(work)
69
+
70
+ expect(work.edit_users).to include work.depositor
71
+ end
72
+ end
73
+
74
+ context 'when visibility is set' do
75
+ let(:visibility) { Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC }
76
+
77
+ before { work.visibility = visibility }
78
+
79
+ it 'keeps the visibility' do
80
+ expect { transaction.call(work) }
81
+ .not_to change { work.visibility }
82
+ .from visibility
83
+ end
84
+ end
85
+
86
+ context 'with an admin set' do
87
+ let(:admin_set) { AdminSet.find(template.source_id) }
88
+ let(:template) { create(:permission_template, with_admin_set: true) }
89
+ let(:work) { build(:generic_work, admin_set: admin_set) }
90
+
91
+ context 'without a permission template' do
92
+ let(:admin_set) { create(:admin_set, with_permission_template: false) }
93
+
94
+ it 'is a failure' do
95
+ expect(transaction.call(work)).to be_failure
96
+ end
97
+
98
+ it 'is does not persist the work' do
99
+ expect { transaction.call(work) }
100
+ .not_to change { work.persisted? }
101
+ .from false
102
+ end
103
+ end
104
+
105
+ it 'is a success' do
106
+ expect(transaction.call(work)).to be_success
107
+ end
108
+
109
+ it 'retains the set admin set' do
110
+ expect { transaction.call(work) }
111
+ .not_to change { work.admin_set&.id }
112
+ .from admin_set.id
113
+ end
114
+
115
+ context 'with users and groups' do
116
+ let(:manage_groups) { ['manage_group_1', 'manage_group_2'] }
117
+ let(:manage_users) { create_list(:user, 2) }
118
+ let(:view_groups) { ['view_group_1', 'view_group_2'] }
119
+ let(:view_users) { create_list(:user, 2) }
120
+
121
+ let(:template) do
122
+ create(:permission_template,
123
+ with_admin_set: true,
124
+ manage_groups: manage_groups,
125
+ manage_users: manage_users,
126
+ view_groups: view_groups,
127
+ view_users: view_users)
128
+ end
129
+
130
+ it 'assigns edit groups from template' do
131
+ expect { transaction.call(work) }
132
+ .to change { work.edit_groups }
133
+ .to include(*manage_groups)
134
+ end
135
+
136
+ it 'assigns edit users from template' do
137
+ expect { transaction.call(work) }
138
+ .to change { work.edit_users }
139
+ .to include(*manage_users.map(&:user_key))
140
+ end
141
+
142
+ it 'assigns read groups from template' do
143
+ expect { transaction.call(work) }
144
+ .to change { work.read_groups }
145
+ .to include(*view_groups)
146
+ end
147
+
148
+ it 'assigns read users from template' do
149
+ expect { transaction.call(work) }
150
+ .to change { work.read_users }
151
+ .to include(*view_users.map(&:user_key))
152
+ end
153
+ end
154
+ end
155
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+ require 'spec_helper'
3
+ require 'hyrax/transactions'
4
+
5
+ RSpec.describe Hyrax::Transactions::Steps::ApplyPermissionTemplate do
6
+ subject(:step) { described_class.new }
7
+ let(:work) { build(:generic_work) }
8
+
9
+ context 'without an admin_set' do
10
+ it 'is a failure' do
11
+ expect(step.call(work)).to be_failure
12
+ end
13
+ end
14
+
15
+ context 'with an admin_set' do
16
+ let(:work) { build(:generic_work, admin_set: admin_set) }
17
+ let(:admin_set) { create(:admin_set, with_permission_template: true) }
18
+
19
+ it 'is a success' do
20
+ expect(step.call(work)).to be_success
21
+ end
22
+
23
+ context 'with users and groups' do
24
+ let(:admin_set) { AdminSet.find(template.source_id) }
25
+ let(:manage_groups) { ['edit_group_1', 'edit_group_2'] }
26
+ let(:manage_users) { create_list(:user, 2) }
27
+ let(:view_groups) { ['read_group_1', 'read_group_2'] }
28
+ let(:view_users) { create_list(:user, 2) }
29
+
30
+ let(:template) do
31
+ create(:permission_template,
32
+ with_admin_set: true,
33
+ manage_groups: manage_groups,
34
+ manage_users: manage_users,
35
+ view_groups: view_groups,
36
+ view_users: view_users)
37
+ end
38
+
39
+ it 'assigns edit users from template' do
40
+ expect { step.call(work) }
41
+ .to change { work.edit_users }
42
+ .to include(*manage_users.map(&:user_key))
43
+ end
44
+
45
+ it 'assigns edit groups from template' do
46
+ expect { step.call(work) }
47
+ .to change { work.edit_groups }
48
+ .to include(*manage_groups)
49
+ end
50
+
51
+ it 'assigns read users from template' do
52
+ expect { step.call(work) }
53
+ .to change { work.read_users }
54
+ .to include(*view_users.map(&:user_key))
55
+ end
56
+
57
+ it 'assigns read groups from template' do
58
+ expect { step.call(work) }
59
+ .to change { work.read_groups }
60
+ .to include(*view_groups)
61
+ end
62
+ end
63
+
64
+ context 'missing PermissionTemplate' do
65
+ let(:admin_set) { create(:admin_set, with_permission_template: false) }
66
+
67
+ it 'is a failure' do
68
+ expect(step.call(work)).to be_failure
69
+ end
70
+ end
71
+ end
72
+ end