hyrax 3.0.0.pre.rc3 → 3.0.0.pre.rc4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (84) hide show
  1. checksums.yaml +4 -4
  2. data/.dassie/config/locales/hyrax.es.yml +3 -1
  3. data/.dassie/config/tinymce.yml +3 -2
  4. data/.regen +1 -1
  5. data/CONTAINERS.md +12 -0
  6. data/Dockerfile +10 -8
  7. data/README.md +5 -0
  8. data/app/assets/javascripts/hyrax.js +1 -0
  9. data/app/assets/javascripts/hyrax/app.js.erb +0 -10
  10. data/app/assets/stylesheets/hyrax/_catalog.scss +1 -0
  11. data/app/assets/stylesheets/hyrax/_representative-media.scss +2 -2
  12. data/app/controllers/hyrax/file_sets_controller.rb +55 -4
  13. data/app/controllers/hyrax/my_controller.rb +1 -1
  14. data/app/forms/hyrax/forms/file_manager_form.rb +9 -2
  15. data/app/helpers/hyrax/ability_helper.rb +2 -1
  16. data/app/helpers/hyrax/contact_form_helper.rb +1 -2
  17. data/app/helpers/hyrax/hyrax_helper_behavior.rb +16 -1
  18. data/app/helpers/hyrax/workflows_helper.rb +42 -0
  19. data/app/models/concerns/hyrax/ability.rb +2 -2
  20. data/app/models/hyrax/contact_form.rb +1 -7
  21. data/app/models/hyrax/permission_template.rb +14 -0
  22. data/app/models/proxy_deposit_request.rb +8 -4
  23. data/app/presenters/hyrax/file_set_presenter.rb +10 -0
  24. data/app/presenters/hyrax/google_scholar_presenter.rb +86 -0
  25. data/app/presenters/hyrax/work_show_presenter.rb +1 -1
  26. data/app/search_builders/hyrax/dashboard/nested_collections_search_builder.rb +0 -24
  27. data/app/services/hyrax/admin_set_member_service.rb +1 -1
  28. data/app/services/hyrax/change_content_depositor_service.rb +29 -7
  29. data/app/services/hyrax/collections/permissions_service.rb +5 -6
  30. data/app/services/hyrax/custom_queries/find_ids_by_model.rb +37 -0
  31. data/app/services/hyrax/edit_permissions_service.rb +201 -0
  32. data/app/services/hyrax/identifier/dispatcher.rb +1 -1
  33. data/app/services/hyrax/listeners/active_fedora_acl_index_listener.rb +26 -0
  34. data/app/services/hyrax/listeners/metadata_index_listener.rb +5 -1
  35. data/app/views/catalog/_index_header_list_collection.html.erb +1 -1
  36. data/app/views/catalog/_index_header_list_default.html.erb +1 -1
  37. data/app/views/catalog/_index_list_default.html.erb +1 -1
  38. data/app/views/hyrax/admin/admin_sets/_show_document_list_row.html.erb +1 -1
  39. data/app/views/hyrax/base/_currently_shared.html.erb +46 -0
  40. data/app/views/hyrax/base/_form_share.html.erb +5 -33
  41. data/app/views/hyrax/base/_show_actions.html.erb +16 -14
  42. data/app/views/hyrax/base/unavailable.html.erb +1 -1
  43. data/app/views/hyrax/batch_edits/_currently_shared.html.erb +8 -0
  44. data/app/views/hyrax/collections/_show_document_list_row.html.erb +1 -1
  45. data/app/views/hyrax/collections/_sort_and_per_page.html.erb +1 -1
  46. data/app/views/hyrax/contact_form/new.html.erb +3 -1
  47. data/app/views/hyrax/dashboard/collections/_show_document_list_menu.html.erb +1 -1
  48. data/app/views/hyrax/dashboard/collections/_show_document_list_row.html.erb +1 -1
  49. data/app/views/hyrax/dashboard/collections/_sort_and_per_page.html.erb +1 -1
  50. data/app/views/hyrax/file_sets/_actions.html.erb +1 -2
  51. data/app/views/hyrax/file_sets/_permission_form.html.erb +2 -31
  52. data/app/views/hyrax/file_sets/_show_actions.html.erb +1 -1
  53. data/app/views/hyrax/file_sets/media_display/_audio.html.erb +2 -2
  54. data/app/views/hyrax/file_sets/media_display/_default.html.erb +1 -1
  55. data/app/views/hyrax/file_sets/media_display/_image.html.erb +1 -1
  56. data/app/views/hyrax/file_sets/media_display/_office_document.html.erb +1 -1
  57. data/app/views/hyrax/file_sets/media_display/_pdf.html.erb +2 -2
  58. data/app/views/hyrax/file_sets/media_display/_video.html.erb +2 -2
  59. data/app/views/hyrax/my/_sort_and_per_page.html.erb +1 -1
  60. data/app/views/layouts/_head_tag_content.html.erb +1 -1
  61. data/app/views/shared/_citations.html.erb +16 -12
  62. data/bin/hyrax-entrypoint.sh +9 -2
  63. data/chart/hyrax/Chart.yaml +2 -2
  64. data/config/initializers/listeners.rb +1 -0
  65. data/config/locales/hyrax.de.yml +71 -13
  66. data/config/locales/hyrax.en.yml +31 -19
  67. data/config/locales/hyrax.es.yml +60 -2
  68. data/config/locales/hyrax.fr.yml +60 -2
  69. data/config/locales/hyrax.it.yml +60 -2
  70. data/config/locales/hyrax.pt-BR.yml +60 -2
  71. data/config/locales/hyrax.zh.yml +60 -2
  72. data/documentation/developing-your-hyrax-based-app.md +2 -2
  73. data/hyrax.gemspec +2 -2
  74. data/lib/generators/hyrax/templates/catalog_controller.rb +4 -0
  75. data/lib/generators/hyrax/templates/config/tinymce.yml +3 -2
  76. data/lib/generators/hyrax/work_resource/work_resource_generator.rb +11 -0
  77. data/lib/hyrax/configuration.rb +14 -0
  78. data/lib/hyrax/engine.rb +1 -0
  79. data/lib/hyrax/version.rb +1 -1
  80. data/lib/wings.rb +1 -0
  81. data/lib/wings/services/custom_queries/find_ids_by_model.rb +46 -0
  82. data/lib/wings/setup.rb +1 -0
  83. data/template.rb +1 -1
  84. metadata +21 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 80d651ec9f588b25d242b2b6dcb5c1a98695b3eb9f8bb1f4706a9664a4ce6dbd
4
- data.tar.gz: a145d9fdce4f1577c02b4a521b11b64a91d0dff6f20f9b63b4a663942410e346
3
+ metadata.gz: 684ca77fe907962abffc140cd9b96081584650df75282c35e0ccd6fc041473ca
4
+ data.tar.gz: 661b6c451fa1fbd7f25d91ab56331e88827a4f3e88fddb85bbcb1623a7d9f068
5
5
  SHA512:
6
- metadata.gz: 6d4ca532232ec1d92221da0dbb738a4d081c5ad94dd316f9b878fb3461909a1a6dbbe9520fab6ea11f3a84b55bef41160b3797a7d2318b505163d51c899885eb
7
- data.tar.gz: dc49090b11ff8a4c1c6c57ba97c912d3ae28dd22c3d838154eac4dc76ca20f87fffda64d94f92846342c814bc12fd2bf5fa4ae1265b6243f1bfaacc37899ac71
6
+ metadata.gz: 2f884204185783729a1d7a8d00dfa41c27e592097749f773418cdecf033aff2804e853ccefadf48d7d0c7c18da7576d3d1fa30aba05a58e687814f6d337b8c7c
7
+ data.tar.gz: ae5b51cbb3949d03967a5d4aa1650aaf77c8776d799df5456db09ff4b615ed8665699277f092e50267277afb654ca09e75200863f02f91c92b0f8f08465c0a60
@@ -19,6 +19,7 @@ es:
19
19
  date_created_tesim: Fecha de Creacion
20
20
  date_modified_dtsi: Fecha Modificada
