Commit 8a1fa398 authored by Mikko Ahlroth's avatar Mikko Ahlroth

Refactor with statement to just get rid of warnings instead

parent 747556d1
Pipeline #42763391 passed with stages
in 8 minutes and 22 seconds
......@@ -62,21 +62,7 @@ defmodule CodeStatsWeb.PreferencesController do
|> redirect(to: Routes.preferences_path(conn, :edit))
else
err ->
# In the case below, the compiler and dialyzer will warn about the clauses. That is an
# Elixir bug related to the with construct, so the warnings are bogus.
# See: https://github.com/elixir-lang/elixir/issues/6738
error_changeset =
case err do
{:old_pass, false} ->
# We need to add an action to the changeset so that Phoenix will display the error,
# otherwise it will think the changeset was not processed (as it has not been passed
# to any Repo call) and will not show the errors
%{password_changeset | action: :update}
|> Ecto.Changeset.add_error(:old_password, "does not match your current password")
{:updated, cset} ->
cset
end
error_changeset = get_password_error_cset(err, password_changeset)
conn
|> common_edit_assigns()
......@@ -101,6 +87,16 @@ defmodule CodeStatsWeb.PreferencesController do
AuthUtils.delete_user_action(conn, params, {&Routes.preferences_path/2, :edit})
end
defp get_password_error_cset({:old_pass, false}, orig_changeset) do
# We need to add an action to the changeset so that Phoenix will display the error,
# otherwise it will think the changeset was not processed (as it has not been passed
# to any Repo call) and will not show the errors
%{orig_changeset | action: :update}
|> Ecto.Changeset.add_error(:old_password, "does not match your current password")
end
defp get_password_error_cset({:updated, cset}, _), do: cset
# Common edit assigns, including empty changesets that will be overridden in specific clauses
defp common_edit_assigns(conn) do
user_data = AuthUtils.get_current_user(conn)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment