feat(accounts): block update/destroy on system-actor user
Validation prevents modifying system actor user (required for internal ops).
This commit is contained in:
parent
7d33acde9f
commit
d98b32af8d
1 changed files with 13 additions and 4 deletions
|
|
@ -175,6 +175,13 @@ defmodule Mv.Accounts.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Internal update used only by SystemActor/bootstrap and tests to assign role to system user.
|
||||||
|
# Not protected by system-user validation so bootstrap can run.
|
||||||
|
update :update_internal do
|
||||||
|
accept []
|
||||||
|
require_atomic? false
|
||||||
|
end
|
||||||
|
|
||||||
# Admin action for direct password changes in admin panel
|
# Admin action for direct password changes in admin panel
|
||||||
# Uses the official Ash Authentication HashPasswordChange with correct context
|
# Uses the official Ash Authentication HashPasswordChange with correct context
|
||||||
update :admin_set_password do
|
update :admin_set_password do
|
||||||
|
|
@ -366,18 +373,20 @@ defmodule Mv.Accounts.User do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Prevent deletion of the system actor user (required for internal operations)
|
# Prevent modification of the system actor user (required for internal operations).
|
||||||
|
# Block update/destroy on UI-exposed actions only; :update_internal is used by bootstrap/tests.
|
||||||
validate fn changeset, _context ->
|
validate fn changeset, _context ->
|
||||||
if to_string(changeset.data.email) == Mv.Helpers.SystemActor.system_user_email() do
|
if Mv.Helpers.SystemActor.system_user?(changeset.data) do
|
||||||
{:error,
|
{:error,
|
||||||
field: :email,
|
field: :email,
|
||||||
message:
|
message:
|
||||||
"Cannot delete system actor user. This user is required for internal operations."}
|
"Cannot modify system actor user. This user is required for internal operations."}
|
||||||
else
|
else
|
||||||
:ok
|
:ok
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
on: [:destroy]
|
on: [:update, :destroy],
|
||||||
|
where: [action_is([:update, :update_user, :admin_set_password, :destroy])]
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_oidc_id_present(changeset, _context) do
|
def validate_oidc_id_present(changeset, _context) do
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue