Hide system actor from user list and block show/edit
Index: filter out SystemActor.system_user_email() in query. Show/Form: redirect to /users with flash when viewing or editing system actor user. Index format_error: handle Ash errors without :message field.
This commit is contained in:
parent
b7f37c80bd
commit
8ad5201e1a
3 changed files with 47 additions and 9 deletions
|
|
@ -266,10 +266,31 @@ defmodule MvWeb.UserLive.Form do
|
|||
|
||||
user =
|
||||
case params["id"] do
|
||||
nil -> nil
|
||||
id -> Ash.get!(Mv.Accounts.User, id, domain: Mv.Accounts, load: [:member], actor: actor)
|
||||
nil ->
|
||||
nil
|
||||
|
||||
id ->
|
||||
loaded =
|
||||
Ash.get!(Mv.Accounts.User, id, domain: Mv.Accounts, load: [:member], actor: actor)
|
||||
|
||||
if to_string(loaded.email) == Mv.Helpers.SystemActor.system_user_email() do
|
||||
{:redirect, loaded}
|
||||
else
|
||||
loaded
|
||||
end
|
||||
end
|
||||
|
||||
if match?({:redirect, _}, user) do
|
||||
{:ok,
|
||||
socket
|
||||
|> put_flash(:error, gettext("This user cannot be edited."))
|
||||
|> push_navigate(to: ~p"/users")}
|
||||
else
|
||||
mount_continue(user, params, socket)
|
||||
end
|
||||
end
|
||||
|
||||
defp mount_continue(user, params, socket) do
|
||||
action = if is_nil(user), do: gettext("New"), else: gettext("Edit")
|
||||
page_title = action <> " " <> gettext("User")
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue