diff --git a/hyrax/app/helpers/complex_filter_helper.rb b/hyrax/app/helpers/complex_filter_helper.rb index 967b7722fea74625fe39b2bf4521d85f3325f7dc..07bb016e6ffb370ea37d0acfad8e768c6b88baaf 100644 --- a/hyrax/app/helpers/complex_filter_helper.rb +++ b/hyrax/app/helpers/complex_filter_helper.rb @@ -65,7 +65,7 @@ module ComplexFilterHelper complex_subjects end - def filtered_sessions(subject_query, session_query, modality_query) + def filtered_sessions(subject_query = nil, session_query = nil , modality_query = nil) complex_sessions = ComplexSession.includes(:complex_subject, :complex_modalities) if subject_query.present? @@ -83,7 +83,7 @@ module ComplexFilterHelper complex_sessions end - def filtered_modalities(subject_query, session_query, modality_query) + def filtered_modalities(subject_query = nil, session_query = nil , modality_query = nil) complex_modalities = ComplexModality.includes(complex_session: :complex_subject) if subject_query.present? diff --git a/hyrax/app/helpers/hyrax/workflows_helper.rb b/hyrax/app/helpers/hyrax/workflows_helper.rb new file mode 100644 index 0000000000000000000000000000000000000000..d47aff0e543ade281a3e4341a05443376e78da23 --- /dev/null +++ b/hyrax/app/helpers/hyrax/workflows_helper.rb @@ -0,0 +1,42 @@ +# frozen_string_literal: true +module Hyrax + module WorkflowsHelper + # Does a workflow restriction exist for the given :object and + # given :ability? + # + # @note If the object responds to a :workflow_restriction?, we'll + # use that answer. + # + # This method doesn't answer what kind of restriction is in place + # (that requires a far more nuanced permissioning system than + # Hyrax presently has). Instead, it answers is there one in + # place. From that answer, you may opt out of rendering a region + # on a view (e.g. don't show links to the edit page). + # + # @param object [Object] + # @param ability [Ability] + # + # @return [false] when there are no applicable workflow restrictions + # + # @return [true] when there is an applicable workflow restriction, + # and you likely want to not render something. + # + # @note This is Jeremy, I encourage you to look at the views that + # call this method to understand the conceptual space this + # method covers. + # + # @todo As I noodle on this, I'm fairly certain we should be + # registering a CanCan ability check. I believe in + # promoting this to a helper method it will be easier to + # incorporate this into an ability. + # + # @see Hyrax::FileSetsController for non-view usage. + def workflow_restriction?(object, ability: current_ability) + return false if object.nil? # Yup, we may get nil, and there's no restriction on nil + return object.workflow_restriction? if object.respond_to?(:workflow_restriction?) + return false if ability.can?(:edit, object) || ability.can?(:read, object) + return object.suppressed? if object.respond_to?(:suppressed?) + false + end + end +end \ No newline at end of file diff --git a/hyrax/config/initializers/file_set_presenter_override.rb b/hyrax/config/initializers/file_set_presenter_override.rb new file mode 100644 index 0000000000000000000000000000000000000000..41326ff45cf2fe7cc3a42332cdcea4319504fae6 --- /dev/null +++ b/hyrax/config/initializers/file_set_presenter_override.rb @@ -0,0 +1,20 @@ +Rails.configuration.to_prepare do + Hyrax::FileSetPresenter.class_eval do + private + + def fetch_parent_presenter + ids = Hyrax::SolrService.query("{!field f=member_ids_ssim}#{id}", fl: Hyrax.config.id_field) + .map { |x| x.fetch(Hyrax.config.id_field) } + Hyrax.logger.warn("Couldn't find a parent work for FileSet: #{id}.") if ids.empty? + ids.each do |id| + doc = ::SolrDocument.find(id) + next if current_ability.can?(:edit, doc) || current_ability.can?(:read, doc) + raise WorkflowAuthorizationException if doc.suppressed? && current_ability.can?(:read, doc) + end + + Hyrax::PresenterFactory.build_for(ids: ids, + presenter_class: Hyrax::WorkShowPresenter, + presenter_args: current_ability).first + end + end +end \ No newline at end of file