Join requests cannot be approved when any custom field is required; harden the join flow end to end #645

Closed
opened 2026-11-09 10:08:46 +01:00 by simon · 0 comments
Owner

Problem

A club with required custom fields cannot approve any join request. Every approval fails with the generic flash "Failed to approve join request." Rejecting still works. Server log:

Failed to approve join request <id>: %Ash.Error.Invalid{... Mv.Membership.Member.create_member ...
  InvalidArgument{field: :custom_field_values, message: "Required custom fields missing: Gewünschtes Beitrittsdatum, Mitgliedsform"}

The values are present in the request's form_data, keyed by custom field UUID and in a valid format (:date → "2026-03-21", :string → "Ordentlich").

Root causes found so far

  1. Key mismatch (blocker). JoinFlow.build_member_attrs/1 builds %{custom_field_id: key, value: to_string(value)} with atom keys and a bare string value. Member.Validations.RequiredCustomFields.extract_value_from_arg/2 reads string keys ("custom_field_id", "value"). Every provided value is lost, so every required custom field is reported missing. Present since approval was introduced (86d9242d).
  2. Values are not cast per value_type. The join form stores boolean custom fields as "on" / "off", which Ash.Type.Boolean rejects ({:error, "is invalid"}). The affected club has five optional boolean fields in its join form, including consent fields ("Datenschutzerklärung akzeptiert", "Zustimmung Satzung und Beitrag"). Once (1) is fixed, approval is expected to fail on these, and consent values must not be lost. Empty strings are passed through instead of being skipped.
  3. Stale custom field ids in form_data. A request carries a value for a custom field that no longer exists (deleted after submission). build_member_attrs/1 forwards every UUID-shaped key, so creating the custom field value for a deleted field will fail.
  4. Configuration contradiction is allowed silently. A custom field can be required on the member but optional in the join form (join_form_field_required); here "Gewünschtes Beitrittsdatum" is required: true while its join description says "optional". Requests submitted without it can never be approved, and nothing warns the admin.
  5. No error detail in the UI. JoinRequestLive.Show logs the error but shows only a generic flash.

Hardening: test the join flow thoroughly before building further features on it

Cover the full path public join form → submit → confirm → approve → member, through the real LiveView, not only the domain functions. At least:

  • Custom field types: string, integer, boolean, date, email — each × required on member (yes/no) × required in join form (yes/no) × filled/empty.
  • Checkbox semantics: checked ("on"), unchecked ("off" or absent), and the resulting member value; consent fields must arrive on the member.
  • Member fields from the form: date fields, postal code, phone, umlauts, long input; the member carries exactly what was submitted.
  • Configuration drift after submission: field added to / removed from the join form, required flag changed, type changed, custom field deleted.
  • Duplicates: member with the same email exists; pending request with the same email exists.
  • Lifecycle: approve twice, approve after reject, two reviewers approving concurrently; unconfirmed or expired request.
  • Reviewer permissions: admin, normal_user, own_data (approve refused cleanly).
  • Failure UX: every approval failure shows the reviewer an actionable reason (e.g. which required field is missing).

A property test over custom field type × submitted value (including "" and checkbox values) replaces hand-picked examples for the casting logic.

Acceptance criteria

  • A join request whose form_data contains valid values for all required custom fields is approved, and the member carries those values with correct types.
  • Boolean, date, integer and empty values from the join form are converted correctly; empty optional values create no custom field value.
  • Values for custom fields that no longer exist are ignored without failing the approval.
  • When approval fails, the reviewer sees the reason.
  • The settings prevent or clearly warn about a custom field that is required on the member but optional in the join form.
  • The scenarios above are covered by tests.
## Problem A club with required custom fields cannot approve any join request. Every approval fails with the generic flash "Failed to approve join request." Rejecting still works. Server log: ``` Failed to approve join request <id>: %Ash.Error.Invalid{... Mv.Membership.Member.create_member ... InvalidArgument{field: :custom_field_values, message: "Required custom fields missing: Gewünschtes Beitrittsdatum, Mitgliedsform"} ``` The values *are* present in the request's `form_data`, keyed by custom field UUID and in a valid format (`:date` → `"2026-03-21"`, `:string` → `"Ordentlich"`). ## Root causes found so far 1. **Key mismatch (blocker).** `JoinFlow.build_member_attrs/1` builds `%{custom_field_id: key, value: to_string(value)}` with atom keys and a bare string value. `Member.Validations.RequiredCustomFields.extract_value_from_arg/2` reads string keys (`"custom_field_id"`, `"value"`). Every provided value is lost, so every required custom field is reported missing. Present since approval was introduced (`86d9242d`). 2. **Values are not cast per `value_type`.** The join form stores boolean custom fields as `"on"` / `"off"`, which `Ash.Type.Boolean` rejects (`{:error, "is invalid"}`). The affected club has five optional boolean fields in its join form, including consent fields ("Datenschutzerklärung akzeptiert", "Zustimmung Satzung und Beitrag"). Once (1) is fixed, approval is expected to fail on these, and consent values must not be lost. Empty strings are passed through instead of being skipped. 3. **Stale custom field ids in `form_data`.** A request carries a value for a custom field that no longer exists (deleted after submission). `build_member_attrs/1` forwards every UUID-shaped key, so creating the custom field value for a deleted field will fail. 4. **Configuration contradiction is allowed silently.** A custom field can be required on the member but optional in the join form (`join_form_field_required`); here "Gewünschtes Beitrittsdatum" is `required: true` while its join description says "optional". Requests submitted without it can never be approved, and nothing warns the admin. 5. **No error detail in the UI.** `JoinRequestLive.Show` logs the error but shows only a generic flash. ## Hardening: test the join flow thoroughly before building further features on it Cover the full path *public join form → submit → confirm → approve → member*, through the real LiveView, not only the domain functions. At least: - **Custom field types:** string, integer, boolean, date, email — each × required on member (yes/no) × required in join form (yes/no) × filled/empty. - **Checkbox semantics:** checked (`"on"`), unchecked (`"off"` or absent), and the resulting member value; consent fields must arrive on the member. - **Member fields from the form:** date fields, postal code, phone, umlauts, long input; the member carries exactly what was submitted. - **Configuration drift after submission:** field added to / removed from the join form, `required` flag changed, type changed, custom field deleted. - **Duplicates:** member with the same email exists; pending request with the same email exists. - **Lifecycle:** approve twice, approve after reject, two reviewers approving concurrently; unconfirmed or expired request. - **Reviewer permissions:** admin, `normal_user`, `own_data` (approve refused cleanly). - **Failure UX:** every approval failure shows the reviewer an actionable reason (e.g. which required field is missing). A property test over *custom field type × submitted value* (including `""` and checkbox values) replaces hand-picked examples for the casting logic. ## Acceptance criteria - A join request whose `form_data` contains valid values for all required custom fields is approved, and the member carries those values with correct types. - Boolean, date, integer and empty values from the join form are converted correctly; empty optional values create no custom field value. - Values for custom fields that no longer exist are ignored without failing the approval. - When approval fails, the reviewer sees the reason. - The settings prevent or clearly warn about a custom field that is required on the member but optional in the join form. - The scenarios above are covered by tests.
simon closed this issue 2026-11-09 22:54:42 +01:00
Sign in to join this conversation.
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
local-it/mitgliederverwaltung#645
No description provided.