CommandedAggregateless.AuthSubject (commanded_aggregateless v1.0.0)

Copy Markdown

Represents an actor that is attempting to execute a command or a query

Summary

Types

Map representation of an AuthSubject

The unique identifier of the entity that was cast to an AuthSubject

A permission that can be granted to an AuthSubject

List of permissions that have been granted to the auth subject

The original entity that was cast to an AuthSubject

t()

Functions

Returns an AuthSubject that represents an anonymous user

Is the given value convertible to an AuthSubject?

Check if the AuthSubject satisfies the given permission set

Creates a new AuthSubject from the given data.

Creates a new AuthSubject from the given data.

Compares two datum to see if they convert to the same AuthSubject

Returns the "system user" to be used by internal processes that are ot triggered by a specific user.

Returns the list of all valid permissions that have been defined.

Types

as_map()

@type as_map() :: %{source: source(), id: id(), permissions: permissions()}

Map representation of an AuthSubject

id()

@type id() :: binary()

The unique identifier of the entity that was cast to an AuthSubject

permission()

@type permission() :: String.t()

A permission that can be granted to an AuthSubject

permissions()

@type permissions() :: [permission() | permissions()]

List of permissions that have been granted to the auth subject

source()

@type source() :: String.t()

The original entity that was cast to an AuthSubject

t()

@type t() :: %CommandedAggregateless.AuthSubject{
  id: id(),
  permissions: permissions(),
  source: source()
}

Functions

anonymous_user()

@spec anonymous_user() :: t()

Returns an AuthSubject that represents an anonymous user

auth_subject?(value)

@spec auth_subject?(any()) :: boolean()

Is the given value convertible to an AuthSubject?

convert(data)

See CommandedAggregateless.AuthSubject.Conversion.convert/1.

has_permission?(auth_subject, permissions)

@spec has_permission?(any(), atom() | permission() | [permission()]) :: boolean()

Check if the AuthSubject satisfies the given permission set

A permission set can consist of one or more permissions with the following formats:

  • "permission_a" - the AuthSubject must have permission_a

  • ["permission_a", "permission_b"] - the AuthSubject must have either permission_a or permission_b

  • [["permission_a", "permission_b"]] - the AuthSubject must have both permission_a and permission_b

  • [["permission_a", "permission_b"], "permission_c"] - the AuthSubject must have either permission_c or both permission_a and permission_b

new(attrs)

@spec new(source :: CommandedAggregateless.AuthSubject.Conversion.t()) ::
  {:ok, t()} | {:error, {:invalid_auth_subject, keyword(keyword(String.t()))}}

Creates a new AuthSubject from the given data.

Returns {:ok, auth_subject} if the data is valid, otherwise {:error, message}.

new!(attributes)

Creates a new AuthSubject from the given data.

Raises ArgumentError if the data is invalid.

same?(term_1, term_2)

Compares two datum to see if they convert to the same AuthSubject

system_user()

@spec system_user() :: t()

Returns the "system user" to be used by internal processes that are ot triggered by a specific user.

valid?(self)

valid_permissions()

@spec valid_permissions() :: [String.t()]

Returns the list of all valid permissions that have been defined.

validate(struct)

See CommandedAggregateless.StructValidation.validate/1.

validate_permissions(permissions)

@spec validate_permissions(term()) :: :ok | {:error, String.t()}