2018-02-21 10:33:36 -07:00
|
|
|
defmodule Mix.Tasks.SetModerator do
|
|
|
|
use Mix.Task
|
|
|
|
import Mix.Ecto
|
|
|
|
alias Pleroma.{Repo, User}
|
|
|
|
|
|
|
|
@shortdoc "Set moderator status"
|
|
|
|
def run([nickname | rest]) do
|
|
|
|
ensure_started(Repo, [])
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
moderator =
|
|
|
|
case rest do
|
|
|
|
[moderator] -> moderator == "true"
|
|
|
|
_ -> true
|
|
|
|
end
|
2018-02-21 10:33:36 -07:00
|
|
|
|
|
|
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
2018-03-30 07:01:53 -06:00
|
|
|
info =
|
|
|
|
user.info
|
|
|
|
|> Map.put("is_moderator", !!moderator)
|
|
|
|
|
2018-02-21 10:33:36 -07:00
|
|
|
cng = User.info_changeset(user, %{info: info})
|
|
|
|
user = Repo.update!(cng)
|
|
|
|
|
2018-03-30 07:01:53 -06:00
|
|
|
IO.puts("Moderator status of #{nickname}: #{user.info["is_moderator"]}")
|
2018-02-21 10:33:36 -07:00
|
|
|
else
|
|
|
|
_ ->
|
2018-03-30 07:01:53 -06:00
|
|
|
IO.puts("No local user #{nickname}")
|
2018-02-21 10:33:36 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|