CSV export: apply cycle_status_filter and boolean_filters when exporting all

This commit is contained in:
Moritz 2026-03-04 20:12:45 +01:00
parent d914f5aa22
commit d71d5881cf
Signed by: moritz
GPG key ID: 1020A035E5DD0824
3 changed files with 110 additions and 4 deletions

View file

@ -378,6 +378,33 @@ defmodule Mv.Membership.MemberExport do
end
end
@doc """
Applies export filters (cycle status and boolean custom field filters) when exporting "all" (no selected_ids).
Used by the CSV export controller so that "Export (all)" with active filters exports only the filtered members,
matching PDF export behavior.
- `members` - Loaded members (must have cycle data loaded when cycle_status_filter is used).
- `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.
"""
@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
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)
)
end
end
defp extract_list(params, key) do
case Map.get(params, key) do
list when is_list(list) -> list