689 B · text 5af55d9
defmodule Mix.Tasks.Gitgud.PromoteAdmin do
@shortdoc "Promote a user to admin by email."
@moduledoc """
mix gitgud.promote_admin user@example.com
"""
use Mix.Task
@impl Mix.Task
def run([email | _]) do
Mix.Task.run("app.start")
case GitGud.Accounts.get_user_by_email(email) do
nil ->
Mix.shell().error("no user with email: #{email}")
System.halt(1)
user ->
user
|> GitGud.Accounts.User.admin_changeset(true)
|> GitGud.Repo.update!()
Mix.shell().info("promoted: #{email}")
end
end
def run(_) do
Mix.shell().error("usage: mix gitgud.promote_admin <email>")
System.halt(1)
end
end