From 5427d2af3a1bd9a5b571375b4aca2ccd9042b3b9 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 16:41:50 +0100 Subject: [PATCH 1/2] Update mix tasks since User.info.info_changeset is deprecated --- lib/mix/tasks/make_moderator.ex | 14 ++++++-------- lib/mix/tasks/set_admin.ex | 17 ++++++++--------- lib/mix/tasks/set_locked.ex | 18 ++++++++---------- 3 files changed, 22 insertions(+), 27 deletions(-) diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex index 15586dc30..9ea6c45c1 100644 --- a/lib/mix/tasks/make_moderator.ex +++ b/lib/mix/tasks/make_moderator.ex @@ -8,7 +8,7 @@ defmodule Mix.Tasks.SetModerator do """ use Mix.Task - import Mix.Ecto + import Ecto.Changeset alias Pleroma.{Repo, User} def run([nickname | rest]) do @@ -21,14 +21,12 @@ def run([nickname | rest]) do end with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_moderator", !!moderator) + info_cng = User.Info.admin_api_update(user.info, %{is_moderator: !!moderator}) + user_cng = Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) - - IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}") + IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}") else _ -> IO.puts("No local user #{nickname}") diff --git a/lib/mix/tasks/set_admin.ex b/lib/mix/tasks/set_admin.ex index d5ccf261b..9788e49b9 100644 --- a/lib/mix/tasks/set_admin.ex +++ b/lib/mix/tasks/set_admin.ex @@ -1,5 +1,6 @@ defmodule Mix.Tasks.SetAdmin do use Mix.Task + import Ecto.Changeset alias Pleroma.User @doc """ @@ -9,21 +10,19 @@ defmodule Mix.Tasks.SetAdmin do def run([nickname | rest]) do Application.ensure_all_started(:pleroma) - status = + admin = case rest do - [status] -> status == "true" + [admin] -> admin == "true" _ -> true end with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("is_admin", !!status) + info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin}) + user_cng = Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) - cng = User.info_changeset(user, %{info: info}) - {:ok, user} = User.update_and_set_cache(cng) - - IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}") + IO.puts("Admin status of #{nickname}: #{user.info.is_admin}") else _ -> IO.puts("No local user #{nickname}") diff --git a/lib/mix/tasks/set_locked.ex b/lib/mix/tasks/set_locked.ex index a154595ca..42d978599 100644 --- a/lib/mix/tasks/set_locked.ex +++ b/lib/mix/tasks/set_locked.ex @@ -8,13 +8,13 @@ defmodule Mix.Tasks.SetLocked do Example: ``mix set_locked lain`` """ - + use Mix.Task - import Mix.Ecto + import Ecto.Changeset alias Pleroma.{Repo, User} def run([nickname | rest]) do - ensure_started(Repo, []) + Application.ensure_all_started(:pleroma) locked = case rest do @@ -23,14 +23,12 @@ def run([nickname | rest]) do end with %User{local: true} = user <- User.get_by_nickname(nickname) do - info = - user.info - |> Map.put("locked", !!locked) + info_cng = User.Info.profile_update(user.info, %{locked: !!locked}) + user_cng = Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) - cng = User.info_changeset(user, %{info: info}) - user = Repo.update!(cng) - - IO.puts("locked status of #{nickname}: #{user.info["locked"]}") + IO.puts("Locked status of #{nickname}: #{user.info.locked}") else _ -> IO.puts("No local user #{nickname}") From c3519132dfdcd5f59c0ebe99fa8ab4b764ac4982 Mon Sep 17 00:00:00 2001 From: Rin Toshaka Date: Wed, 5 Dec 2018 16:44:15 +0100 Subject: [PATCH 2/2] Sorry --- lib/mix/tasks/make_moderator.ex | 7 +++++-- lib/mix/tasks/set_admin.ex | 7 +++++-- lib/mix/tasks/set_locked.ex | 9 ++++++--- 3 files changed, 16 insertions(+), 7 deletions(-) diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex index 9ea6c45c1..8dc0a04dd 100644 --- a/lib/mix/tasks/make_moderator.ex +++ b/lib/mix/tasks/make_moderator.ex @@ -22,8 +22,11 @@ def run([nickname | rest]) do with %User{local: true} = user <- User.get_by_nickname(nickname) do info_cng = User.Info.admin_api_update(user.info, %{is_moderator: !!moderator}) - user_cng = Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}") diff --git a/lib/mix/tasks/set_admin.ex b/lib/mix/tasks/set_admin.ex index 9788e49b9..ac26516f1 100644 --- a/lib/mix/tasks/set_admin.ex +++ b/lib/mix/tasks/set_admin.ex @@ -18,8 +18,11 @@ def run([nickname | rest]) do with %User{local: true} = user <- User.get_by_nickname(nickname) do info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin}) - user_cng = Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) IO.puts("Admin status of #{nickname}: #{user.info.is_admin}") diff --git a/lib/mix/tasks/set_locked.ex b/lib/mix/tasks/set_locked.ex index 42d978599..e93a63505 100644 --- a/lib/mix/tasks/set_locked.ex +++ b/lib/mix/tasks/set_locked.ex @@ -8,7 +8,7 @@ defmodule Mix.Tasks.SetLocked do Example: ``mix set_locked lain`` """ - + use Mix.Task import Ecto.Changeset alias Pleroma.{Repo, User} @@ -24,8 +24,11 @@ def run([nickname | rest]) do with %User{local: true} = user <- User.get_by_nickname(nickname) do info_cng = User.Info.profile_update(user.info, %{locked: !!locked}) - user_cng = Ecto.Changeset.change(user) - |> put_embed(:info, info_cng) + + user_cng = + Ecto.Changeset.change(user) + |> put_embed(:info, info_cng) + {:ok, user} = User.update_and_set_cache(user_cng) IO.puts("Locked status of #{nickname}: #{user.info.locked}")