Update mix tasks since User.info.info_changeset is deprecated
This commit is contained in:
parent
22eff17912
commit
5427d2af3a
|
@ -8,7 +8,7 @@ defmodule Mix.Tasks.SetModerator do
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
import Mix.Ecto
|
import Ecto.Changeset
|
||||||
alias Pleroma.{Repo, User}
|
alias Pleroma.{Repo, User}
|
||||||
|
|
||||||
def run([nickname | rest]) do
|
def run([nickname | rest]) do
|
||||||
|
@ -21,14 +21,12 @@ def run([nickname | rest]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
info =
|
info_cng = User.Info.admin_api_update(user.info, %{is_moderator: !!moderator})
|
||||||
user.info
|
user_cng = Ecto.Changeset.change(user)
|
||||||
|> Map.put("is_moderator", !!moderator)
|
|> put_embed(:info, info_cng)
|
||||||
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||||
|
|
||||||
cng = User.info_changeset(user, %{info: info})
|
IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}")
|
||||||
{:ok, user} = User.update_and_set_cache(cng)
|
|
||||||
|
|
||||||
IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}")
|
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
IO.puts("No local user #{nickname}")
|
IO.puts("No local user #{nickname}")
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
defmodule Mix.Tasks.SetAdmin do
|
defmodule Mix.Tasks.SetAdmin do
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
|
import Ecto.Changeset
|
||||||
alias Pleroma.User
|
alias Pleroma.User
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
|
@ -9,21 +10,19 @@ defmodule Mix.Tasks.SetAdmin do
|
||||||
def run([nickname | rest]) do
|
def run([nickname | rest]) do
|
||||||
Application.ensure_all_started(:pleroma)
|
Application.ensure_all_started(:pleroma)
|
||||||
|
|
||||||
status =
|
admin =
|
||||||
case rest do
|
case rest do
|
||||||
[status] -> status == "true"
|
[admin] -> admin == "true"
|
||||||
_ -> true
|
_ -> true
|
||||||
end
|
end
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
info =
|
info_cng = User.Info.admin_api_update(user.info, %{is_admin: !!admin})
|
||||||
user.info
|
user_cng = Ecto.Changeset.change(user)
|
||||||
|> Map.put("is_admin", !!status)
|
|> put_embed(:info, info_cng)
|
||||||
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||||
|
|
||||||
cng = User.info_changeset(user, %{info: info})
|
IO.puts("Admin status of #{nickname}: #{user.info.is_admin}")
|
||||||
{:ok, user} = User.update_and_set_cache(cng)
|
|
||||||
|
|
||||||
IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}")
|
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
IO.puts("No local user #{nickname}")
|
IO.puts("No local user #{nickname}")
|
||||||
|
|
|
@ -8,13 +8,13 @@ defmodule Mix.Tasks.SetLocked do
|
||||||
|
|
||||||
Example: ``mix set_locked lain``
|
Example: ``mix set_locked lain``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
use Mix.Task
|
use Mix.Task
|
||||||
import Mix.Ecto
|
import Ecto.Changeset
|
||||||
alias Pleroma.{Repo, User}
|
alias Pleroma.{Repo, User}
|
||||||
|
|
||||||
def run([nickname | rest]) do
|
def run([nickname | rest]) do
|
||||||
ensure_started(Repo, [])
|
Application.ensure_all_started(:pleroma)
|
||||||
|
|
||||||
locked =
|
locked =
|
||||||
case rest do
|
case rest do
|
||||||
|
@ -23,14 +23,12 @@ def run([nickname | rest]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
info =
|
info_cng = User.Info.profile_update(user.info, %{locked: !!locked})
|
||||||
user.info
|
user_cng = Ecto.Changeset.change(user)
|
||||||
|> Map.put("locked", !!locked)
|
|> put_embed(:info, info_cng)
|
||||||
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
||||||
|
|
||||||
cng = User.info_changeset(user, %{info: info})
|
IO.puts("Locked status of #{nickname}: #{user.info.locked}")
|
||||||
user = Repo.update!(cng)
|
|
||||||
|
|
||||||
IO.puts("locked status of #{nickname}: #{user.info["locked"]}")
|
|
||||||
else
|
else
|
||||||
_ ->
|
_ ->
|
||||||
IO.puts("No local user #{nickname}")
|
IO.puts("No local user #{nickname}")
|
||||||
|
|
Loading…
Reference in New Issue