From 56cfe7185852320b740392e0f58ce096b6cbecb6 Mon Sep 17 00:00:00 2001 From: lain Date: Wed, 21 Feb 2018 18:33:36 +0100 Subject: [PATCH] Add moderator task. --- lib/mix/tasks/make_moderator.ex | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 lib/mix/tasks/make_moderator.ex diff --git a/lib/mix/tasks/make_moderator.ex b/lib/mix/tasks/make_moderator.ex new file mode 100644 index 000000000..a76b54f40 --- /dev/null +++ b/lib/mix/tasks/make_moderator.ex @@ -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 -- 2.45.2