Add moderator task.
This commit is contained in:
parent
765671a5b0
commit
56cfe71858
27
lib/mix/tasks/make_moderator.ex
Normal file
27
lib/mix/tasks/make_moderator.ex
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
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, [])
|
||||||
|
|
||||||
|
moderator = case rest do
|
||||||
|
[moderator] -> moderator == "true"
|
||||||
|
_ -> true
|
||||||
|
end
|
||||||
|
|
||||||
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
|
info = user.info
|
||||||
|
|> Map.put("is_moderator", !!moderator)
|
||||||
|
cng = User.info_changeset(user, %{info: info})
|
||||||
|
user = Repo.update!(cng)
|
||||||
|
|
||||||
|
IO.puts "Moderator status of #{nickname}: #{user.info["is_moderator"]}"
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
IO.puts "No local user #{nickname}"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue