Add admin option to pleroma.user new. Add user existence checking to toggle_activated
This commit is contained in:
parent
ae82852330
commit
a8ef6b1190
1 changed files with 18 additions and 4 deletions
|
@ -47,7 +47,8 @@ def run(["new", nickname, email | rest]) do
|
|||
name: :string,
|
||||
bio: :string,
|
||||
password: :string,
|
||||
moderator: :boolean
|
||||
moderator: :boolean,
|
||||
admin: :boolean
|
||||
]
|
||||
)
|
||||
|
||||
|
@ -64,6 +65,7 @@ def run(["new", nickname, email | rest]) do
|
|||
end
|
||||
|
||||
moderator? = Keyword.get(options, :moderator, false)
|
||||
admin? = Keyword.get(options, :admin, false)
|
||||
|
||||
Mix.shell().info("""
|
||||
A user will be created with the following information:
|
||||
|
@ -75,6 +77,7 @@ def run(["new", nickname, email | rest]) do
|
|||
- name: #{name}
|
||||
- bio: #{bio}
|
||||
- moderator: #{if(moderator?, do: "true", else: "false")}
|
||||
- admin: #{if(admin?, do: "true", else: "false")}
|
||||
""")
|
||||
|
||||
proceed? = Mix.shell().yes?("Continue?")
|
||||
|
@ -102,9 +105,14 @@ def run(["new", nickname, email | rest]) do
|
|||
run(["set", nickname, "--moderator"])
|
||||
end
|
||||
|
||||
if admin? do
|
||||
run(["set", nickname, "--admin"])
|
||||
end
|
||||
|
||||
if generated_password? do
|
||||
run(["reset_password", nickname])
|
||||
end
|
||||
|
||||
else
|
||||
Mix.shell().info("User will not be created.")
|
||||
end
|
||||
|
@ -115,16 +123,22 @@ def run(["rm", nickname]) do
|
|||
|
||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||
User.delete(user)
|
||||
Mix.shell().info("User #{nickname} deleted.")
|
||||
else
|
||||
_ ->
|
||||
Mix.shell().error("No local user #{nickname}")
|
||||
end
|
||||
|
||||
Mix.shell().info("User #{nickname} deleted.")
|
||||
end
|
||||
|
||||
def run(["toggle_activated", nickname]) do
|
||||
Mix.Task.run("app.start")
|
||||
|
||||
with user <- User.get_by_nickname(nickname) do
|
||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||
User.deactivate(user, !user.info["deactivated"])
|
||||
Mix.shell().info("Activation status of #{nickname}: #{user.info["deactivated"]}")
|
||||
else
|
||||
_ ->
|
||||
Mix.shell().error("No local user #{nickname}")
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue