Karta.Accounts.Scope (Karta v1.0.0)

Who is acting, and what they may do: the signed-in user and their role in each organisation. Every page and action of the admin interface gets one (current_scope) and asks can?/3 before it shows or changes anything.

Roles, per organisation (Karta.Accounts.Membership):

Actionowneradminmemberread-only
:view✓✓✓✓
:manage_messages✓✓✓
:manage_credentials✓✓✓
:manage_servers✓✓
:manage_inbound✓✓
:manage_webhooks✓✓
:manage_domains✓✓
:manage_members✓✓
:manage_owners✓
:manage_organisation✓

:view covers the organisation, its servers, domains, credentials (never their secrets), messages with their bodies, deliveries, received mail with its deliveries, and webhooks with their deliveries (never their secrets). :manage_inbound adds, changes and removes a server's routes and endpoints (never showing their secrets again), and sends a received message's failed or waiting delivery again. :manage_webhooks adds, changes, tests and removes a server's webhooks, rotates their secrets and sends their deliveries again. :manage_members adds, removes and changes members below owner; :manage_owners makes or removes owners. :manage_organisation renames or deletes the organisation.

Instance administrators (admin users) may do everything in every organisation, and they alone may create organisations (can?(scope, :create_organisation)).

Summary

Functions

True for an instance administrator.

The actions a role allows.

True when the scope may take an action that belongs to no organisation.

True when the scope may take action in the organisation.

A scope for user and their memberships ([Membership]).

The user's role in the organisation (nil when not a member).

Types

action()

@type action() ::
  :view
  | :manage_messages
  | :manage_credentials
  | :manage_servers
  | :manage_inbound
  | :manage_webhooks
  | :manage_domains
  | :manage_members
  | :manage_owners
  | :manage_organisation

role()

@type role() :: :owner | :admin | :member | :read_only

t()

@type t() :: %Karta.Accounts.Scope{
  roles: %{required(binary()) => role()},
  user: Karta.Accounts.User.t() | nil
}

Functions

admin?(scope)

@spec admin?(t() | nil) :: boolean()

True for an instance administrator.

allowed(role)

@spec allowed(role()) :: [action()]

The actions a role allows.

can?(scope, atom)

@spec can?(t() | nil, :create_organisation) :: boolean()

True when the scope may take an action that belongs to no organisation.

can?(scope, action, organisation_id)

@spec can?(t() | nil, action(), binary()) :: boolean()

True when the scope may take action in the organisation.

new(user, memberships)

A scope for user and their memberships ([Membership]).

role(arg1, organisation_id)

@spec role(t() | nil, binary()) :: role() | nil

The user's role in the organisation (nil when not a member).