feat: relate user and member

This commit is contained in:
Moritz 2025-08-05 17:17:28 +02:00
parent b7f0060358
commit d4c7af558d
Signed by: moritz
GPG key ID: 1020A035E5DD0824
8 changed files with 167 additions and 12 deletions

View file

@ -5,7 +5,8 @@ defmodule Mv.Accounts.User do
use Ash.Resource,
domain: Mv.Accounts,
data_layer: AshPostgres.DataLayer,
extensions: [AshAuthentication]
extensions: [AshAuthentication],
notifiers: [Mv.Accounts.User.MemberCreationNotifier]
# authorizers: [Ash.Policy.Authorizer]
@ -64,11 +65,16 @@ defmodule Mv.Accounts.User do
defaults [:read, :create, :destroy, :update]
create :create_user do
accept [:email]
accept [:email, :member_id]
argument :member, :map
change manage_relationship(:member, type: :create)
end
update :update_user do
accept [:email]
require_atomic? false
accept [:email, :member_id]
argument :member, :map
change manage_relationship(:member, on_match: :update, on_no_match: :create)
end
# Admin action for direct password changes in admin panel
@ -152,6 +158,7 @@ defmodule Mv.Accounts.User do
identities do
identity :unique_email, [:email]
identity :unique_oidc_id, [:oidc_id]
identity :unique_member_id, [:member_id]
end
# You can customize this if you wish, but this is a safe default that