Module: Hyrax::AbilityHelper

Included in:
HyraxHelperBehavior
Defined in:
app/helpers/hyrax/ability_helper.rb

Instance Method Summary collapse

Instance Method Details



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'app/helpers/hyrax/ability_helper.rb', line 24

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

#visibility_badge(value) ⇒ Object



20
21
22
# File 'app/helpers/hyrax/ability_helper.rb', line 20

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

#visibility_options(variant) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/hyrax/ability_helper.rb', line 4

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