rampart v1.0.1 Rampart.Controller

The Controller module provides functions that are to be used by controllers in your application. These may not strictly be controllers, but they are for the part of your application that will handle the request, and trigger the authorisation.

Summary

Types

A resource can be anything and is application specific, but in most scenarios it will most likely be a module, or a struct

Functions

Authorizes the supplied resource. This should be called in the controller action, as Rampart will automatically determine which policy to use, and what action was invoked

Authorizes the supplied resource. Unlike authorize/2, this function allows you to specify which policy action should be used, rather than having it determined by Rampart. This is useful if you have a number of actions that all require the same permission

Types

resource()
resource() :: any

A resource can be anything and is application specific, but in most scenarios it will most likely be a module, or a struct.

Functions

authorize!(conn, resource) (macro)
authorize!(term, Plug.Conn.t, resource) :: none

Authorizes the supplied resource. This should be called in the controller action, as Rampart will automatically determine which policy to use, and what action was invoked.

If you want to specify a different policy action, see authorize!/3

authorize!(conn, resource, action) (macro)
authorize!(term, Plug.Conn.t, resource, atom) :: none

Authorizes the supplied resource. Unlike authorize/2, this function allows you to specify which policy action should be used, rather than having it determined by Rampart. This is useful if you have a number of actions that all require the same permission.

For example, if you had a photo controller, which had an edit and a resize action, both of these actions are forms of editing. So your resize action may call

photo = Repo.get(MyApp.Photo, id)
authorize!(photo, :edit?)

And your policy would not need a resize/2 function defined.