Class: Components::AccessIndicator

Inherits:
Base
  • Object
show all
Defined in:
app/components/access_indicator.rb

Instance Method Summary collapse

Constructor Details

#initialize(object:, icon: true, text: false) ⇒ AccessIndicator

Returns a new instance of AccessIndicator.

Parameters:

  • object —

    The object to show the access details for; must include the CaberSubject concern

  • icon (defaults to: true) —

    Whether or not to show an indicator icon

  • text (defaults to: false) —

    Whether or not to show a indicator text



5
6
7
8
9
# File 'app/components/access_indicator.rb', line 5

def initialize(object:, icon: true, text: false)
  @object = object
  @icon = icon
  @text = text
end

Instance Method Details

#render? ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
# File 'app/components/access_indicator.rb', line 11

def render?
  SiteSettings.multiuser_enabled? && !@object.remote? && (current_user&.is_moderator? || current_user&.owns?(@object))
end

#view_template ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/components/access_indicator.rb', line 15

def view_template
  span do
    if @object.private?
      span(class: "text-danger") { Icon(icon: "lock-fill", label: t("general.private")) } if @icon
      if @text
        whitespace
        span { t("general.private") }
      end
    elsif @object.public?
      span(class: "text-success") { Icon(icon: "eye-fill", label: t("general.public")) } if @icon
      if @text
        whitespace
        span { t("general.public") }
      end
    else
      span(class: "text-info") { Icon(icon: "unlock", label: t("general.shared")) } if @icon
      if @text
        whitespace
        span { t("general.shared") }
      end
    end
  end
end