hyrax 1.0.0.rc1 → 1.0.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/.travis.yml +1 -0
  4. data/README.md +7 -1
  5. data/app/actors/hyrax/actors/file_set_actor.rb +22 -32
  6. data/app/assets/javascripts/hyrax/editor.es6 +1 -1
  7. data/app/assets/javascripts/hyrax/monkey_patch_turbolinks.js.coffee +8 -7
  8. data/app/assets/javascripts/hyrax/select_work_type.es6 +4 -0
  9. data/app/assets/stylesheets/hyrax/_dashboard.scss +10 -0
  10. data/app/assets/stylesheets/hyrax/_forms.scss +8 -0
  11. data/app/controllers/concerns/hyrax/controller.rb +2 -5
  12. data/app/controllers/hyrax/admin/workflow_roles_controller.rb +1 -1
  13. data/app/controllers/hyrax/workflow_actions_controller.rb +14 -4
  14. data/app/forms/hyrax/forms/permission_template_form.rb +38 -1
  15. data/app/forms/hyrax/forms/work_form.rb +16 -31
  16. data/app/forms/hyrax/forms/workflow_responsibility_form.rb +5 -2
  17. data/app/helpers/hyrax/hyrax_helper_behavior.rb +1 -1
  18. data/app/jobs/attach_files_to_work_job.rb +5 -15
  19. data/app/models/concerns/hyrax/naming.rb +1 -0
  20. data/app/models/hyrax/permission_template_access.rb +10 -10
  21. data/app/models/sipity/workflow.rb +30 -0
  22. data/app/presenters/hyrax/admin/workflow_role_presenter.rb +17 -31
  23. data/app/presenters/hyrax/admin/workflow_roles_presenter.rb +43 -0
  24. data/app/presenters/hyrax/collection_options_presenter.rb +30 -0
  25. data/app/presenters/hyrax/workflow_presenter.rb +2 -2
  26. data/app/search_builders/hyrax/active_works_search_builder.rb +13 -0
  27. data/app/search_builders/hyrax/my_works_search_builder.rb +9 -12
  28. data/app/search_builders/hyrax/works_search_builder.rb +7 -0
  29. data/app/services/hyrax/actor_factory.rb +1 -1
  30. data/app/services/hyrax/admin_set_create_service.rb +24 -2
  31. data/app/services/hyrax/form_metadata_service.rb +13 -0
  32. data/app/services/hyrax/persist_directly_contained_output_file_service.rb +3 -3
  33. data/app/services/hyrax/workflow/abstract_notification.rb +3 -1
  34. data/app/services/hyrax/workflow/activate_object.rb +1 -1
  35. data/app/services/hyrax/workflow/deactivate_object.rb +1 -1
  36. data/app/services/hyrax/workflow/grant_edit_to_depositor.rb +1 -1
  37. data/app/services/hyrax/workflow/grant_read_to_depositor.rb +13 -0
  38. data/app/services/hyrax/workflow/revoke_edit_from_depositor.rb +11 -0
  39. data/app/services/hyrax/workflow/workflow_schema.rb +1 -1
  40. data/app/views/catalog/_facet_limit.html.erb +5 -3
  41. data/app/views/hyrax/base/_form_visibility_component.html.erb +1 -0
  42. data/app/views/hyrax/homepage/index.html.erb +11 -4
  43. data/app/views/hyrax/my/_facet_limit.html.erb +11 -8
  44. data/app/views/hyrax/my/_index_partials/_default_group.html.erb +2 -1
  45. data/app/views/hyrax/my/_index_partials/_list_works.html.erb +1 -0
  46. data/config/locales/hyrax.en.yml +5 -0
  47. data/config/locales/hyrax.es.yml +8 -3
  48. data/config/locales/hyrax.zh.yml +730 -0
  49. data/hyrax.gemspec +5 -8
  50. data/lib/generators/hyrax/install_generator.rb +2 -3
  51. data/lib/generators/hyrax/models_generator.rb +1 -1
  52. data/lib/generators/hyrax/templates/catalog_controller.rb +37 -37
  53. data/lib/generators/hyrax/templates/config/locales/hyrax.en.yml +43 -0
  54. data/lib/generators/hyrax/templates/config/locales/hyrax.es.yml +43 -0
  55. data/lib/generators/hyrax/templates/config/locales/hyrax.zh.yml +55 -0
  56. data/lib/generators/hyrax/templates/mediated_deposit_workflow.json.erb +4 -1
  57. data/lib/generators/hyrax/work/templates/controller.rb.erb +1 -1
  58. data/lib/generators/hyrax/work/templates/feature_spec.rb.erb +12 -5
  59. data/lib/generators/hyrax/work/templates/locale.zh.yml.erb +10 -0
  60. data/lib/generators/hyrax/work/work_generator.rb +29 -13
  61. data/lib/hyrax/collections_migration.rb +18 -0
  62. data/lib/hyrax/engine.rb +1 -2
  63. data/lib/hyrax/errors.rb +11 -0
  64. data/lib/hyrax/rails/routes.rb +1 -1
  65. data/lib/hyrax/search_state.rb +1 -9
  66. data/lib/hyrax/specs/shared_specs.rb +1 -0
  67. data/lib/hyrax/specs/shared_specs/workflow_method.rb +46 -0
  68. data/lib/hyrax/version.rb +1 -1
  69. data/lib/tasks/migrate.rake +5 -0
  70. data/spec/controllers/hyrax/admin/workflow_roles_controller_spec.rb +3 -3
  71. data/spec/controllers/hyrax/batch_uploads_controller_spec.rb +1 -1
  72. data/spec/controllers/hyrax/workflow_actions_controller_spec.rb +18 -0
  73. data/spec/features/browse_catalog_spec.rb +1 -1
  74. data/spec/features/workflow_roles_spec.rb +1 -1
  75. data/spec/forms/hyrax/forms/work_form_spec.rb +19 -0
  76. data/spec/forms/hyrax/forms/workflow_responsibility_form_spec.rb +15 -7
  77. data/spec/helpers/blacklight_helper_spec.rb +1 -1
  78. data/spec/helpers/hyrax_helper_spec.rb +1 -1
  79. data/spec/jobs/attach_files_to_work_job_spec.rb +8 -14
  80. data/spec/lib/hyrax/collections_migration_spec.rb +34 -0
  81. data/spec/lib/hyrax/search_state_spec.rb +2 -2
  82. data/spec/models/hyrax/permission_template_spec.rb +1 -1
  83. data/spec/models/sipity/workflow_role_spec.rb +1 -0
  84. data/spec/presenters/hyrax/admin/workflow_role_presenter_spec.rb +8 -10
  85. data/spec/presenters/hyrax/admin/workflow_roles_presenter_spec.rb +18 -0
  86. data/spec/presenters/hyrax/collection_options_presenter_spec.rb +14 -0
  87. data/spec/search_builders/hyrax/active_works_search_builder_spec.rb +53 -0
  88. data/spec/search_builders/hyrax/works_search_builder_spec.rb +24 -0
  89. data/spec/services/hyrax/admin_set_create_service_spec.rb +64 -35
  90. data/spec/services/hyrax/persist_directly_contained_output_file_service_spec.rb +11 -7
  91. data/spec/services/hyrax/workflow/activate_object_spec.rb +4 -0
  92. data/spec/services/hyrax/workflow/changes_required_notification_spec.rb +2 -2
  93. data/spec/services/hyrax/workflow/deactivate_object_spec.rb +4 -0
  94. data/spec/services/hyrax/workflow/deposited_notification_spec.rb +2 -2
  95. data/spec/services/hyrax/workflow/grant_edit_to_depositor_spec.rb +4 -0
  96. data/spec/services/hyrax/workflow/pending_review_notification_spec.rb +2 -2
  97. data/spec/services/hyrax/workflow/revoke_edit_from_depositor_spec.rb +35 -0
  98. data/spec/support/controller_level_helpers.rb +1 -1
  99. data/spec/test_app_templates/lib/generators/test_app_generator.rb +10 -2
  100. data/spec/views/catalog/_index_list_default.html.erb_spec.rb +1 -2
  101. data/spec/views/hyrax/admin/workflow_roles/index.html.erb_spec.rb +2 -2
  102. data/spec/views/hyrax/homepage/index.html.erb_spec.rb +22 -2
  103. data/spec/views/shared/select_work_type_modal.html.erb_spec.rb +3 -3
  104. data/template.rb +1 -1
  105. metadata +34 -45
  106. data/lib/hyrax/single_use_error.rb +0 -3
  107. data/lib/hyrax/workflow_authorization_exception.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a838f94e767ce2bce589e28136f4e2d47cddad7c
