Lightning.Policies.Collections (Lightning v2.19.0-pre)

View Source

The Bodyguard Policy module for Collections.

Access to collections is controlled by the project the collection belongs to.

Read access (:access_collection) is allowed for any project member, or for a run that belongs to the project (via its workflow).

Access is gated on the caller's project role, mirroring the read/write asymmetry used elsewhere in the app:

  • :access_collection (read: get, stream, download) is allowed for any project member, or for a run that belongs to the project.
  • :put_collection_item / :delete_collection_item (put, put_all and single-key delete) require at least the :editor role.
  • :delete_all_collection_items (wiping/matching-delete of a collection's items) requires :owner or :admin.
  • :manage_collection (creating, renaming or deleting the collection itself) requires :owner or :admin. Creation is authorized against the %Project{}, since no collection exists yet.

The *_collection_item(s) actions target the key-value entries exposed by the Collections API; :manage_collection targets the collection record itself.

Runs retain full access to collections within their own project, since jobs need to read and mutate collection data while executing.

Summary

Types

actions()

@type actions() ::
  :access_collection
  | :put_collection_item
  | :delete_collection_item
  | :delete_all_collection_items
  | :manage_collection

Functions

authorize(action, user, collection)

@spec authorize(
  actions(),
  Lightning.Accounts.User.t() | Lightning.Run.t(),
  Lightning.Collections.Collection.t() | Lightning.Projects.Project.t()
) :: :ok | {:error, :unauthorized} | boolean()

Callback implementation for Bodyguard.Policy.authorize/3.