Module: Outpost::Controller::Authorization

Included in:
ApplicationController
Defined in:
lib/outpost/controller/authorization.rb

Instance Method Summary collapse

Instance Method Details

#authorize(resource) ⇒ Object

Make sure the user can authorize the current resource



9
10
11
12
13
# File 'lib/outpost/controller/authorization.rb', line 9

def authorize(resource)
  if !current_user.can_manage?(resource)
    handle_unauthorized(resource)
  end
end

#authorize_resourceObject

Use this for before_filter. Should be overridden for custom behavor.



16
17
18
# File 'lib/outpost/controller/authorization.rb', line 16

def authorize_resource
  authorize(self.class.model)
end

#handle_unauthorized(resource) ⇒ Object

What to do when a user doesn’t have proper permissions



21
22
23
24
25
26
# File 'lib/outpost/controller/authorization.rb', line 21

def handle_unauthorized(resource)
  redirect_to outpost.root_path,
    alert: "You don't have permission to manage " \
           "#{resource.to_title.pluralize}"
  return false
end