Class: Faalis::Dashboard::Models::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/faalis/dashboard/models/sidebar.rb

Direct Known Subclasses

Menu

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(title, options) ⇒ Item

Returns a new instance of Item.



5
6
7
8
9
# File 'lib/faalis/dashboard/models/sidebar.rb', line 5

def initialize(title, options)
  @title = title
  @model = nil
  extract_options(options)
end

Instance Attribute Details

#iconObject (readonly)

Returns the value of attribute icon.



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def icon
  @icon
end

#members_onlyObject (readonly)

Returns the value of attribute members_only.



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def members_only
  @members_only
end

#modelObject (readonly)

Returns the value of attribute model.



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def model
  @model
end

#titleObject (readonly)

Returns the value of attribute title.



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def title
  @title
end

#urlObject (readonly)

Returns the value of attribute url.



4
5
6
# File 'lib/faalis/dashboard/models/sidebar.rb', line 4

def url
  @url
end

Instance Method Details

#visible?(user) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/faalis/dashboard/models/sidebar.rb', line 11

def visible?(user)
  return true if @model.nil?

  if @model.respond_to? :map
    permissions = @model.map do |model|
      # Find the appropriate policy for each model
      # and authorize the user against that.
      Pundit.policy!(user, model.to_sym).index?
    end
    # If user don't have access to none of the models
    # then the menu should not be visible
    permissions.any?
  else

    # Authorize the menu visibility against user and given model
    Pundit.policy!(user, @model.to_sym).index?
  end
end