21
21
  date_uploaded_dtsi: Fecha de Subida
22
+ depositor_tesim: Propietario
22
23
  description_tesim: Descripción
23
24
  file_format_tesim: Formato de Archivo
24
25
  identifier_tesim: Identificador
@@ -35,6 +36,7 @@ es:
35
36
  date_created_tesim: Fecha de Creacion
36
37
  date_modified_dtsi: Fecha Modificada
37
38
  date_uploaded_dtsi: Fecha de Subida
39
+ depositor_tesim: Propietario
38
40
  description_tesim: Descripción
39
41
  file_format_tesim: Formato de Archivo
40
42
  identifier_tesim: Identificador
@@ -51,7 +53,7 @@ es:
51
53
  suffix: "@example.org"
52
54
  footer:
53
55
  copyright_html: "<strong>Copyright &copy; 2018 Samvera</strong> bajo licencia de Apache, Version 2.0"
54
- service_html: Un servicio de <a href="http://samvera.org/" class="navbar-link" target="_blank">Samvera/a>.
56
+ service_html: Un servicio de <a href="http://samvera.org/" class="navbar-link" target="_blank">Samvera</a>.
55
57
  institution_name: institución
56
58
  institution_name_full: El nombre de la institución
57
59
  product_name: Hyrax
@@ -3,10 +3,11 @@ default: &default
3
3
  content_block:
4
4
  <<: *default
5
5
  menubar: false
6
- toolbar1: styleselect | bold italic | link image | undo redo
7
- toolbar2: table | fullscreen | uploadimage
6
+ toolbar1: styleselect | bold italic | undo redo
7
+ toolbar2: table | fullscreen | image
8
8
  plugins:
9
9
  - table
10
10
  - fullscreen
11
+ - image
11
12
  custom:
12
13
  <<: *default
data/.regen CHANGED
@@ -1 +1 @@
1
- 35idx
1
+ 36
data/CONTAINERS.md CHANGED
@@ -42,6 +42,8 @@ To stop the containers for the Hyrax-based application, type <kbd>Ctrl</kbd>+<kb
42
42
 
43
43
  _**Note:** Starting and stopping Docker in this way will preserve your data between restarts._
44
44
 
45
+ _**Note:** I (Jeremy) encountered a problem using `docker-compose build`. I ran `bundle update` in `./hyrax` as well as within `./hyrax/.dassie`. That appeared to clear up the problem of a failure to build a gem._
46
+
45
47
  ### Code Changes and Testing
46
48
 
47
49
  With `docker-compose up` running, any changes you make to your cloned Hyrax code-base should show up in `http://localhost:3000`; There may be cases where you need to restart your test application (e.g. stop the containers and start them up again).
@@ -95,6 +97,16 @@ docker-compose exec -w /app/samvera/hyrax-engine app sh -c "bundle exec rake -T"
95
97
 
96
98
  In the two examples, note the difference in the `-w` switch. In the first case, it's referencing the Hyrax-based application. In the latter case, it's referencing the Hyrax engine.
97
99
 
