View Source Rolex.Options (Rolex v0.1.1)

A module for validating options for permission-related actions.

These options make up a small domain-specific language ("DSL").

The grammar has three terms for scoping permissions:

* `:all` - a special atom for granting or denying ALL of something
* module - any module that defines a struct with an `id` field
* entity - any struct with an `id` key; e.g. `%User{id: 123}`

And only three* keywords:

* `role: <atom>` - any atom except `:all` or `:any`
* `to: <subject>` - what scope is being granted the role?
* `on: <object>` - which resources are being granted?
  • When revoking permissions, from is used in place of to

Summary

Functions

Validates options for performing action.

Returns a changeset for options used when creating permissions.

Returns a changeset for options used when revoking permissions.

Returns a changeset for options used when filtering permissions.

Functions

Link to this function

changeset(action, opts \\ [])

View Source

Validates options for performing action.

Link to this function

creating_changeset(opts)

View Source

Returns a changeset for options used when creating permissions.

Options:

* `role` - an atom
* `to` - `:all`, a module, or a struct with an `id` key
* `on` - `:all`, a module, or a struct with an `id` key
Link to this function

deleting_changeset(opts)

View Source

Returns a changeset for options used when revoking permissions.

Options:

* `role` - an atom
* `from` - `:all`, a module, a struct with an `id` key, or:
  * `:any` - will match ANY permission subject
  * `{:any, <module>}` - will match ANY permission subject of the named type
* `on` - `:all`, a module, a struct with an `id` key, or:
  * `:any` - will match ANY permission object
  * `{:any, <module>}` - will match ANY permission object of the named type
Link to this function

filtering_changeset(opts)

View Source

Returns a changeset for options used when filtering permissions.

Options:

* `role` - an atom
* `from` - `:all`, a module, a struct with an `id` key, or:
  * `:any` - will match ANY permission subject
  * `{:any, <module>}` - will match ANY permission subject of the named type
* `on` - `:all`, a module, a struct with an `id` key, or:
  * `:any` - will match ANY permission object
  * `{:any, <module>}` - will match ANY permission object of the named type