4
- data.tar.gz: a08c3e0312fc897291fc88e869c32c3fcac169de
3
+ metadata.gz: 99e1fa3e513ad51bdf68404a23597596504fe7bf
4
+ data.tar.gz: 79efe8dbd4eca246b5b6252f19390dbd86a9dba7
5
5
  SHA512:
6
- metadata.gz: da822bb260c799a46b44b848ba74a94add9778f95d58cc41f5869e65617f7d52678d4583db2aa481f9259d76139e6eaa297838a72f4fc447afa250188165c2cc
7
- data.tar.gz: '02968f3e798d6396b35d54eaddc3a0e009743ea48c2ea092a2491ef8d08951a26c68699f84c74105b25f4e6c2b995ee20bb0fb4b6fa115ccf3b80e3289fcecae'
6
+ metadata.gz: 363166554478d540eb6afc4c2b5179fc81ce18307c7c88874d11c0f0b9510845bc5e322ab6824dc9c5023b2360d311fbc4437c0d3a1daa559dc32b7119605e1a
7
+ data.tar.gz: 05c71ebf86f994a796c24833b4d231e31cb2ba1d4d5d91be5e1eeb596c1226e3575fbf31389677f22f5d94be1e210ae941c7a330734c94333bbf5255ad3a2bb5
data/.rubocop.yml CHANGED
@@ -128,3 +128,6 @@ RSpec/NestedGroups:
128
128
 
129
129
  RSpec/LeadingSubject:
130
130
  Enabled: false
131
+
132
+ RSpec/ExampleLength:
133
+ Enabled: false
data/.travis.yml CHANGED
@@ -1,5 +1,6 @@
1
1
  language: ruby
2
2
  sudo: false
3
+ dist: trusty
3
4
 
4
5
  cache:
5
6
  bundler: true
data/README.md CHANGED
@@ -59,7 +59,7 @@ If you have questions or need help, please email [the Hydra community tech list]
59
59
  # Getting started
60
60
 
61
61
  This document contains instructions specific to setting up an app with __Hyrax
62
- v1.0.0.alpha__. If you are looking for instructions on installing a different
62
+ v1.0.0.rc2__. If you are looking for instructions on installing a different
63
63
  version, be sure to select the appropriate branch or tag from the drop-down
64
64
  menu above.
65
65
 
@@ -160,6 +160,12 @@ or
160
160
  rails generate hyrax:work MovingImage
161
161
  ```
162
162
 
163
+ Namespaces can be included in the work My::MovingImage by adding the path.
164
+
165
+ ```
166
+ rails generate hyrax:work My/MovingImage
167
+ ```
168
+
163
169
  You may wish to [customize your work type](https://github.com/projecthydra/sufia/wiki/Customizing-your-work-types) now that it's been generated.
164
170
 
165
171
  ## Start servers
@@ -3,7 +3,6 @@ module Hyrax
3
3
  # Actions are decoupled from controller logic so that they may be called from a controller or a background job.
4
4
  class FileSetActor
5
5
  include Lockable
6
-
7
6
  attr_reader :file_set, :user, :attributes
8
7
 
9
8
  def initialize(file_set, user)
@@ -12,21 +11,17 @@ module Hyrax
12
11
  end
13
12
 
14
13
  # Adds the appropriate metadata, visibility and relationships to file_set
15
- #
16
- # *Note*: In past versions of Hyrax this method did not perform a save because it is mainly used in conjunction with
17
- # create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects,
18
- # we have to save both the parent work and the file_set in order to record the "metadata" relationship
19
- # between them.
14
+ # @note In past versions of Hyrax this method did not perform a save because it is mainly used in conjunction with
15
+ # create_content, which also performs a save. However, due to the relationship between Hydra::PCDM objects,
16
+ # we have to save both the parent work and the file_set in order to record the "metadata" relationship between them.
20
17
  # @param [Hash] file_set_params specifying the visibility, lease and/or embargo of the file set.
21
- # If you don't provide at least one of visibility, embargo_release_date or
22
- # lease_expiration_date, visibility will be copied from the parent.
18
+ # Without visibility, embargo_release_date or lease_expiration_date, visibility will be copied from the parent.
23
19
  def create_metadata(file_set_params = {})
24
20
  file_set.apply_depositor_metadata(user)
25
21
  now = TimeService.time_in_utc
26
22
  file_set.date_uploaded = now
27
23
  file_set.date_modified = now
28
24
  file_set.creator = [user.user_key]
29
-
30
25
  Actors::ActorStack.new(file_set, ability, [InterpretVisibilityActor]).create(file_set_params) if assign_visibility?(file_set_params)
31
26
  yield(file_set) if block_given?
32
27
  end
@@ -39,29 +34,21 @@ module Hyrax
39
34
  # If the file set doesn't have a title or label assigned, set a default.
40
35
  file_set.label ||= file.respond_to?(:original_filename) ? file.original_filename : ::File.basename(file)
41
36
  file_set.title = [file_set.label] if file_set.title.blank?
42
-
43
- # Need to save the file_set in order to get an id
44
- return false unless file_set.save
45
-
37
+ return false unless file_set.save # Need to save the file_set in order to get an id
46
38
  file_actor_class.new(file_set, relation, user).ingest_file(file, asynchronous)
47
39
  true
48
40
  end
49
41
 
50
42
  # Adds a FileSet to the work using ore:Aggregations.
51
- # Locks to ensure that only one process is operating on
52
- # the list at a time.
43
+ # Locks to ensure that only one process is operating on the list at a time.
53
44
  def attach_file_to_work(work, file_set_params = {})
54
45
  acquire_lock_for(work.id) do
55
- # Ensure we have an up-to-date copy of the members association, so
56
- # that we append to the end of the list.
46
+ # Ensure we have an up-to-date copy of the members association, so that we append to the end of the list.
57
47
  work.reload unless work.new_record?
58
- unless assign_visibility?(file_set_params)
59
- copy_visibility(work, file_set)
60
- end
48
+ copy_visibility(work, file_set) unless assign_visibility?(file_set_params)
61
49
  work.ordered_members << file_set
62
50
  set_representative(work, file_set)
63
51
  set_thumbnail(work, file_set)
64
-
65
52
  # Save the work so the association between the work and the file_set is persisted (head_id)
66
53
  # NOTE: the work may not be valid, in which case this save doesn't do anything.
67
54
  work.save
@@ -72,12 +59,9 @@ module Hyrax
72
59
  # @param [String] relation ('original_file')
73
60
  def revert_content(revision_id, relation = 'original_file')
74
61
  file_actor = file_actor_class.new(file_set, relation, user)
75
- if file_actor.revert_to(revision_id)
76
- Hyrax.config.callback.run(:after_revert_content, file_set, user, revision_id)
77
- true
78
- else
79
- false
80
- end
62
+ return false unless file_actor.revert_to(revision_id)
63
+ Hyrax.config.callback.run(:after_revert_content, file_set, user, revision_id)
64
+ true
81
65
  end
82
66
 
83
67
  # @param [File, ActionDigest::HTTP::UploadedFile, Tempfile] file the file uploaded by the user.
@@ -105,6 +89,14 @@ module Hyrax
105
89
  Hyrax::Actors::FileActor
106
90
  end
107
91
 
92
+ # Spawns async job to attach file to fileset
93
+ # @param [#to_s] url
94
+ def import_url(url)
95
+ file_set.update(import_url: url.to_s)
96
+ operation = Hyrax::Operation.create!(user: user, operation_type: "Attach File")
97
+ ImportUrlJob.perform_later(file_set, operation)
98
+ end
99
+
108
100
  private
109
101
 
110
102
  def ability
@@ -112,7 +104,7 @@ module Hyrax
112
104
  end
113
105
 
114
106
  # Takes an optional block and executes the block if the save was successful.
115
- # returns false if the save was unsuccessful
107
+ # @return [Boolean] false if the save was unsuccessful
116
108
  def save
117
109
  on_retry = ->(exception, _, _, _) { ActiveFedora::Base.logger.warn "Hyrax::Actors::FileSetActor#save Caught RSOLR error #{exception.inspect}" }
118
110
  Retriable.retriable on: RSolr::Error::Http,
@@ -147,10 +139,8 @@ module Hyrax
147
139
  def unlink_from_work
148
140
  work = file_set.parent
149
141
  return unless work && (work.thumbnail_id == file_set.id || work.representative_id == file_set.id)
150
- # This is required to clear the thumbnail_id and representative_id
151
- # fields on the work and force it to be re-solrized. Although
152
- # ActiveFedora clears the children nodes it leaves the work's
153
- # thumbnail_id and representative_id fields in Solr populated.
142
+ # Must clear the thumbnail_id and representative_id fields on the work and force it to be re-solrized.
143
+ # Although ActiveFedora clears the children nodes it leaves those fields in Solr populated.
154
144
  work.thumbnail = nil if work.thumbnail_id == file_set.id
155
145
  work.representative = nil if work.representative_id == file_set.id
156
146
  work.save!
@@ -17,7 +17,7 @@ export default class {
17
17
  // Display the sharing tab if they select an admin set that permits sharing
18
18
  sharingTab() {
19
19
  if(this.adminSetWidget && !this.adminSetWidget.isEmpty()) {
20
- this.adminSetWidget.on('change', (data) => this.sharingTabVisiblity(data))
20
+ this.adminSetWidget.on('change', () => this.sharingTabVisiblity(this.adminSetWidget.isSharing()))
21
21
  this.sharingTabVisiblity(this.adminSetWidget.isSharing())
22
22
  }
23
23
  }
@@ -1,10 +1,11 @@
1
1
  # Monkey patch Turbolinks to render 401
2
2
  # See https://github.com/turbolinks/turbolinks/issues/179
3
3
  # https://github.com/projecthydra-labs/hyrax/issues/617
4
- Turbolinks.HttpRequest.prototype.requestLoaded = ->
5
- @endRequest =>
6
- if 200 <= @xhr.status < 300 or @xhr.status == 401
7
- @delegate.requestCompletedWithResponse(@xhr.responseText, @xhr.getResponseHeader("Turbolinks-Location"))
8
- else
9
- @failed = true
10
- @delegate.requestFailedWithStatusCode(@xhr.status, @xhr.responseText)
4
+ if Turbolinks?
5
+ Turbolinks.HttpRequest.prototype.requestLoaded = ->
6
+ @endRequest =>
7
+ if 200 <= @xhr.status < 300 or @xhr.status == 401
8
+ @delegate.requestCompletedWithResponse(@xhr.responseText, @xhr.getResponseHeader("Turbolinks-Location"))
9
+ else
10
+ @failed = true
11
+ @delegate.requestFailedWithStatusCode(@xhr.status, @xhr.responseText)
@@ -14,6 +14,7 @@ export default class SelectWorkType {
14
14
  e.preventDefault()
15
15
  this.modal.modal()
16
16
  // ensure the type is set for the last clicked element
17
+ // type is either "batch" or "single" (work)
17
18
  this.type = element.data('create-type')
18
19
  // add custom routing logic when the modal is shown
19
20
  this.form.on('submit', this.routingLogic.bind(this))
@@ -34,6 +35,9 @@ export default class SelectWorkType {
34
35
  window.location.href = this.destination()
35
36
  }
36
37
 
38
+ // Each input has two attributes that contain paths, one for the batch and one
39
+ // for a single work. So, given the value of 'this.type', return the appropriate
40
+ // path.
37
41
  destination() {
38
42
  return this.form.find('input[type="radio"]:checked').data(this.type)
39
43
  }
@@ -141,3 +141,13 @@ ul.collapsing > li > a {
141
141
  }
142
142
  }
143
143
  }
144
+
145
+ .works-list {
146
+ .workflow-state {
147
+ white-space: nowrap;
148
+ }
149
+
150
+ .media-body {
151
+ width: 18vw;
152
+ }
153
+ }
@@ -52,6 +52,14 @@ form {
52
52
  label { font-weight: normal; }
53
53
  & .form-group { padding: 0 1.75em; }
54
54
 
55
+ #collapseEmbargo .form-group {
56
+ padding: 0;
57
+
58
+ &.generic_work_visibility_after_embargo {
59
+ margin-top: 6px;
60
+ }
61
+ }
62
+
55
63
  .form-inline {
56
64
  .control-label, label {
57
65
  padding-left: 0;
@@ -4,6 +4,8 @@ module Hyrax::Controller
4
4
  included do
5
5
  class_attribute :create_work_presenter_class
6
6
  self.create_work_presenter_class = Hyrax::SelectTypeListPresenter
7
+ self.search_state_class = Hyrax::SearchState
8
+
7
9
  # Adds Hydra behaviors into the application controller
8
10
  include Hydra::Controller::ControllerBehavior
9
11
  helper_method :create_work_presenter
@@ -28,11 +30,6 @@ module Hyrax::Controller
28
30
  super.merge(locale: I18n.locale)
29
31
  end
30
32
 
31
- # Override Blacklight to use the Hyrax::SearchState
32
- def search_state
33
- @search_state ||= Hyrax::SearchState.new(self)
34
- end
35
-
36
33
  private
37
34
 
38
35
  def set_locale
@@ -8,7 +8,7 @@ module Hyrax
8
8
  add_breadcrumb t(:'hyrax.controls.home'), root_path
9
9
  add_breadcrumb t(:'hyrax.toolbar.admin.menu'), hyrax.admin_path
10
10
  add_breadcrumb t(:'hyrax.admin.workflow_roles.header'), hyrax.admin_workflow_roles_path
11
- @presenter = WorkflowRolePresenter.new
11
+ @presenter = WorkflowRolesPresenter.new
12
12
  end
13
13
 
14
14
  def destroy
@@ -3,16 +3,19 @@ module Hyrax
3
3
  before_action :authenticate_user!
4
4
 
5
5
  def update
6
- work = ActiveFedora::Base.find(params[:id])
6
+ @curation_concern = ActiveFedora::Base.find(params[:id])
7
7
  workflow_action_form = Hyrax::Forms::WorkflowActionForm.new(
8
8
  current_ability: current_ability,
9
- work: work,
9
+ work: @curation_concern,
10
10
  attributes: workflow_action_params
11
11
  )
12
12
  if workflow_action_form.save
13
- redirect_to [main_app, work], notice: "The #{work.human_readable_type} has been updated."
13
+ after_update_response
14
14
  else
15
- render 'hyrax/base/unauthorized', status: :unauthorized
15
+ respond_to do |wants|
16
+ wants.html { render 'hyrax/base/unauthorized', status: :unauthorized }
17
+ wants.json { render_json_response(response_type: :unprocessable_entity, options: { errors: @curation_concern.errors }) }
18
+ end
16
19
  end
17
20
  end
18
21
 
@@ -21,5 +24,12 @@ module Hyrax
21
24
  def workflow_action_params
22
25
  params.require(:workflow_action).permit(:name, :comment)
23
26
  end
27
+
28
+ def after_update_response
29
+ respond_to do |wants|
30
+ wants.html { redirect_to [main_app, @curation_concern], notice: "The #{@curation_concern.human_readable_type} has been updated." }
31
+ wants.json { render 'hyrax/base/show', status: :ok, location: polymorphic_path([main_app, @curation_concern]) }
32
+ end
33
+ end
24
34
  end
25
35
  end
@@ -57,6 +57,14 @@ module Hyrax
57
57
  return_info
58
58
  end
59
59
 
60
+ # If management roles have been granted or removed, then copy this access
61
+ # to the edit permissions of the AdminSet and to the WorkflowResponsibilities
62
+ # of the active workflow
63
+ def update_management
64
+ admin_set.update_access_controls!
65
+ update_workflow_approving_responsibilities
66
+ end
67
+
60
68
  private
61
69
 
62
70
  # @return [String]
@@ -70,7 +78,36 @@ module Hyrax
70
78
  def update_participants_options(attributes)
71
79
  update_permission_template(attributes)
72
80
  # if managers were added, recalculate update the access controls on the AdminSet
73
- admin_set.update_access_controls! if managers_updated?(attributes)
81
+ return unless managers_updated?(attributes)
82
+ update_management
83
+ end
84
+
85
+ # Grant workflow approve roles for any admin set managers
86
+ # and revoke the approving role for non-managers
87
+ def update_workflow_approving_responsibilities
88
+ return unless active_workflow
89
+ approving_role = Sipity::Role.find_by_name('approving')
90
+ return unless approving_role
91
+ active_workflow.update_responsibilities(role: approving_role, agents: manager_agents)
92
+ end
93
+
94
+ # @return [Array<Sipity::Agent>] a list of sipity agents corresponding to the manager role of the permission_template
95
+ def manager_agents
96
+ @manager_agents ||= begin
97
+ authorized_agents = manager_grants.map do |access|
98
+ if access.agent_type == 'user'
99
+ ::User.find_by_user_key(access.agent_id)
100
+ else
101
+ Hyrax::Group.new(access.agent_id)
102
+ end
103
+ end
104
+ authorized_agents.map { |agent| PowerConverter.convert_to_sipity_agent(agent) }
105
+ end
106
+ end
107
+
108
+ # @return [Array<PermissionTemplateAccess>] a list of grants corresponding to the manager role of the permission_template
109
+ def manager_grants
110
+ model.access_grants.where(access: 'manage'.freeze)
74
111
  end
75
112
 
76
113
  # @return [String, Nil] error_code if validation fails, nil otherwise
@@ -31,6 +31,9 @@ module Hyrax
31
31
 
32
32
  self.required_fields = [:title, :creator, :keyword, :rights]
33
33
 
34
+ # The service that determines the cardinality of each field
35
+ self.field_metadata_service = Hyrax::FormMetadataService
36
+
34
37
  def initialize(model, current_ability, controller)
35
38
  @current_ability = current_ability
36
39
  @agreement_accepted = !model.new_record?
@@ -81,41 +84,12 @@ module Hyrax
81
84
  # Get a list of collection id/title pairs for the select form
82
85
  def collections_for_select
83
86
  service = Hyrax::CollectionsService.new(@controller)
84
- convert_solr_docs_to_select_options(service.search_results(:edit))
85
- end
86
-
87
- def convert_solr_docs_to_select_options(results)
88
- option_values = results.map do |r|
89
- [r.to_s, r.id]
90
- end
91
- option_values.sort do |a, b|
92
- if a.first && b.first
93
- a.first <=> b.first
94
- else
95
- a.first ? -1 : 1
96
- end
97
- end
98
- end
99
-
100
- # This determines whether the allowed parameters are single or multiple.
101
- # We are returning true for properties that are backed by methods, for
102
- # which the HydraEditor::FieldMetadataService cannot determine are multiple.
103
- # The instance variable is used when choosing which UI widget to draw.
104
- def multiple?(field)
105
- return true if ['ordered_member_ids', 'in_works_ids', 'member_of_collection_ids'].include? field.to_s
106
- super
107
- end
108
-
109
- # The class method _multiple?_ is used for building the permitted params
110
- # for the update action
111
- def self.multiple?(field)
112
- return true if ['ordered_member_ids', 'in_works_ids', 'member_of_collection_ids'].include? field.to_s
113
- super
87
+ CollectionOptionsPresenter.new(service).select_options(:edit)
114
88
  end
115
89
 
116
90
  def self.sanitize_params(form_params)
117
91
  admin_set_id = form_params[:admin_set_id]
118
- if admin_set_id && Sipity::Workflow.find_by!(id: Hyrax::PermissionTemplate.find_by!(admin_set_id: admin_set_id).active_workflow).allows_access_grant?
92
+ if admin_set_id && workflow_for(admin_set_id: admin_set_id).allows_access_grant?
119
93
  return super
120
94
  end
121
95
  params_without_permissions = permitted_params.reject { |arg| arg.respond_to?(:key?) && arg.key?(:permissions_attributes) }
@@ -132,6 +106,17 @@ module Hyrax
132
106
  ]
133
107
  end
134
108
 
109
+ def self.workflow_for(admin_set_id:)
110
+ begin
111
+ workflow = Hyrax::PermissionTemplate.find_by!(admin_set_id: admin_set_id).active_workflow
112
+ rescue ActiveRecord::RecordNotFound
113
+ raise "Missing permission template for AdminSet(id:#{admin_set_id})"
114
+ end
115
+ raise Hyrax::MissingWorkflowError, "PermissionTemplate for AdminSet(id:#{admin_set_id}) does not have an active_workflow" unless workflow
116
+ workflow
117
+ end
118
+ private_class_method :workflow_for
119
+
135
120
  private
136
121
 
137
122
  # @return [Array<FileSetPresenter>] presenters for the file sets in order of the ids
@@ -26,9 +26,12 @@ module Hyrax
26
26
  ::User.all
27
27
  end
28
28
 
29
- # The select options for choosing a responsibility
29
+ # The select options for choosing a responsibility sorted by label
30
30
  def workflow_role_options
31
- Sipity::WorkflowRole.all.map { |wf_role| [label(wf_role), wf_role.id] }
31
+ options = Sipity::WorkflowRole.all.map do |wf_role|
32
+ [Hyrax::Admin::WorkflowRolePresenter.new(wf_role).label, wf_role.id]
33
+ end
34
+ options.sort_by(&:first)
32
35
  end
33
36
 
34
37
  private