Module: Helioth::ControllerAdditions

Defined in:
lib/helioth/controller_additions.rb

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



3
4
5
6
# File 'lib/helioth/controller_additions.rb', line 3

def self.included(base)
  base.extend ClassMethods
  base.helper_method :access_to?, :locale_access_to?, :user_access_to?, :instance_access_to?
end

Instance Method Details

#access_to?(feature, *actions) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
17
18
19
# File 'lib/helioth/controller_additions.rb', line 14

def access_to?(feature, *actions)
  return false if !locale_access_to?(feature, *actions)
  return true if DSL.roles.user.present? && user_access_to?(feature, *actions)
  return true if DSL.roles.instance.present? && instance_access_to?(feature, *actions)
  return false
end

#instance_access_to?(feature, *actions) ⇒ Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/helioth/controller_additions.rb', line 29

def instance_access_to?(feature, *actions)
  DSL.authorized_for_instance?(feature, actions, current_instance.helioth_role?)
end

#locale_access_to?(feature, *actions) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/helioth/controller_additions.rb', line 21

def locale_access_to?(feature, *actions)
  DSL.authorized_for_locale?(feature, actions, I18n.locale)
end

#user_access_to?(feature, *actions) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/helioth/controller_additions.rb', line 25

def user_access_to?(feature, *actions)
  DSL.authorized_for_user?(feature, actions, current_user.helioth_role?)
end