Configurable member field "required" flag and Vereinfacht-required fields closes #440 #441
1 changed files with 39 additions and 35 deletions
|
|
@ -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.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue