2018-02-21 18:33:36 +01:00
|
|
|
defmodule Mix.Tasks.SetModerator do
|
2018-07-13 01:02:18 +02:00
|
|
|
@moduledoc """
|
|
|
|
Set moderator to a local user
|
|
|
|
|
2018-11-02 09:32:48 +01:00
|
|
|
Usage: ``mix set_moderator <nickname>``
|
2018-07-13 01:02:18 +02:00
|
|
|
|
|
|
|
Example: ``mix set_moderator lain``
|
|
|
|
"""
|
|
|
|
|
2018-02-21 18:33:36 +01:00
|
|
|
use Mix.Task
|
2018-12-05 16:41:50 +01:00
|
|
|
import Ecto.Changeset
|
2018-02-21 18:33:36 +01:00
|
|
|
alias Pleroma.{Repo, User}
|
|
|
|
|
|
|
|
def run([nickname | rest]) do
|
2018-06-12 14:42:40 +02:00
|
|
|
Application.ensure_all_started(:pleroma)
|
2018-02-21 18:33:36 +01:00
|
|
|
|
2018-03-30 15:01:53 +02:00
|
|
|
moderator =
|
|
|
|
case rest do
|
|
|
|
[moderator] -> moderator == "true"
|
|
|
|
_ -> true
|
|
|
|
end
|
2018-02-21 18:33:36 +01:00
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
2018-12-05 16:41:50 +01:00
|
|
|
info_cng = User.Info.admin_api_update(user.info, %{is_moderator: !!moderator})
|
2018-12-05 16:44:15 +01:00
|
|
|
|
|
|
|
user_cng =
|
|
|
|
Ecto.Changeset.change(user)
|
|
|
|
|> put_embed(:info, info_cng)
|
|
|
|
|
2018-12-05 16:41:50 +01:00
|
|
|
{:ok, user} = User.update_and_set_cache(user_cng)
|
2018-03-30 15:01:53 +02:00
|
|
|
|
2018-12-05 16:41:50 +01:00
|
|
|
IO.puts("Moderator status of #{nickname}: #{user.info.is_moderator}")
|
2018-02-21 18:33:36 +01:00
|
|
|
else
|
|
|
|
_ ->
|
2018-03-30 15:01:53 +02:00
|
|
|
IO.puts("No local user #{nickname}")
|
2018-02-21 18:33:36 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|