Member: skip required custom fields validation for set_vereinfacht_contact_id
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/promote/production Build is passing

Validation runs only for create_member and update_member so Vereinfacht
sync (which only sets vereinfacht_contact_id) no longer fails with
Required custom fields missing.
This commit is contained in:
Moritz 2026-02-23 23:02:27 +01:00
parent e9ed61a8fd
commit b3b8b31c0f
Signed by: moritz
GPG key ID: 1020A035E5DD0824

View file

@ -500,50 +500,54 @@ defmodule Mv.Membership.Member do
end end
end end
# Validate required custom fields (actor from validation context only; no fallback) # Validate required custom fields (actor from validation context only; no fallback).
# Only for create_member/update_member; skip for set_vereinfacht_contact_id (internal sync
# only sets vereinfacht_contact_id; custom fields were already validated and saved).
validate fn changeset, context -> validate fn changeset, context ->
provided_values = provided_custom_field_values(changeset) provided_values = provided_custom_field_values(changeset)
actor = context.actor actor = context.actor
case Mv.Membership.list_required_custom_fields(actor: actor) do case Mv.Membership.list_required_custom_fields(actor: actor) do
{:ok, required_custom_fields} -> {:ok, required_custom_fields} ->
missing_fields = missing_required_fields(required_custom_fields, provided_values) missing_fields =
missing_required_fields(required_custom_fields, provided_values)
if Enum.empty?(missing_fields) do if Enum.empty?(missing_fields) do
:ok :ok
else else
build_custom_field_validation_error(missing_fields) build_custom_field_validation_error(missing_fields)
end end
{:error, %Ash.Error.Forbidden{}} -> {:error, %Ash.Error.Forbidden{}} ->
Logger.warning( Logger.warning(
"Required custom fields validation: actor not authorized to read CustomField" "Required custom fields validation: actor not authorized to read CustomField"
) )
{:error, {:error,
field: :custom_field_values, field: :custom_field_values,
message: message:
"You are not authorized to perform this action. Please sign in again or contact support."} "You are not authorized to perform this action. Please sign in again or contact support."}
{:error, :missing_actor} -> {:error, :missing_actor} ->
Logger.warning("Required custom fields validation: no actor in context") Logger.warning("Required custom fields validation: no actor in context")
{:error, {:error,
field: :custom_field_values, field: :custom_field_values,
message: message:
"You are not authorized to perform this action. Please sign in again or contact support."} "You are not authorized to perform this action. Please sign in again or contact support."}
{:error, error} -> {:error, error} ->
Logger.error( Logger.error(
"Failed to load custom fields for validation: #{inspect(error)}. Required field validation cannot be performed." "Failed to load custom fields for validation: #{inspect(error)}. Required field validation cannot be performed."
) )
{:error, {:error,
field: :custom_field_values, field: :custom_field_values,
message: message:
"Unable to validate required custom fields. Please try again or contact support."} "Unable to validate required custom fields. Please try again or contact support."}
end end
end end,
where: [action_is([:create_member, :update_member])]
# Validate member fields that are marked as required in settings or by Vereinfacht. # Validate member fields that are marked as required in settings or by Vereinfacht.
# When settings cannot be loaded, we still enforce email + Vereinfacht-required fields. # When settings cannot be loaded, we still enforce email + Vereinfacht-required fields.