CSV export: robust apply_export_filters, single custom_field_ids_union, string boolean_filters, more tests
Some checks reported errors
continuous-integration/drone/push Build was killed

This commit is contained in:
Moritz 2026-03-04 20:50:52 +01:00
parent d71d5881cf
commit fc7b035123
Signed by: moritz
GPG key ID: 1020A035E5DD0824
3 changed files with 176 additions and 18 deletions

View file

@ -388,20 +388,25 @@ defmodule Mv.Membership.MemberExport do
- `opts` - Map with `:selected_ids`, `:cycle_status_filter`, `:show_current_cycle`, `:boolean_filters`.
- `custom_fields_by_id` - Map of custom field id => custom field struct (for boolean filter resolution).
When `opts.selected_ids` is not empty, returns `members` unchanged. Otherwise applies
cycle status filter and boolean custom field filters.
When `opts.selected_ids` is not empty, returns `members` unchanged (selected_ids
override filters). Otherwise applies cycle status filter and boolean custom field filters.
Uses `Map.get(opts, :selected_ids, [])` so that `nil` or a missing key is treated as
"export all" and filters are applied.
"""
@spec apply_export_filters([struct()], map(), map()) :: [struct()]
def apply_export_filters(members, opts, custom_fields_by_id) do
if opts[:selected_ids] != [] do
members
else
selected_ids = Map.get(opts, :selected_ids, [])
if Enum.empty?(selected_ids) do
members
|> apply_cycle_status_filter(opts[:cycle_status_filter], opts[:show_current_cycle])
|> Index.apply_boolean_custom_field_filters(
Map.get(opts, :boolean_filters, %{}),
Map.values(custom_fields_by_id)
)
else
members
end
end