This commit is contained in:
parent
b429a4dbb6
commit
e7d63b9b0a
5 changed files with 93 additions and 18 deletions
|
|
@ -10,10 +10,10 @@ defmodule MvWeb.MemberExportController do
|
|||
require Ash.Query
|
||||
import Ash.Expr
|
||||
|
||||
alias Mv.Membership.Member
|
||||
alias Mv.Membership.CustomField
|
||||
alias Mv.Membership.MembersCSV
|
||||
alias Mv.Authorization.Actor
|
||||
alias Mv.Membership.CustomField
|
||||
alias Mv.Membership.Member
|
||||
alias Mv.Membership.MembersCSV
|
||||
|
||||
@member_fields_allowlist Mv.Constants.member_fields() |> Enum.map(&Atom.to_string/1)
|
||||
@custom_field_prefix Mv.Constants.custom_field_prefix()
|
||||
|
|
@ -100,7 +100,9 @@ defmodule MvWeb.MemberExportController do
|
|||
|
||||
defp filter_valid_uuids(id_list) when is_list(id_list) do
|
||||
id_list
|
||||
|> Enum.filter(fn id -> is_binary(id) and match?({:ok, _}, Ecto.UUID.cast(id)) end)
|
||||
|> Enum.filter(fn id ->
|
||||
is_binary(id) and match?({:ok, _}, Ecto.UUID.cast(id))
|
||||
end)
|
||||
|> Enum.uniq()
|
||||
end
|
||||
|
||||
|
|
@ -130,14 +132,18 @@ defmodule MvWeb.MemberExportController do
|
|||
|> Ash.Query.filter(expr(id in ^custom_field_ids))
|
||||
|> Ash.Query.select([:id, :name, :value_type])
|
||||
|
||||
case Ash.read(query, actor: actor) do
|
||||
{:ok, custom_fields} ->
|
||||
by_id = build_custom_fields_by_id(custom_field_ids, custom_fields)
|
||||
{:ok, by_id}
|
||||
query
|
||||
|> Ash.read(actor: actor)
|
||||
|> handle_custom_fields_read_result(custom_field_ids)
|
||||
end
|
||||
|
||||
{:error, %Ash.Error.Forbidden{}} ->
|
||||
{:error, :forbidden}
|
||||
end
|
||||
defp handle_custom_fields_read_result({:ok, custom_fields}, custom_field_ids) do
|
||||
by_id = build_custom_fields_by_id(custom_field_ids, custom_fields)
|
||||
{:ok, by_id}
|
||||
end
|
||||
|
||||
defp handle_custom_fields_read_result({:error, %Ash.Error.Forbidden{}}, _custom_field_ids) do
|
||||
{:error, :forbidden}
|
||||
end
|
||||
|
||||
defp build_custom_fields_by_id(custom_field_ids, custom_fields) do
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue