- `--bio BIO` - the user's bio
- `--password PASSWORD` - the user's password
- `--moderator`/`--no-moderator` - whether the user is a moderator
+ - `--admin`/`--no-admin` - whether the user is an admin
## Delete the user's account.
Options:
- `--locked`/`--no-locked` - whether the user's account is locked
- `--moderator`/`--no-moderator` - whether the user is a moderator
+ - `--admin`/`--no-admin` - whether the user is an admin
"""
def run(["new", nickname, email | rest]) do
rest,
strict: [
moderator: :boolean,
+ admin: :boolean,
locked: :boolean
]
)
nil -> nil
value -> set_locked(nickname, value)
end
+
+ case Keyword.get(options, :admin) do
+ nil -> nil
+ value -> set_admin(nickname, value)
+ end
end
defp set_moderator(nickname, value) do
end
end
+ defp set_admin(nickname, value) do
+ Application.ensure_all_started(:pleroma)
+
+ with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ info =
+ user.info
+ |> Map.put("is_admin", value)
+
+ cng = User.info_changeset(user, %{info: info})
+ {:ok, user} = User.update_and_set_cache(cng)
+
+ Mix.shell().info("Admin status of #{nickname}: #{user.info["is_admin"]}")
+ else
+ _ ->
+ Mix.shell().error("No local user #{nickname}")
+ end
+ end
+
defp set_locked(nickname, value) do
Mix.Ecto.ensure_started(Repo, [])
+++ /dev/null
-defmodule Mix.Tasks.SetAdmin do
- use Mix.Task
- alias Pleroma.User
-
- @doc """
- Sets admin status
- Usage: set_admin nickname [true|false]
- """
- def run([nickname | rest]) do
- Application.ensure_all_started(:pleroma)
-
- status =
- case rest do
- [status] -> status == "true"
- _ -> true
- end
-
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
- info =
- user.info
- |> Map.put("is_admin", !!status)
-
- cng = User.info_changeset(user, %{info: info})
- {:ok, user} = User.update_and_set_cache(cng)
-
- IO.puts("Admin status of #{nickname}: #{user.info["is_admin"]}")
- else
- _ ->
- IO.puts("No local user #{nickname}")
- end
- end
-end