diff --git a/lib/philomena/users.ex b/lib/philomena/users.ex index a940ce70..252d67e7 100644 --- a/lib/philomena/users.ex +++ b/lib/philomena/users.ex @@ -518,6 +518,10 @@ defmodule Philomena.Users do unsubscribe_restricted_actors(user) end) |> Repo.transaction() + |> case do + {:ok, %{user: user}} -> {:ok, user} + {:error, :user, changeset, _} -> {:error, changeset} + end end defp clean_roles(nil), do: [] diff --git a/lib/philomena_web/controllers/admin/user_controller.ex b/lib/philomena_web/controllers/admin/user_controller.ex index 9952094a..fe31d2f4 100644 --- a/lib/philomena_web/controllers/admin/user_controller.ex +++ b/lib/philomena_web/controllers/admin/user_controller.ex @@ -15,7 +15,7 @@ defmodule PhilomenaWeb.Admin.UserController do id_field: "slug", preload: [:roles] - plug :load_roles when action in [:edit] + plug :load_roles when action in [:edit, :update] def index(conn, %{"q" => q}) do User @@ -62,10 +62,10 @@ defmodule PhilomenaWeb.Admin.UserController do {:ok, user} -> conn |> put_flash(:info, "User successfully updated.") - |> moderation_log(details: &log_details/3, data: user.user) - |> redirect(to: Routes.profile_path(conn, :show, conn.assigns.user)) + |> moderation_log(details: &log_details/3, data: user) + |> redirect(to: Routes.profile_path(conn, :show, user)) - {:error, %{user: changeset}} -> + {:error, changeset} -> render(conn, "edit.html", changeset: changeset) end end diff --git a/lib/philomena_web/templates/admin/user/_form.html.slime b/lib/philomena_web/templates/admin/user/_form.html.slime index bb9e4f8c..34275f4a 100644 --- a/lib/philomena_web/templates/admin/user/_form.html.slime +++ b/lib/philomena_web/templates/admin/user/_form.html.slime @@ -8,10 +8,14 @@ span.block__header__title Essential user details label.table-list__label .table-list__label__text Name: - .table-list__label__input = text_input f, :name, class: "input" + .table-list__label__input + = error_tag f, :name + = text_input f, :name, class: "input" label.table-list__label .table-list__label__text Email: - .table-list__label__input = text_input f, :email, class: "input" + .table-list__label__input + = error_tag f, :email + = text_input f, :email, class: "input" label.table-list__label .table-list__label__text Role: .table-list__label__input = select f, :role, ["user", "assistant", "moderator", "admin"], class: "input" diff --git a/lib/philomena_web/views/admin/user_view.ex b/lib/philomena_web/views/admin/user_view.ex index c502343e..db9e189f 100644 --- a/lib/philomena_web/views/admin/user_view.ex +++ b/lib/philomena_web/views/admin/user_view.ex @@ -26,7 +26,7 @@ defmodule PhilomenaWeb.Admin.UserView do id: input_id, checked_value: to_string(role.id), hidden_input: false, - checked: Enum.member?(Enum.map(input_value(form, field), & &1.id), role.id) + checked: Enum.member?(Enum.map(Map.get(form.data, field), & &1.id), role.id) ) content_tag(:li, class: "table-list__label") do