refactor: simplify system role deletion validation
Remove redundant action_type check since validation already runs only on destroy actions. Add field to error for better error handling.
This commit is contained in:
parent
9bb0fe5e37
commit
557eb4d27d
1 changed files with 5 additions and 8 deletions
|
|
@ -88,14 +88,11 @@ defmodule Mv.Authorization.Role do
|
|||
message: "must be one of: own_data, read_only, normal_user, admin"
|
||||
|
||||
validate fn changeset, _context ->
|
||||
if changeset.action_type == :destroy do
|
||||
if changeset.data.is_system_role do
|
||||
{:error,
|
||||
message:
|
||||
"Cannot delete system role. System roles are required for the application to function."}
|
||||
else
|
||||
:ok
|
||||
end
|
||||
if changeset.data.is_system_role do
|
||||
{:error,
|
||||
field: :is_system_role,
|
||||
message:
|
||||
"Cannot delete system role. System roles are required for the application to function."}
|
||||
else
|
||||
:ok
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue