forked from AkkomaGang/akkoma
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,
|
name: :string,
|
||||||
bio: :string,
|
bio: :string,
|
||||||
password: :string,
|
password: :string,
|
||||||
moderator: :boolean
|
moderator: :boolean,
|
||||||
|
admin: :boolean
|
||||||
]
|
]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -64,6 +65,7 @@ def run(["new", nickname, email | rest]) do
|
||||||
end
|
end
|
||||||
|
|
||||||
moderator? = Keyword.get(options, :moderator, false)
|
moderator? = Keyword.get(options, :moderator, false)
|
||||||
|
admin? = Keyword.get(options, :admin, false)
|
||||||
|
|
||||||
Mix.shell().info("""
|
Mix.shell().info("""
|
||||||
A user will be created with the following information:
|
A user will be created with the following information:
|
||||||
|
@ -75,6 +77,7 @@ def run(["new", nickname, email | rest]) do
|
||||||
- name: #{name}
|
- name: #{name}
|
||||||
- bio: #{bio}
|
- bio: #{bio}
|
||||||
- moderator: #{if(moderator?, do: "true", else: "false")}
|
- moderator: #{if(moderator?, do: "true", else: "false")}
|
||||||
|
- admin: #{if(admin?, do: "true", else: "false")}
|
||||||
""")
|
""")
|
||||||
|
|
||||||
proceed? = Mix.shell().yes?("Continue?")
|
proceed? = Mix.shell().yes?("Continue?")
|
||||||
|
@ -102,9 +105,14 @@ def run(["new", nickname, email | rest]) do
|
||||||
run(["set", nickname, "--moderator"])
|
run(["set", nickname, "--moderator"])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if admin? do
|
||||||
|
run(["set", nickname, "--admin"])
|
||||||
|
end
|
||||||
|
|
||||||
if generated_password? do
|
if generated_password? do
|
||||||
run(["reset_password", nickname])
|
run(["reset_password", nickname])
|
||||||
end
|
end
|
||||||
|
|
||||||
else
|
else
|
||||||
Mix.shell().info("User will not be created.")
|
Mix.shell().info("User will not be created.")
|
||||||
end
|
end
|
||||||
|
@ -115,16 +123,22 @@ def run(["rm", nickname]) do
|
||||||
|
|
||||||
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
with %User{local: true} = user <- User.get_by_nickname(nickname) do
|
||||||
User.delete(user)
|
User.delete(user)
|
||||||
end
|
|
||||||
|
|
||||||
Mix.shell().info("User #{nickname} deleted.")
|
Mix.shell().info("User #{nickname} deleted.")
|
||||||
|
else
|
||||||
|
_ ->
|
||||||
|
Mix.shell().error("No local user #{nickname}")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["toggle_activated", nickname]) do
|
def run(["toggle_activated", nickname]) do
|
||||||
Mix.Task.run("app.start")
|
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"])
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue