Commit 503f5be6eea859b9b38ea443b930665a6145a04e

Thomas de Grivel 2021-12-15T09:11:03

[admin] fix user update

diff --git a/lib/kmxgit/user_manager/user.ex b/lib/kmxgit/user_manager/user.ex
index 8bdb57f..1302025 100644
--- a/lib/kmxgit/user_manager/user.ex
+++ b/lib/kmxgit/user_manager/user.ex
@@ -59,6 +59,16 @@ defmodule Kmxgit.UserManager.User do
     |> unique_constraint(:email)
   end
 
+  defp maybe_validate_password(changeset, opts) do
+    p = changeset.changes[:password]
+    if p && p != "" do
+      changeset
+      |> validate_password(opts)
+    else
+      changeset
+    end
+  end
+
   defp validate_password(changeset, opts) do
     changeset
     |> validate_required([:password])
@@ -174,7 +184,7 @@ defmodule Kmxgit.UserManager.User do
     user
     |> cast(attrs, [:deploy_only, :description, :email, :is_admin, :name, :password, :ssh_keys])
     |> validate_email()
-    |> validate_password(opts)
+    |> maybe_validate_password(opts)
     |> common_changeset()
   end
 
diff --git a/lib/kmxgit_web/controllers/admin/user_controller.ex b/lib/kmxgit_web/controllers/admin/user_controller.ex
index 258daa6..4aea7ae 100644
--- a/lib/kmxgit_web/controllers/admin/user_controller.ex
+++ b/lib/kmxgit_web/controllers/admin/user_controller.ex
@@ -81,6 +81,7 @@ defmodule KmxgitWeb.Admin.UserController do
           conn
           |> redirect(to: Routes.admin_user_path(conn, :show, user1))
         {:error, changeset} ->
+          IO.inspect(changeset)
           conn
           |> assign(:changeset, changeset)
           |> assign(:user, user)