Module: Formol::Permissions::Controllers::InstanceMethods

Defined in:
lib/formol/permissions/controllers.rb

Instance Method Summary collapse

Instance Method Details

#formol_authorize!(user, rights, obj = nil) ⇒ Object



22
23
24
25
26
# File 'lib/formol/permissions/controllers.rb', line 22

def formol_authorize!(user, rights, obj = nil)
  unless formol_authorized?(user, rights, obj)
    raise Formol::Permissions::NotAuthorizedError.new
  end
end

#formol_authorized?(user, rights, obj = nil) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
16
17
18
19
20
# File 'lib/formol/permissions/controllers.rb', line 13

def formol_authorized?(user, rights, obj = nil)
  user = Formol.config.user.new(:formol_profile => :default) if user.nil?
  
  rights = [rights]
  rights.flatten!
  
  rights.any?{ |r| user.formol_allowed_to?(r, obj) }
end