Use authorize?: false for integrity checks in validations

This commit is contained in:
Moritz 2026-01-24 01:42:15 +01:00 committed by Simon
parent b387897adb
commit ba5c982368
Signed by: simon
GPG key ID: 40E7A58C4AA1EDB2
2 changed files with 14 additions and 31 deletions

View file

@ -85,13 +85,11 @@ defmodule Mv.MembershipFees.MembershipFeeType do
if changeset.action_type == :destroy do
require Ash.Query
# Use system_actor for validation queries (systemic operation)
system_actor = Mv.Helpers.SystemActor.get_system_actor()
# Integrity check: count members without authorization (systemic operation)
member_count =
Mv.Membership.Member
|> Ash.Query.filter(membership_fee_type_id == ^changeset.data.id)
|> Ash.count!(actor: system_actor)
|> Ash.count!(authorize?: false)
if member_count > 0 do
{:error,
@ -111,13 +109,11 @@ defmodule Mv.MembershipFees.MembershipFeeType do
if changeset.action_type == :destroy do
require Ash.Query
# Use system_actor for validation queries (systemic operation)
system_actor = Mv.Helpers.SystemActor.get_system_actor()
# Integrity check: count cycles without authorization (systemic operation)
cycle_count =
Mv.MembershipFees.MembershipFeeCycle
|> Ash.Query.filter(membership_fee_type_id == ^changeset.data.id)
|> Ash.count!(actor: system_actor)
|> Ash.count!(authorize?: false)
if cycle_count > 0 do
{:error,
@ -137,13 +133,11 @@ defmodule Mv.MembershipFees.MembershipFeeType do
if changeset.action_type == :destroy do
require Ash.Query
# Use system_actor for validation queries (systemic operation)
system_actor = Mv.Helpers.SystemActor.get_system_actor()
# Integrity check: count settings without authorization (systemic operation)
setting_count =
Mv.Membership.Setting
|> Ash.Query.filter(default_membership_fee_type_id == ^changeset.data.id)
|> Ash.count!(actor: system_actor)
|> Ash.count!(authorize?: false)
if setting_count > 0 do
{:error,