refactor: address review comments for join request settings
This commit is contained in:
parent
05e2a298fe
commit
21812542ad
6 changed files with 29 additions and 15 deletions
|
|
@ -60,6 +60,10 @@ defmodule Mv.Membership.Setting do
|
|||
domain: Mv.Membership,
|
||||
data_layer: AshPostgres.DataLayer
|
||||
|
||||
# Used in join_form_field_ids validation (compile-time to avoid recompiling regex and list on every validation)
|
||||
@uuid_pattern ~r/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
||||
@valid_join_form_member_fields Mv.Constants.member_fields() |> Enum.map(&Atom.to_string/1)
|
||||
|
||||
postgres do
|
||||
table "settings"
|
||||
repo Mv.Repo
|
||||
|
|
@ -255,16 +259,10 @@ defmodule Mv.Membership.Setting do
|
|||
field_ids = Ash.Changeset.get_attribute(changeset, :join_form_field_ids)
|
||||
|
||||
if is_list(field_ids) and field_ids != [] do
|
||||
valid_member_fields =
|
||||
Mv.Constants.member_fields() |> Enum.map(&Atom.to_string/1)
|
||||
|
||||
uuid_pattern =
|
||||
~r/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
|
||||
|
||||
invalid_ids =
|
||||
Enum.reject(field_ids, fn id ->
|
||||
is_binary(id) and
|
||||
(id in valid_member_fields or Regex.match?(uuid_pattern, id))
|
||||
(id in @valid_join_form_member_fields or Regex.match?(@uuid_pattern, id))
|
||||
end)
|
||||
|
||||
if Enum.empty?(invalid_ids) do
|
||||
|
|
@ -442,6 +440,7 @@ defmodule Mv.Membership.Setting do
|
|||
|
||||
attribute :join_form_field_ids, {:array, :string} do
|
||||
allow_nil? true
|
||||
default []
|
||||
public? true
|
||||
|
||||
description "Ordered list of field IDs shown on the join form. Each entry is a member field name (e.g. 'email') or a custom field UUID. Email is always present after normalization."
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue