Document System Actor pattern in code guidelines

Add section explaining when and how to use system actor for systemic operations.
Include examples and distinction between user mode and system mode.
This commit is contained in:
Moritz 2026-01-20 22:09:22 +01:00
parent f1bb6a0f9a
commit a3cf8571ff
3 changed files with 73 additions and 8 deletions

View file

@ -79,7 +79,10 @@ defmodule Mv.Helpers.SystemActorTest do
|> Ash.load!(:role, domain: Mv.Accounts)
_ ->
Accounts.create_user!(%{email: admin_email}, upsert?: true, upsert_identity: :unique_email)
Accounts.create_user!(%{email: admin_email},
upsert?: true,
upsert_identity: :unique_email
)
|> Ash.Changeset.for_update(:update, %{})
|> Ash.Changeset.manage_relationship(:role, admin_role, type: :append_and_remove)
|> Ash.update!()
@ -152,6 +155,7 @@ defmodule Mv.Helpers.SystemActorTest do
end
admin_email = System.get_env("ADMIN_EMAIL") || "admin@localhost"
case Accounts.User
|> Ash.Query.filter(email == ^admin_email)
|> Ash.read_one(domain: Mv.Accounts) do