Pass actor through CycleGenerator so seeds can use admin
- get_actor(opts): use opts[:actor] or system actor - load_member, do_generate_cycles, create_cycles pass opts - Seeds pass admin_user_with_role for Ash.load! and cycle updates
This commit is contained in:
parent
6e309622a0
commit
a263cb4954
2 changed files with 34 additions and 28 deletions
|
|
@ -379,10 +379,9 @@ Enum.each(member_attrs_list, fn member_attrs ->
|
|||
|
||||
# Generate cycles if member has a fee type
|
||||
if final_member.membership_fee_type_id do
|
||||
# Load member with cycles to check if they already exist
|
||||
# Load member with cycles to check if they already exist (actor required for auth)
|
||||
member_with_cycles =
|
||||
final_member
|
||||
|> Ash.load!(:membership_fee_cycles)
|
||||
Ash.load!(final_member, :membership_fee_cycles, actor: admin_user_with_role)
|
||||
|
||||
# Only generate if no cycles exist yet (to avoid duplicates on re-run)
|
||||
cycles =
|
||||
|
|
@ -427,7 +426,7 @@ Enum.each(member_attrs_list, fn member_attrs ->
|
|||
if cycle.status != status do
|
||||
cycle
|
||||
|> Ash.Changeset.for_update(:update, %{status: status})
|
||||
|> Ash.update!(actor: admin_user_with_role)
|
||||
|> Ash.update!(actor: admin_user_with_role, domain: Mv.MembershipFees)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
@ -542,10 +541,9 @@ Enum.with_index(linked_members)
|
|||
|
||||
# Generate cycles for linked members
|
||||
if final_member.membership_fee_type_id do
|
||||
# Load member with cycles to check if they already exist
|
||||
# Load member with cycles to check if they already exist (actor required for auth)
|
||||
member_with_cycles =
|
||||
final_member
|
||||
|> Ash.load!(:membership_fee_cycles)
|
||||
Ash.load!(final_member, :membership_fee_cycles, actor: admin_user_with_role)
|
||||
|
||||
# Only generate if no cycles exist yet (to avoid duplicates on re-run)
|
||||
cycles =
|
||||
|
|
@ -575,7 +573,7 @@ Enum.with_index(linked_members)
|
|||
if cycle.status != status do
|
||||
cycle
|
||||
|> Ash.Changeset.for_update(:update, %{status: status})
|
||||
|> Ash.update!()
|
||||
|> Ash.update!(actor: admin_user_with_role, domain: Mv.MembershipFees)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue