hyrax 2.3.3 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +1 -1
- data/.github/stale.yml +19 -0
- data/README.md +2 -2
- data/app/actors/hyrax/actors/apply_permission_template_actor.rb +2 -4
- data/app/actors/hyrax/actors/create_with_files_ordered_members_actor.rb +45 -0
- data/app/actors/hyrax/actors/create_with_remote_files_ordered_members_actor.rb +96 -0
- data/app/actors/hyrax/actors/file_set_ordered_members_actor.rb +16 -0
- data/app/actors/hyrax/actors/ordered_members_actor.rb +28 -0
- data/app/assets/javascripts/hyrax/collections.js +2 -0
- data/app/assets/stylesheets/hyrax/_file-listing.scss +2 -1
- data/app/assets/stylesheets/hyrax/_work-show.scss +4 -0
- data/app/controllers/concerns/hyrax/embargoes_controller_behavior.rb +1 -1
- data/app/controllers/concerns/hyrax/works_controller_behavior.rb +5 -2
- data/app/controllers/hyrax/dashboard/nest_collections_controller.rb +2 -9
- data/app/helpers/hyrax/batch_edits_helper.rb +0 -1
- data/app/helpers/hyrax/hyrax_helper_behavior.rb +1 -0
- data/app/helpers/hyrax/iiif_helper.rb +12 -0
- data/app/jobs/attach_files_to_work_with_ordered_members_job.rb +41 -0
- data/app/presenters/hyrax/work_show_presenter.rb +29 -2
- data/app/services/hyrax/permission_template_applicator.rb +48 -0
- data/app/views/hyrax/admin/collection_types/_form_settings.html.erb +1 -1
- data/app/views/hyrax/admin/collection_types/index.html.erb +1 -1
- data/app/views/hyrax/base/_form_rendering.html.erb +7 -5
- data/app/views/hyrax/base/_form_representative.html.erb +4 -2
- data/app/views/hyrax/base/_form_thumbnail.html.erb +4 -2
- data/app/views/hyrax/base/_member.html.erb +1 -1
- data/app/views/hyrax/base/_representative_media.html.erb +1 -4
- data/app/views/hyrax/base/_show_actions.html.erb +6 -4
- data/app/views/hyrax/base/iiif_viewers/_universal_viewer.html.erb +4 -0
- data/app/views/hyrax/base/show.html.erb +2 -2
- data/app/views/hyrax/dashboard/works/_default_group.html.erb +1 -1
- data/app/views/hyrax/file_sets/_file_set_title.erb +2 -2
- data/app/views/hyrax/homepage/_featured.html.erb +0 -3
- data/app/views/hyrax/my/_collection_action_menu.html.erb +1 -0
- data/app/views/hyrax/my/collections/_default_group.html.erb +1 -9
- data/app/views/hyrax/my/collections/_list_collections.html.erb +1 -1
- data/app/views/hyrax/users/_activity_log.html.erb +1 -1
- data/config/locales/hyrax.de.yml +2 -0
- data/config/locales/hyrax.en.yml +2 -0
- data/config/locales/hyrax.es.yml +2 -0
- data/config/locales/hyrax.fr.yml +2 -0
- data/config/locales/hyrax.it.yml +2 -0
- data/config/locales/hyrax.pt-BR.yml +2 -0
- data/config/locales/hyrax.zh.yml +2 -0
- data/hyrax.gemspec +1 -0
- data/lib/generators/hyrax/templates/config/initializers/hyrax.rb +1 -1
- data/lib/generators/hyrax/templates/config/locales/hyrax.de.yml +1 -1
- data/lib/generators/hyrax/templates/config/locales/hyrax.en.yml +1 -1
- data/lib/generators/hyrax/templates/config/locales/hyrax.es.yml +1 -1
- data/lib/generators/hyrax/templates/config/locales/hyrax.fr.yml +1 -1
- data/lib/generators/hyrax/templates/config/locales/hyrax.it.yml +1 -1
- data/lib/generators/hyrax/templates/config/locales/hyrax.zh.yml +1 -1
- data/lib/hyrax/configuration.rb +1 -1
- data/lib/hyrax/transactions.rb +23 -0
- data/lib/hyrax/transactions/container.rb +63 -0
- data/lib/hyrax/transactions/create_work.rb +47 -0
- data/lib/hyrax/transactions/steps/apply_permission_template.rb +29 -0
- data/lib/hyrax/transactions/steps/ensure_admin_set.rb +23 -0
- data/lib/hyrax/transactions/steps/ensure_permission_template.rb +27 -0
- data/lib/hyrax/transactions/steps/save_work.rb +35 -0
- data/lib/hyrax/transactions/steps/set_default_admin_set.rb +25 -0
- data/lib/hyrax/transactions/steps/set_modified_date.rb +25 -0
- data/lib/hyrax/transactions/steps/set_uploaded_date.rb +28 -0
- data/lib/hyrax/version.rb +1 -1
- data/spec/actors/hyrax/actors/create_with_files_ordered_members_actor_spec.rb +41 -0
- data/spec/actors/hyrax/actors/create_with_remote_files_ordered_members_actor_spec.rb +49 -0
- data/spec/actors/hyrax/actors/file_set_ordered_members_actor_spec.rb +35 -0
- data/spec/actors/hyrax/actors/ordered_members_actor_spec.rb +59 -0
- data/spec/controllers/hyrax/embargoes_controller_spec.rb +2 -0
- data/spec/controllers/hyrax/generic_works_controller_spec.rb +6 -1
- data/spec/factories/generic_works.rb +6 -0
- data/spec/features/collection_multi_membership_spec.rb +6 -6
- data/spec/features/work_show_spec.rb +58 -5
- data/spec/helpers/hyrax/batch_edits_helper_spec.rb +4 -2
- data/spec/helpers/hyrax/iiif_helper_spec.rb +44 -0
- data/spec/hyrax/transactions/create_work_spec.rb +155 -0
- data/spec/hyrax/transactions/steps/apply_permission_template_spec.rb +72 -0
- data/spec/hyrax/transactions/steps/ensure_admin_set_spec.rb +25 -0
- data/spec/hyrax/transactions/steps/ensure_permission_template_spec.rb +33 -0
- data/spec/hyrax/transactions/steps/save_work_spec.rb +32 -0
- data/spec/hyrax/transactions/steps/set_default_admin_set_spec.rb +38 -0
- data/spec/hyrax/transactions/steps/set_modified_date_spec.rb +22 -0
- data/spec/hyrax/transactions/steps/set_uploaded_date_spec.rb +32 -0
- data/spec/jobs/attach_files_to_work_with_ordered_members_job_spec.rb +13 -0
- data/spec/presenters/hyrax/presenter_renderer_spec.rb +4 -2
- data/spec/presenters/hyrax/work_show_presenter_spec.rb +46 -2
- data/spec/services/hyrax/permission_template_applicator_spec.rb +69 -0
- data/spec/spec_helper.rb +13 -2
- data/spec/views/catalog/index.html.erb_spec.rb +7 -4
- data/spec/views/hyrax/admin/admin_sets/_show_actions.html.erb_spec.rb +2 -0
- data/spec/views/hyrax/admin/admin_sets/_show_document_list_row.html.erb_spec.rb +4 -1
- data/spec/views/hyrax/admin/admin_sets/index.html.erb_spec.rb +6 -2
- data/spec/views/hyrax/admin/admin_sets/index.json.erb_spec.rb +1 -2
- data/spec/views/hyrax/admin/collection_types/_form_metadata_admin_set.html.erb_spec.rb +1 -1
- data/spec/views/hyrax/admin/collection_types/_form_settings.html.erb_spec.rb +5 -26
- data/spec/views/hyrax/admin/collection_types/index.html.erb_spec.rb +26 -5
- data/spec/views/hyrax/admin/stats/show.html.erb_spec.rb +1 -0
- data/spec/views/hyrax/base/_attribute_rows.html.erb_spec.rb +5 -1
- data/spec/views/hyrax/base/_attributes.html.erb_spec.rb +1 -0
- data/spec/views/hyrax/base/_form_rendering.html.erb_spec.rb +5 -1
- data/spec/views/hyrax/base/_items.html.erb_spec.rb +2 -0
- data/spec/views/hyrax/base/_relationships.html.erb_spec.rb +2 -1
- data/spec/views/hyrax/base/_show_actions.html.erb_spec.rb +71 -0
- data/spec/views/hyrax/base/file_manager.html.erb_spec.rb +11 -14
- data/spec/views/hyrax/base/show.html.erb_spec.rb +2 -2
- data/spec/views/hyrax/base/show.json.jbuilder_spec.rb +3 -1
- data/spec/views/hyrax/collections/_show_document_list_row.html.erb_spec.rb +6 -1
- data/spec/views/hyrax/collections/_show_parent_collections.html.erb_spec.rb +5 -5
- data/spec/views/hyrax/collections/_subcollection_list.html.erb_spec.rb +1 -1
- data/spec/views/hyrax/collections/show.html.erb_spec.rb +3 -2
- data/spec/views/hyrax/dashboard/collections/_form_share.erb_spec.rb +1 -1
- data/spec/views/hyrax/dashboard/collections/_form_share_table.html.erb_spec.rb +1 -1
- data/spec/views/hyrax/dashboard/collections/_show_document_list_row.html.erb_spec.rb +6 -1
- data/spec/views/hyrax/dashboard/collections/_subcollection_list.html.erb_spec.rb +1 -1
- data/spec/views/hyrax/dashboard/collections/edit.html.erb_spec.rb +3 -1
- data/spec/views/hyrax/dashboard/profiles/show.html.erb_spec.rb +2 -3
- data/spec/views/hyrax/file_sets/_show_characterization_details.html.erb_spec.rb +1 -2
- data/spec/views/hyrax/file_sets/_single_use_links.html.erb_spec.rb +1 -2
- data/spec/views/hyrax/homepage/_sortable_featured.html.erb_spec.rb +1 -1
- data/spec/views/hyrax/my/_collection_action_menu.html.erb_spec.rb +5 -5
- data/spec/views/hyrax/my/collections/_list_collections.html.erb_spec.rb +11 -8
- data/spec/views/hyrax/users/index.html.erb_spec.rb +1 -0
- data/spec/views/hyrax/users/show.html.erb_spec.rb +3 -0
- data/template.rb +1 -1
- metadata +65 -3
- data/app/views/hyrax/dashboard/collections/_form_default_group_delt.html.erb +0 -27
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
##
|
5
|
+
# A transaction for creating a Work ready for use in Hyrax. Handles
|
6
|
+
# ensuring admin sets and permission templates are present, and setting
|
7
|
+
# system managed dates prior to save.
|
8
|
+
#
|
9
|
+
# @note This is an experimental replacement for the actor stack's `#create`
|
10
|
+
# stack. In time, we hope this will have feature parity with that stack,
|
11
|
+
# along with improved architecture, error handling, readability, and
|
12
|
+
# customizability. While this develops, please provide feedback.
|
13
|
+
#
|
14
|
+
# @since 2.4.0
|
15
|
+
#
|
16
|
+
# @example Creating a work transactionally
|
17
|
+
# work = MyWork.new(title: ['Comet in Moominland'])
|
18
|
+
# result = Hyrax::Transactions::CreateWork.call(work)
|
19
|
+
# result.success? => true
|
20
|
+
#
|
21
|
+
# @example Handling errors with procedural style
|
22
|
+
# work = MyWork.new # invalid work (no title)
|
23
|
+
# result = Hyrax::Transactions::CreateWork.call(work)
|
24
|
+
# result.success? => false
|
25
|
+
#
|
26
|
+
# result.failure # => failure description or object
|
27
|
+
#
|
28
|
+
# @example Handling errors with `#or`
|
29
|
+
# work = MyWork.new # invalid work (no title)
|
30
|
+
#
|
31
|
+
# Hyrax::Transactions::CreateWork
|
32
|
+
# .call(work)
|
33
|
+
# .or { |error| handle_error(error) }
|
34
|
+
#
|
35
|
+
# @see https://dry-rb.org/gems/dry-transaction/
|
36
|
+
class CreateWork
|
37
|
+
include Dry::Transaction(container: Hyrax::Transactions::Container)
|
38
|
+
|
39
|
+
step :set_default_admin_set, with: 'work.set_default_admin_set'
|
40
|
+
step :ensure_admin_set, with: 'work.ensure_admin_set'
|
41
|
+
step :apply_permission_template, with: 'work.apply_permission_template'
|
42
|
+
step :set_modified_date, with: 'work.set_modified_date'
|
43
|
+
step :set_uploaded_date, with: 'work.set_uploaded_date'
|
44
|
+
step :save_work, with: 'work.save_work'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transcation` step that applies a permission template.
|
7
|
+
#
|
8
|
+
# @since 2.4.0
|
9
|
+
class ApplyPermissionTemplate
|
10
|
+
include Dry::Transaction::Operation
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param [Hyrax::WorkBehavior] work
|
14
|
+
#
|
15
|
+
# @return [Dry::Monads::Result]
|
16
|
+
def call(work)
|
17
|
+
return Failure(:missing_permission) unless
|
18
|
+
(template = work&.admin_set&.permission_template)
|
19
|
+
|
20
|
+
Hyrax::PermissionTemplateApplicator.apply(template).to(model: work)
|
21
|
+
|
22
|
+
Success(work)
|
23
|
+
rescue ActiveRecord::RecordNotFound => err
|
24
|
+
Failure(err)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transaction` step that ensures the input `work` has an AdminSet.
|
7
|
+
#
|
8
|
+
# @since 2.4.0
|
9
|
+
class EnsureAdminSet
|
10
|
+
include Dry::Transaction::Operation
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param [Hyrax::WorkBehavior] work
|
14
|
+
#
|
15
|
+
# @return [Dry::Monads::Result] `Failure` if there is no `AdminSet` for
|
16
|
+
# the input; `Success(input)`, otherwise.
|
17
|
+
def call(work)
|
18
|
+
work.admin_set_id ? Success(work) : Failure(:no_admin_set_id)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transaction` step that ensures the input `work` has a permission
|
7
|
+
# template.
|
8
|
+
#
|
9
|
+
# @since 2.4.0
|
10
|
+
class EnsurePermissionTemplate
|
11
|
+
include Dry::Transaction::Operation
|
12
|
+
|
13
|
+
##
|
14
|
+
# @param [Hyrax::WorkBehavior] work
|
15
|
+
#
|
16
|
+
# @return [Dry::Monads::Result] `Failure` if there is no
|
17
|
+
# `PermissionTemplate` for the input; `Success(input)`, otherwise.
|
18
|
+
def call(work)
|
19
|
+
return Failure(:no_permission_template) unless
|
20
|
+
Hyrax::PermissionTemplate.find_by(source_id: work.admin_set&.id)
|
21
|
+
|
22
|
+
Success(work)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transaction` step that saves an input work.
|
7
|
+
#
|
8
|
+
# @example saving a work
|
9
|
+
# step = Hyrax::Transactions::Steps::SaveWork.new
|
10
|
+
# work = MyWork.new(title: ['Comet in Moominland'])
|
11
|
+
#
|
12
|
+
# step.call(work) # => Success
|
13
|
+
#
|
14
|
+
# @example handling error cases
|
15
|
+
# step = Hyrax::Transactions::Steps::SaveWork.new
|
16
|
+
# work = MyWork.new(title: [:invalid_title])
|
17
|
+
#
|
18
|
+
# step.call(work).or { |err| puts err.messages }
|
19
|
+
#
|
20
|
+
# @since 2.4.0
|
21
|
+
class SaveWork
|
22
|
+
include Dry::Transaction::Operation
|
23
|
+
|
24
|
+
##
|
25
|
+
# @param [Hyrax::WorkBehavior] work
|
26
|
+
#
|
27
|
+
# @return [Dry::Monads::Result] `Failure` if the work fails to save;
|
28
|
+
# `Success(input)`, otherwise.
|
29
|
+
def call(work)
|
30
|
+
work.save ? Success(work) : Failure(work.errors)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transaction` step that sets the `AdminSet` for an input work to
|
7
|
+
# the default admin set, if none is already set. Creates the default
|
8
|
+
# admin set if it doesn't already exist.
|
9
|
+
class SetDefaultAdminSet
|
10
|
+
include Dry::Transaction::Operation
|
11
|
+
|
12
|
+
##
|
13
|
+
# @param [Hyrax::WorkBehavior] work
|
14
|
+
#
|
15
|
+
# @return [Dry::Monads::Result]
|
16
|
+
def call(work)
|
17
|
+
work.admin_set ||=
|
18
|
+
AdminSet.find(AdminSet.find_or_create_default_admin_set_id)
|
19
|
+
|
20
|
+
Success(work)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transaction` step that sets the modified date to now for an
|
7
|
+
# input work.
|
8
|
+
#
|
9
|
+
# @since 2.4.0
|
10
|
+
class SetModifiedDate
|
11
|
+
include Dry::Transaction::Operation
|
12
|
+
|
13
|
+
##
|
14
|
+
# @param [Hyrax::WorkBehavior] work
|
15
|
+
#
|
16
|
+
# @return [Dry::Monads::Result]
|
17
|
+
def call(work)
|
18
|
+
work.date_modified = Hyrax::TimeService.time_in_utc
|
19
|
+
|
20
|
+
Success(work)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Hyrax
|
3
|
+
module Transactions
|
4
|
+
module Steps
|
5
|
+
##
|
6
|
+
# A `dry-transaction` step that sets the uploaded date to now for an
|
7
|
+
# input work.
|
8
|
+
#
|
9
|
+
# @since 2.4.0
|
10
|
+
class SetUploadedDate
|
11
|
+
include Dry::Transaction::Operation
|
12
|
+
|
13
|
+
##
|
14
|
+
# @note the current implementation sets the uploaded date to
|
15
|
+
# `#date_modified` if it exists, falling back on the current datetime.
|
16
|
+
#
|
17
|
+
# @param [Hyrax::WorkBehavior] work
|
18
|
+
#
|
19
|
+
# @return [Dry::Monads::Result]
|
20
|
+
def call(work)
|
21
|
+
work.date_uploaded =
|
22
|
+
work.date_modified || Hyrax::TimeService.time_in_utc
|
23
|
+
Success(work)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/hyrax/version.rb
CHANGED
@@ -0,0 +1,41 @@
|
|
1
|
+
RSpec.describe Hyrax::Actors::CreateWithFilesOrderedMembersActor do
|
2
|
+
let(:user) { create(:user) }
|
3
|
+
let(:ability) { ::Ability.new(user) }
|
4
|
+
let(:work) { create(:generic_work, user: user) }
|
5
|
+
let(:env) { Hyrax::Actors::Environment.new(work, ability, attributes) }
|
6
|
+
let(:terminator) { Hyrax::Actors::Terminator.new }
|
7
|
+
let(:uploaded_file1) { create(:uploaded_file, user: user) }
|
8
|
+
let(:uploaded_file2) { create(:uploaded_file, user: user) }
|
9
|
+
let(:uploaded_file_ids) { [uploaded_file1.id, uploaded_file2.id] }
|
10
|
+
let(:attributes) { { uploaded_files: uploaded_file_ids } }
|
11
|
+
|
12
|
+
subject(:middleware) do
|
13
|
+
stack = ActionDispatch::MiddlewareStack.new.tap do |middleware|
|
14
|
+
middleware.use described_class
|
15
|
+
end
|
16
|
+
stack.build(terminator)
|
17
|
+
end
|
18
|
+
|
19
|
+
[:create, :update].each do |mode|
|
20
|
+
context "on #{mode}" do
|
21
|
+
before do
|
22
|
+
allow(terminator).to receive(mode).and_return(true)
|
23
|
+
end
|
24
|
+
context "when uploaded_file" do
|
25
|
+
it "invoke the job" do
|
26
|
+
expect(AttachFilesToWorkWithOrderedMembersJob).to receive(:perform_later)
|
27
|
+
middleware.public_send(mode, env)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context "when no uploaded_file" do
|
32
|
+
let(:uploaded_file_ids) { [] }
|
33
|
+
|
34
|
+
it "doesn't invoke job" do
|
35
|
+
expect(AttachFilesToWorkWithOrderedMembersJob).not_to receive(:perform_later)
|
36
|
+
expect(middleware.public_send(mode, env)).to be true
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
RSpec.describe Hyrax::Actors::CreateWithRemoteFilesOrderedMembersActor do
|
2
|
+
let(:terminator) { Hyrax::Actors::Terminator.new }
|
3
|
+
let(:actor) { stack.build(terminator) }
|
4
|
+
let(:stack) do
|
5
|
+
ActionDispatch::MiddlewareStack.new.tap do |middleware|
|
6
|
+
middleware.use described_class
|
7
|
+
end
|
8
|
+
end
|
9
|
+
let(:user) { create(:user) }
|
10
|
+
let(:ability) { Ability.new(user) }
|
11
|
+
let(:work) { create(:generic_work, user: user) }
|
12
|
+
let(:url1) { "https://dl.dropbox.com/fake/blah-blah.filepicker-demo.txt.txt" }
|
13
|
+
let(:url2) { "https://dl.dropbox.com/fake/blah-blah.Getting%20Started.pdf" }
|
14
|
+
|
15
|
+
let(:remote_files) do
|
16
|
+
[{ url: url1,
|
17
|
+
expires: "2014-03-31T20:37:36.214Z",
|
18
|
+
file_name: "filepicker-demo.txt.txt" },
|
19
|
+
{ url: url2,
|
20
|
+
expires: "2014-03-31T20:37:36.731Z",
|
21
|
+
file_name: "Getting+Started.pdf" }]
|
22
|
+
end
|
23
|
+
let(:attributes) { { remote_files: remote_files } }
|
24
|
+
let(:environment) { Hyrax::Actors::Environment.new(work, ability, attributes) }
|
25
|
+
|
26
|
+
before do
|
27
|
+
allow(terminator).to receive(:create).and_return(true)
|
28
|
+
end
|
29
|
+
|
30
|
+
context "with two file_sets" do
|
31
|
+
let(:remote_files) do
|
32
|
+
[{ url: url1,
|
33
|
+
expires: "2014-03-31T20:37:36.214Z",
|
34
|
+
file_name: "filepicker-demo.txt.txt" },
|
35
|
+
{ url: url2,
|
36
|
+
expires: "2014-03-31T20:37:36.731Z",
|
37
|
+
file_name: "Getting+Started.pdf" }]
|
38
|
+
end
|
39
|
+
|
40
|
+
it "attaches files and passes ordered_members to OrderedMembersActor in correct order" do
|
41
|
+
expect(Hyrax::Actors::OrderedMembersActor).to receive(:new).with([FileSet, FileSet], user).and_return(Hyrax::Actors::OrderedMembersActor)
|
42
|
+
expect(Hyrax::Actors::OrderedMembersActor).to receive(:attach_ordered_members_to_work).with(work)
|
43
|
+
expect(ImportUrlJob).to receive(:perform_later).with(FileSet, Hyrax::Operation, {}).twice
|
44
|
+
expect(actor.create(environment)).to be true
|
45
|
+
expect(actor.ordered_members.first.label).to eq('filepicker-demo.txt.txt')
|
46
|
+
expect(actor.ordered_members.last.label).to eq('Getting+Started.pdf')
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
RSpec.describe Hyrax::Actors::FileSetOrderedMembersActor do
|
2
|
+
include ActionDispatch::TestProcess
|
3
|
+
|
4
|
+
let(:user) { create(:user) }
|
5
|
+
let(:file_path) { File.join(fixture_path, 'world.png') }
|
6
|
+
let(:file) { fixture_file_upload(file_path, 'image/png') } # we will override for the different types of File objects
|
7
|
+
let(:local_file) { File.open(file_path) }
|
8
|
+
let(:file_set) { create(:file_set, content: local_file) }
|
9
|
+
let(:actor) { described_class.new(file_set, user) }
|
10
|
+
let(:relation) { :original_file }
|
11
|
+
let(:file_actor) { Hyrax::Actors::FileActor.new(file_set, relation, user) }
|
12
|
+
|
13
|
+
describe 'creating metadata, content and attaching to a work' do
|
14
|
+
let(:work) { create(:generic_work) }
|
15
|
+
let(:date_today) { DateTime.current }
|
16
|
+
|
17
|
+
subject { file_set.reload }
|
18
|
+
|
19
|
+
before do
|
20
|
+
allow(DateTime).to receive(:current).and_return(date_today)
|
21
|
+
allow(actor).to receive(:acquire_lock_for).and_yield
|
22
|
+
actor.create_metadata
|
23
|
+
actor.create_content(file)
|
24
|
+
actor.attach_to_work(work)
|
25
|
+
end
|
26
|
+
|
27
|
+
context 'when a work is provided' do
|
28
|
+
it 'does not add the FileSet to the parent work' do
|
29
|
+
expect(subject.parents).to eq []
|
30
|
+
expect(subject.visibility).to eq 'restricted'
|
31
|
+
expect(work.reload.file_sets).not_to include(subject)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,59 @@
|
|
1
|
+
require 'redlock'
|
2
|
+
|
3
|
+
RSpec.describe Hyrax::Actors::OrderedMembersActor do
|
4
|
+
include ActionDispatch::TestProcess
|
5
|
+
|
6
|
+
let(:user) { create(:user) }
|
7
|
+
let(:actor) { described_class.new([file_set], user) }
|
8
|
+
let(:file_set) { build(:file_set) }
|
9
|
+
let(:work) { create(:generic_work) }
|
10
|
+
|
11
|
+
describe 'attaching to a work' do
|
12
|
+
before do
|
13
|
+
allow(actor).to receive(:acquire_lock_for).and_yield
|
14
|
+
actor.attach_ordered_members_to_work(work)
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'when a work is provided' do
|
18
|
+
it 'adds the FileSet to the parent work' do
|
19
|
+
expect(file_set.parents).to eq [work]
|
20
|
+
expect(work.reload.file_sets).to include(file_set)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context 'with multiple file_sets' do
|
25
|
+
let(:work_v1) { create(:generic_work) } # this version of the work has no members
|
26
|
+
|
27
|
+
before do # another file_set is added
|
28
|
+
work.ordered_members << create(:file_set)
|
29
|
+
work.save!
|
30
|
+
end
|
31
|
+
|
32
|
+
it "now contains two file_sets" do
|
33
|
+
expect(work.members.size).to eq 2
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with multiple versions' do
|
38
|
+
let(:work_v1) { create(:generic_work) } # this version of the work has no members
|
39
|
+
|
40
|
+
before do # another version of the same work is saved with a member
|
41
|
+
work_v2 = ActiveFedora::Base.find(work_v1.id)
|
42
|
+
work_v2.ordered_members << create(:file_set)
|
43
|
+
work_v2.save!
|
44
|
+
end
|
45
|
+
|
46
|
+
it "writes to the most up to date version" do
|
47
|
+
actor.attach_ordered_members_to_work(work_v1)
|
48
|
+
expect(work_v1.members.size).to eq 2
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe "#runs callbacks" do
|
54
|
+
it 'runs callbacks' do
|
55
|
+
expect(FileSetAttachedEventJob).to receive(:perform_later).with(file_set, user)
|
56
|
+
actor.attach_ordered_members_to_work(work)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
@@ -107,6 +107,7 @@ RSpec.describe Hyrax::EmbargoesController do
|
|
107
107
|
expect(a_work.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
|
108
108
|
expect(file_set.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
|
109
109
|
expect(response).to redirect_to embargoes_path
|
110
|
+
expect(flash[:notice]).to be_present
|
110
111
|
end
|
111
112
|
end
|
112
113
|
|
@@ -138,6 +139,7 @@ RSpec.describe Hyrax::EmbargoesController do
|
|
138
139
|
expect(file_set2.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC
|
139
140
|
expect(file_set3.reload.visibility).to eq Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
|
140
141
|
expect(response).to redirect_to embargoes_path
|
142
|
+
expect(flash[:notice]).to be_present
|
141
143
|
end
|
142
144
|
end
|
143
145
|
end
|