Merge branch 'fix/mix-tasks-userinfo' into 'develop'
Update mix tasks that use User.info.info_changeset since it is deprecated See merge request pleroma/pleroma!503
This commit is contained in:
commit
991b62cb4d
3 changed files with 27 additions and 23 deletions
|
@ -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,15 @@ defmodule Mix.Tasks.SetModerator 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})
|
||||
|
||||
cng = User.info_changeset(user, %{info: info})
|
||||
{:ok, user} = User.update_and_set_cache(cng)
|
||||
user_cng =
|
||||
Ecto.Changeset.change(user)
|
||||
|> put_embed(:info, info_cng)
|
||||
|
||||
IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}")
|
||||
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||
|
||||
IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}")
|
||||
else
|
||||
_ ->
|
||||
IO.puts("No local user #{nickname}")
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
defmodule Mix.Tasks.SetAdmin do
|
||||
use Mix.Task
|
||||
import Ecto.Changeset
|
||||
alias Pleroma.User
|
||||
|
||||
@doc """
|
||||
|
@ -9,21 +10,22 @@ 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})
|
||||
|
||||
cng = User.info_changeset(user, %{info: info})
|
||||
{:ok, user} = User.update_and_set_cache(cng)
|
||||
user_cng =
|
||||
Ecto.Changeset.change(user)
|
||||
|> put_embed(:info, info_cng)
|
||||
|
||||
IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}")
|
||||
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||
|
||||
IO.puts("Admin status of #{nickname}: #{user.info.is_admin}")
|
||||
else
|
||||
_ ->
|
||||
IO.puts("No local user #{nickname}")
|
||||
|
|
|
@ -10,11 +10,11 @@ defmodule Mix.Tasks.SetLocked do
|
|||
"""
|
||||
|
||||
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,15 @@ defmodule Mix.Tasks.SetLocked 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})
|
||||
|
||||
cng = User.info_changeset(user, %{info: info})
|
||||
user = Repo.update!(cng)
|
||||
user_cng =
|
||||
Ecto.Changeset.change(user)
|
||||
|> put_embed(:info, info_cng)
|
||||
|
||||
IO.puts("locked status of #{nickname}: #{user.info["locked"]}")
|
||||
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||
|
||||
IO.puts("Locked status of #{nickname}: #{user.info.locked}")
|
||||
else
|
||||
_ ->
|
||||
IO.puts("No local user #{nickname}")
|
||||
|
|
Loading…
Reference in a new issue