100
+ ### Debugging
101
+
102
+ I (Jeremy) find myself wanting to debug the application. This requires a somewhat different approach than running Hyrax bare-metal. You need to use `docker attach` to debug the running docker instance.
103
+
104
+ 1. With `docker-compose up` running open a new Terminal session.
105
+ 2. In that new Terminal session, using `docker container ls` find the "CONTAINER ID" for the `hyrax-engine-dev`.
106
+ 3. With the "CONTAINER ID", run `docker attach <CONTAINER ID>`.
107
+
108
+ This advice comes from [Debugging Rails App With Docker Compose: How to use Byebug in a dockerized rails app](https://medium.com/gogox-technology/debugging-rails-app-with-docker-compose-39a3767962f4).
109
+
98
110
  <!-- NOTE: This title is referenced in the top-level documentation/developing-your-hyrax-based-app.md. Keep that in mind if you change it. -->
99
111
  ## Docker Image for Hyrax-based Applications
100
112
 
data/Dockerfile CHANGED
@@ -1,5 +1,6 @@
1
1
  ARG RUBY_VERSION=2.7.2
2
- FROM ruby:$RUBY_VERSION-alpine as hyrax-base
2
+ # lock at alpine3.12 because 3.13 has dns resolver problems
3
+ FROM ruby:$RUBY_VERSION-alpine3.12 as hyrax-base
3
4
 
4
5
  ARG DATABASE_APK_PACKAGE="postgresql-dev"
5
6
  ARG EXTRA_APK_PACKAGES="git"
@@ -50,8 +51,8 @@ ENV HYRAX_ENGINE_PATH /app/samvera/hyrax-engine
50
51
  COPY --chown=1001:101 $APP_PATH /app/samvera/hyrax-webapp
51
52
  COPY --chown=1001:101 . /app/samvera/hyrax-engine
52
53
 
53
- RUN cd /app/samvera/hyrax-engine; bundle install --jobs "$(nproc)"
54
- RUN DB_ADAPTER=nulldb DATABASE_URL='postgresql://fake' bundle exec rake assets:precompile
54
+ RUN cd /app/samvera/hyrax-engine && bundle install --jobs "$(nproc)"
55
+ RUN DB_ADAPTER=nulldb DATABASE_URL='postgresql://fake' bundle exec rake yarn:install
55
56
 
56
57
 
57
58
  FROM hyrax-engine-dev as hyrax-engine-dev-worker
@@ -65,11 +66,12 @@ RUN apk --no-cache add bash \
65
66
  mediainfo
66
67
  USER app
67
68
 
68
- RUN wget http://projects.iq.harvard.edu/files/fits/files/fits-1.0.5.zip -O fits.zip \
69
- && unzip fits.zip -d /app \
70
- && rm fits.zip \
71
- && mv /app/fits-1.0.5 /app/fits \
72
- && chmod a+x /app/fits/fits.sh
69
+ RUN mkdir -p /app/fits && \
70
+ cd /app/fits && \
71
+ wget https://github.com/harvard-lts/fits/releases/download/1.5.0/fits-1.5.0.zip -O fits.zip && \
72
+ unzip fits.zip && \
73
+ rm fits.zip && \
74
+ chmod a+x /app/fits/fits.sh
73
75
  ENV PATH="${PATH}:/app/fits"
74
76
 
75
77
  CMD bundle exec sidekiq
data/README.md CHANGED
@@ -17,6 +17,7 @@ Jump in: [![Slack Status](http://slack.samvera.org/badge.svg)](http://slack.samv
17
17
 
18
18
  * [What is Hyrax?](#what-is-hyrax)
19
19
  * [Feature Documentation](#feature-documentation)
20
+ * [Support Policies](#support-policies)
20
21
  * [Help](#help)
21
22
  * [Working with Hyrax](#working-with-hyrax)
22
23
  * [Developing the Hyrax Engine](#developing-the-hyrax-engine)
@@ -52,6 +53,10 @@ Hyrax offers the ability to:
52
53
  * For general information about Hyrax: [Hyrax Site](https://hyrax.samvera.org/)
53
54
  * A note about [versions of Hyrax](./documentation/note-about-versions.md)
54
55
 
56
+ ## Support Policies
57
+
58
+ * Hyrax 3.x supports the latest browser versions for Chrome, Firefox, Edge, and Safari.
59
+
55
60
  ## Help
56
61
 
57
62
  The Samvera community is here to help. Please see our [support guide](./.github/SUPPORT.md).
@@ -30,6 +30,7 @@
30
30
  //= require morris/morris.min
31
31
 
32
32
  //= require clipboard
33
+ //= require tinymce
33
34
 
34
35
  // This is required for Jasmine tests, specifically to polyfill the Symbol() function
35
36
  //= require babel/polyfill
@@ -18,22 +18,12 @@ Hyrax = {
18
18
  this.collectionTypeEditor();
19
19
  this.collectionUtilities();
20
20
  this.adminStatisticsGraphs();
21
- this.tinyMCE();
22
21
  this.sortAndPerPage();
23
22
  this.sidebar();
24
23
  this.batchSelect();
25
24
  this.internationalizationHelper();
26
25
  },
27
26
 
28
- // Add WYSIWYG editor functionality to editable content blocks
29
- tinyMCE: function() {
30
- if (typeof tinyMCE === "undefined")
31
- return;
32
- tinyMCE.init({
33
- selector: 'textarea.tinymce'
34
- });
35
- },
36
-
37
27
  // The AdminSet edit page
38
28
  adminSetEditor: function() {
39
29
  var AdminSetControls = require('hyrax/admin/admin_set_controls');
@@ -37,6 +37,7 @@
37
37
  .search-result-title {
38
38
  display: inline-block;
39
39
  margin: 0 15px;
40
+ font-size: 18px;
40
41
  }
41
42
 
42
43
  @media (max-width: 768px) {
@@ -1,11 +1,11 @@
1
1
  .representative-media {
2
2
  display: block;
3
3
  padding: 0.5em 0;
4
- width: 250px;
4
+ width: 100%;
5
5
  }
6
6
 
7
7
  .canonical-image {
8
8
  display: block;
9
9
  padding: 0.5em 0;
10
- width: 250px;
10
+ width: 100%;
11
11
  }
@@ -1,6 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
  module Hyrax
3
3
  class FileSetsController < ApplicationController
4
+ rescue_from WorkflowAuthorizationException, with: :render_unavailable
5
+
4
6
  include Blacklight::Base
5
7
  include Blacklight::AccessControls::Catalog
6
8
  include Hyrax::Breadcrumbs
@@ -42,9 +44,11 @@ module Hyrax
42
44
 
43
45
  # GET /concern/parent/:parent_id/file_sets/:id
44
46
  def show
47
+ presenter
48
+ guard_for_workflow_restriction_on!(parent: presenter.parent)
45
49
  respond_to do |wants|
46
- wants.html { presenter }
47
- wants.json { presenter }
50
+ wants.html
51
+ wants.json
48
52
  additional_response_formats(wants)
49
53
  end
50
54
  end
@@ -52,12 +56,15 @@ module Hyrax
52
56
  # DELETE /concern/file_sets/:id
53
57
  def destroy
54
58
  parent = curation_concern.parent
59
+ guard_for_workflow_restriction_on!(parent: parent)
55
60
  actor.destroy
56
61
  redirect_to [main_app, parent], notice: view_context.t('hyrax.file_sets.asset_deleted_flash.message')
57
62
  end
58
63
 
59
64
  # PATCH /concern/file_sets/:id
60
65
  def update
66
+ parent = curation_concern.parent
67
+ guard_for_workflow_restriction_on!(parent: parent)
61
68
  if attempt_update
62
69
  after_update_response
63
70
  else
@@ -146,11 +153,23 @@ module Hyrax
146
153
 
147
154
  def initialize_edit_form
148
155
  @parent = @file_set.in_objects.first
156
+ guard_for_workflow_restriction_on!(parent: @parent)
149
157
  original = @file_set.original_file
150
158
  @version_list = Hyrax::VersionListPresenter.new(original ? original.versions.all : [])
151
159
  @groups = current_user.groups
152
160
  end
153
161
 
162
+ include WorkflowsHelper # Provides #workflow_restriction?, and yes I mean include not helper; helper exposes the module methods
163
+ # @param parent [Hyrax::WorkShowPresenter, GenericWork, #suppressed?] an
164
+ # object on which we check if the current can take action.
165
+ #
166
+ # @return true if we did not encounter any workflow restrictions
167
+ # @raise WorkflowAuthorizationException if we encountered some workflow_restriction
168
+ def guard_for_workflow_restriction_on!(parent:)
169
+ return true unless workflow_restriction?(parent, ability: current_ability)
170
+ raise WorkflowAuthorizationException
171
+ end
172
+
154
173
  def actor
155
174
  @actor ||= Hyrax::Actors::FileSetActor.new(@file_set, current_user)
156
175
  end
@@ -161,8 +180,10 @@ module Hyrax
161
180
 
162
181
  def presenter
163
182
  @presenter ||= begin
164
- show_presenter.new(curation_concern_document, current_ability, request)
165
- end
183
+ presenter = show_presenter.new(curation_concern_document, current_ability, request)
184
+ raise WorkflowAuthorizationException if presenter.parent.blank?
185
+ presenter
186
+ end
166
187
  end
167
188
 
168
189
  def curation_concern_document
@@ -200,5 +221,35 @@ module Hyrax
200
221
  end
201
222
  File.join(theme, layout)
202
223
  end
224
+
225
+ # rubocop:disable Metrics/MethodLength
226
+ def render_unavailable
227
+ message = I18n.t("hyrax.workflow.unauthorized_parent")
228
+ respond_to do |wants|
229
+ wants.html do
230
+ unavailable_presenter
231
+ flash[:notice] = message
232
+ render 'unavailable', status: :unauthorized
233
+ end
234
+ wants.json do
235
+ render plain: message, status: :unauthorized
236
+ end
237
+ additional_response_formats(wants)
238
+ wants.ttl do
239
+ render plain: message, status: :unauthorized
240
+ end
241
+ wants.jsonld do
242
+ render plain: message, status: :unauthorized
243
+ end
244
+ wants.nt do
245
+ render plain: message, status: :unauthorized
246
+ end
247
+ end
248
+ end
249
+ # rubocop:enable Metrics/MethodLength
250
+
251
+ def unavailable_presenter
252
+ @presenter ||= show_presenter.new(::SolrDocument.find(params[:id]), current_ability, request)
253
+ end
203
254
  end
204
255
  end
@@ -53,7 +53,7 @@ module Hyrax
53
53
  # TODO: Extract a presenter object that wrangles all of these instance variables.
54
54
  def prepare_instance_variables_for_batch_control_display
55
55
  # set up some parameters for allowing the batch controls to show appropriately
56
- max_batch_size = 80
56
+ max_batch_size = Hyrax.config.range_for_number_of_results_to_display_per_page.max
57
57
  count_on_page = @document_list.count { |doc| batch.index(doc.id) }
58
58
  @disable_select_all = @document_list.count > max_batch_size
59
59
  @result_set_size = @response.response["numFound"]
@@ -6,10 +6,17 @@ module Hyrax
6
6
  self.terms = []
7
7
  delegate :id, :thumbnail_id, :representative_id, :to_s, to: :model
8
8
  attr_reader :current_ability, :request
9
- def initialize(work, ability)
9
+
10
+ ##
11
+ # @param work [Object] a work with members
12
+ # @param ability [::Ability] the current ability
13
+ # @param member_factory [Class] the member_presenter factory object to use
14
+ # when constructing presenters
15
+ def initialize(work, ability, member_factory: MemberPresenterFactory)
10
16
  super(work)
11
17
  @current_ability = ability
12
18
  @request = nil
19
+ @member_factory = member_factory
13
20
  end
14
21
 
15
22
  def version
@@ -21,7 +28,7 @@ module Hyrax
21
28
  private
22
29
 
23
30
  def member_presenter_factory
24
- MemberPresenterFactory.new(model, current_ability)
31
+ @member_factory.new(model, current_ability)
25
32
  end
26
33
  end
27
34
  end
@@ -36,7 +36,8 @@ module Hyrax
36
36
  visibility_badge(document.visibility),
37
37
  path,
38
38
  id: "permission_#{document.id}",
39
- class: 'visibility-link'
39
+ class: 'visibility-link',
40
+ title: "#{t('hyrax.works.form.tab.share')}: #{document.title_or_label}"
40
41
  )
41
42
  end
42
43
 
@@ -17,8 +17,7 @@ module Hyrax
17
17
  #
18
18
  # @see https://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
19
19
  def contact_form_issue_type_options
20
- types = Hyrax::ContactForm.issue_types_for_locale.dup
21
- types.unshift([t('hyrax.contact_form.select_type'), nil])
20
+ Hyrax::ContactForm.issue_types_for_locale.dup
22
21
  end
23
22
  end
24
23
  end
@@ -1,3 +1,4 @@
1
+ # coding: utf-8
1
2
  # frozen_string_literal: true
2
3
  module Hyrax
3
4
  module HyraxHelperBehavior
@@ -17,6 +18,7 @@ module Hyrax
17
18
  include Hyrax::MembershipHelper
18
19
  include Hyrax::PermissionLevelsHelper
19
20
  include Hyrax::WorkFormHelper
21
+ include Hyrax::WorkflowsHelper
20
22
 
21
23
  # Which translations are available for the user to select
22
24
  # @return [Hash{String => String}] locale abbreviations as keys and flags as values
@@ -192,6 +194,7 @@ module Hyrax
192
194
  # *Sometimes* a Blacklight index field helper_method
193
195
  # @param [String,User,Hash{Symbol=>Array}] args if a hash, the user_key must be under :value
194
196
  # @return [ActiveSupport::SafeBuffer] the html_safe link
197
+ # rubocop:disable Metrics/CyclomaticComplexity
195
198
  def link_to_profile(args)
196
199
  user_or_key = args.is_a?(Hash) ? args[:value].first : args
197
200
  user = case user_or_key
@@ -202,8 +205,20 @@ module Hyrax
202
205
  end
203
206
  return user_or_key if user.nil?
204
207
  text = user.respond_to?(:name) ? user.name : user_or_key
205
- link_to text, Hyrax::Engine.routes.url_helpers.user_path(user)
208
+ user_path_params = [user]
209
+
210
+ # Oh the antics, because in some cases (stares at
211
+ # jobs/content_deposit_event_job_spec.rb) the controller is nil,
212
+ # which means calling params will raise a NoMethodError. I also
213
+ # suppose it's possible that the controller won't have a set
214
+ # params. These precautions should help with that. I'd love to
215
+ # use params[:locale] in this case, but the & try syntax doesn't
216
+ # work with that. So you get this lovely bit of logic.
217
+ locale = controller&.params&.fetch(:locale, nil) || controller&.params&.fetch('locale', nil)
218
+ user_path_params << { locale: locale } if locale
219
+ link_to text, Hyrax::Engine.routes.url_helpers.user_path(*user_path_params)
206
220
  end
221
+ # rubocop:enable Metrics/CyclomaticComplexity
207
222
 
208
223
  # A Blacklight index field helper_method
209
224
  # @param [Hash] options from blacklight helper_method invocation. Maps license URIs to links with labels.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+ module Hyrax
3
+ module WorkflowsHelper
4
+ # Does a workflow restriction exist for the given :object and
5
+ # given :ability?
6
+ #
7
+ # @note If the object responds to a :workflow_restriction?, we'll
8
+ # use that answer.
9
+ #
10
+ # This method doesn't answer what kind of restriction is in place
11
+ # (that requires a far more nuanced permissioning system than
12
+ # Hyrax presently has). Instead, it answers is there one in
13
+ # place. From that answer, you may opt out of rendering a region
14
+ # on a view (e.g. don't show links to the edit page).
15
+ #
16
+ # @param object [Object]
17
+ # @param ability [Ability]
18
+ #
19
+ # @return [false] when there are no applicable workflow restrictions
20
+ #
21
+ # @return [true] when there is an applicable workflow restriction,
22
+ # and you likely want to not render something.
23
+ #
24
+ # @note This is Jeremy, I encourage you to look at the views that
25
+ # call this method to understand the conceptual space this
26
+ # method covers.
27
+ #
28
+ # @todo As I noodle on this, I'm fairly certain we should be
29
+ # registering a CanCan ability check. I believe in
30
+ # promoting this to a helper method it will be easier to
31
+ # incorporate this into an ability.
32
+ #
33
+ # @see Hyrax::FileSetsController for non-view usage.
34
+ def workflow_restriction?(object, ability: current_ability)
35
+ return false if object.nil? # Yup, we may get nil, and there's no restriction on nil
36
+ return object.workflow_restriction? if object.respond_to?(:workflow_restriction?)
37
+ return false if ability.can?(:edit, object)
38
+ return object.suppressed? if object.respond_to?(:suppressed?)
39
+ false
40
+ end
41
+ end
42
+ end