Sha256: e8f5712474ffb9e58bcecc7565f8fa22844d0009696e35c66b8c52ef0a21ce82

Contents?: true

Size: 1.62 KB

Versions: 23

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true
module Hyrax
  module AbilityHelper
    def visibility_options(variant)
      options = [
        Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC,
        Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED,
        Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PRIVATE
      ]
      case variant
      when :restrict
        options.delete_at(0)
        options.reverse!
      when :loosen
        options.delete_at(2)
      end
      options.map { |value| [visibility_text(value), value] }
    end

    def visibility_badge(value)
      PermissionBadge.new(value).render
    end

    def render_visibility_link(document)
      # Admin Sets do not have a visibility property.
      return if document.respond_to?(:admin_set?) && document.admin_set?

      # Anchor must match with a tab in
      # https://github.com/samvera/hyrax/blob/master/app/views/hyrax/base/_guts4form.html.erb#L2
      path = if document.collection?
               hyrax.edit_dashboard_collection_path(document, anchor: 'share')
             else
               edit_polymorphic_path([main_app, document], anchor: 'share')
             end
      link_to(
        visibility_badge(document.visibility),
        path,
        id: "permission_#{document.id}",
        class: 'visibility-link',
        title: "#{t('hyrax.works.form.tab.share')}: #{document.title_or_label}"
      )
    end

    private

    def visibility_text(value)
      return institution_name if value == Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED
      t("hyrax.visibility.#{value}.text")
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
hyrax-5.0.1 app/helpers/hyrax/ability_helper.rb
hyrax-5.0.0 app/helpers/hyrax/ability_helper.rb
hyrax-5.0.0.rc3 app/helpers/hyrax/ability_helper.rb
hyrax-5.0.0.rc2 app/helpers/hyrax/ability_helper.rb
hyrax-5.0.0.rc1 app/helpers/hyrax/ability_helper.rb
hyrax-3.6.0 app/helpers/hyrax/ability_helper.rb
hyrax-4.0.0 app/helpers/hyrax/ability_helper.rb
hyrax-4.0.0.rc3 app/helpers/hyrax/ability_helper.rb
hyrax-4.0.0.rc2 app/helpers/hyrax/ability_helper.rb
hyrax-4.0.0.rc1 app/helpers/hyrax/ability_helper.rb
hyrax-3.5.0 app/helpers/hyrax/ability_helper.rb
hyrax-4.0.0.beta2 app/helpers/hyrax/ability_helper.rb
hyrax-3.4.2 app/helpers/hyrax/ability_helper.rb
hyrax-4.0.0.beta1 app/helpers/hyrax/ability_helper.rb
hyrax-3.4.1 app/helpers/hyrax/ability_helper.rb
hyrax-3.4.0 app/helpers/hyrax/ability_helper.rb
hyrax-3.3.0 app/helpers/hyrax/ability_helper.rb
hyrax-3.2.0 app/helpers/hyrax/ability_helper.rb
hyrax-3.1.0 app/helpers/hyrax/ability_helper.rb
hyrax-3.0.2 app/helpers/hyrax/ability_helper.rb