projects
/
akkoma
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Switch to Jason over Poison
[akkoma]
/
lib
/
mix
/
tasks
/
pleroma
/
user.ex
diff --git
a/lib/mix/tasks/pleroma/user.ex
b/lib/mix/tasks/pleroma/user.ex
index 00a9332920b51a7b6a38ca74931a9dcfe4520264..d130ff8c960e3ba919514490ffb2f22a2b7f35a2 100644
(file)
--- a/
lib/mix/tasks/pleroma/user.ex
+++ b/
lib/mix/tasks/pleroma/user.ex
@@
-30,16
+30,16
@@
defmodule Mix.Tasks.Pleroma.User do
mix pleroma.user invite [OPTION...]
Options:
mix pleroma.user invite [OPTION...]
Options:
- - `--expire
_date
DATE` - last day on which token is active (e.g. "2019-04-05")
- - `--max_use NUMBER` - maximum numbers of token use
+ - `--expire
s_at
DATE` - last day on which token is active (e.g. "2019-04-05")
+ - `--max_use NUMBER` - maximum numbers of token use
s
- ##
Generated invites list
+ ##
List generated invites
- mix pleroma.user invites
_list
+ mix pleroma.user invites
## Revoke invite
## Revoke invite
- mix pleroma.user
invite_revok
e TOKEN OR TOKEN_ID
+ mix pleroma.user
revoke_invit
e TOKEN OR TOKEN_ID
## Delete the user's account.
## Delete the user's account.
@@
-126,7
+126,7
@@
defmodule Mix.Tasks.Pleroma.User do
proceed? = assume_yes? or Mix.shell().yes?("Continue?")
proceed? = assume_yes? or Mix.shell().yes?("Continue?")
-
unless not
proceed? do
+
if
proceed? do
Common.start_pleroma()
params = %{
Common.start_pleroma()
params = %{
@@
-138,7
+138,7
@@
defmodule Mix.Tasks.Pleroma.User do
bio: bio
}
bio: bio
}
- changeset = User.register_changeset(%User{}, params,
confirmed: tru
e)
+ changeset = User.register_changeset(%User{}, params,
need_confirmation: fals
e)
{:ok, _user} = User.register(changeset)
Mix.shell().info("User #{nickname} created")
{:ok, _user} = User.register(changeset)
Mix.shell().info("User #{nickname} created")
@@
-162,8
+162,8
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["rm", nickname]) do
Common.start_pleroma()
def run(["rm", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
- User.
delete(
user)
+ with %User{local: true} = user <- User.get_
cached_
by_nickname(nickname) do
+ User.
perform(:delete,
user)
Mix.shell().info("User #{nickname} deleted.")
else
_ ->
Mix.shell().info("User #{nickname} deleted.")
else
_ ->
@@
-174,7
+174,7
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["toggle_activated", nickname]) do
Common.start_pleroma()
def run(["toggle_activated", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_
cached_
by_nickname(nickname) do
{:ok, user} = User.deactivate(user, !user.info.deactivated)
Mix.shell().info(
{:ok, user} = User.deactivate(user, !user.info.deactivated)
Mix.shell().info(
@@
-189,7
+189,7
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["reset_password", nickname]) do
Common.start_pleroma()
def run(["reset_password", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname),
+ with %User{local: true} = user <- User.get_
cached_
by_nickname(nickname),
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
Mix.shell().info("Generated password reset token for #{user.nickname}")
{:ok, token} <- Pleroma.PasswordResetToken.create_token(user) do
Mix.shell().info("Generated password reset token for #{user.nickname}")
@@
-211,14
+211,14
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["unsubscribe", nickname]) do
Common.start_pleroma()
def run(["unsubscribe", nickname]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_
cached_
by_nickname(nickname) do
Mix.shell().info("Deactivating #{user.nickname}")
User.deactivate(user)
{:ok, friends} = User.get_friends(user)
Enum.each(friends, fn friend ->
Mix.shell().info("Deactivating #{user.nickname}")
User.deactivate(user)
{:ok, friends} = User.get_friends(user)
Enum.each(friends, fn friend ->
- user = User.get_by_id(user.id)
+ user = User.get_
cached_
by_id(user.id)
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
User.unfollow(user, friend)
Mix.shell().info("Unsubscribing #{friend.nickname} from #{user.nickname}")
User.unfollow(user, friend)
@@
-226,7
+226,7
@@
defmodule Mix.Tasks.Pleroma.User do
:timer.sleep(500)
:timer.sleep(500)
- user = User.get_by_id(user.id)
+ user = User.get_
cached_
by_id(user.id)
if Enum.empty?(user.following) do
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
if Enum.empty?(user.following) do
Mix.shell().info("Successfully unsubscribed all followers from #{user.nickname}")
@@
-250,7
+250,7
@@
defmodule Mix.Tasks.Pleroma.User do
]
)
]
)
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
+ with %User{local: true} = user <- User.get_
cached_
by_nickname(nickname) do
user =
case Keyword.get(options, :moderator) do
nil -> user
user =
case Keyword.get(options, :moderator) do
nil -> user
@@
-277,7
+277,7
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["tag", nickname | tags]) do
Common.start_pleroma()
def run(["tag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_
cached_
by_nickname(nickname) do
user = user |> User.tag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
user = user |> User.tag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
@@
-290,7
+290,7
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["untag", nickname | tags]) do
Common.start_pleroma()
def run(["untag", nickname | tags]) do
Common.start_pleroma()
- with %User{} = user <- User.get_by_nickname(nickname) do
+ with %User{} = user <- User.get_
cached_
by_nickname(nickname) do
user = user |> User.untag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
user = user |> User.untag(tags)
Mix.shell().info("Tags of #{user.nickname}: #{inspect(tags)}")
@@
-304,70
+304,72
@@
defmodule Mix.Tasks.Pleroma.User do
{options, [], []} =
OptionParser.parse(rest,
strict: [
{options, [], []} =
OptionParser.parse(rest,
strict: [
- expire
_date
: :string,
+ expire
s_at
: :string,
max_use: :integer
]
)
max_use: :integer
]
)
- expire_at =
- with expire_date when expire_date != nil <- Keyword.get(options, :expire_date) do
- Date.from_iso8601!(expire_date)
- end
-
- options = Keyword.put(options, :expire_at, expire_at)
+ options =
+ options
+ |> Keyword.update(:expires_at, {:ok, nil}, fn
+ nil -> {:ok, nil}
+ val -> Date.from_iso8601(val)
+ end)
+ |> Enum.into(%{})
Common.start_pleroma()
Common.start_pleroma()
- with {:ok, token} <- UserInviteToken.create_token(options) do
+ with {:ok, val} <- options[:expires_at],
+ options = Map.put(options, :expires_at, val),
+ {:ok, invite} <- UserInviteToken.create_invite(options) do
Mix.shell().info(
Mix.shell().info(
- "Generated user invite token " <> String.replace(
token.token
_type, "_", " ")
+ "Generated user invite token " <> String.replace(
invite.invite
_type, "_", " ")
)
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
)
url =
Pleroma.Web.Router.Helpers.redirect_url(
Pleroma.Web.Endpoint,
:registration_page,
-
token
.token
+
invite
.token
)
IO.puts(url)
else
)
IO.puts(url)
else
-
_
->
- Mix.shell().error("Could not create invite token
.
")
+
error
->
+ Mix.shell().error("Could not create invite token
: #{inspect(error)}
")
end
end
end
end
- def run(["invites
_list
"]) do
+ def run(["invites"]) do
Common.start_pleroma()
Mix.shell().info("Invites list:")
UserInviteToken.list_invites()
|> Enum.each(fn invite ->
Common.start_pleroma()
Mix.shell().info("Invites list:")
UserInviteToken.list_invites()
|> Enum.each(fn invite ->
- expire_date =
- case invite.expire_at do
- nil -> nil
- date -> " | Expire date: #{Date.to_string(date)}"
+ expire_info =
+ with expires_at when not is_nil(expires_at) <- invite.expires_at do
+ " | Expires at: #{Date.to_string(expires_at)}"
end
using_info =
end
using_info =
- case invite.max_use do
- nil -> nil
- max_use -> " | Max use: #{max_use} Left use: #{max_use - invite.uses}"
+ with max_use when not is_nil(max_use) <- invite.max_use do
+ " | Max use: #{max_use} Left use: #{max_use - invite.uses}"
end
Mix.shell().info(
end
Mix.shell().info(
- "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.
token
_type} | Used: #{
+ "ID: #{invite.id} | Token: #{invite.token} | Token type: #{invite.
invite
_type} | Used: #{
invite.used
invite.used
- }#{expire_
date
}#{using_info}"
+ }#{expire_
info
}#{using_info}"
)
end)
end
)
end)
end
- def run(["
invite_revok
e", token]) do
+ def run(["
revoke_invit
e", token]) do
Common.start_pleroma()
Common.start_pleroma()
- with {:ok, _} <- UserInviteToken.mark_as_used(token) do
+ with {:ok, invite} <- UserInviteToken.find_by_token(token),
+ {:ok, _} <- UserInviteToken.update_invite(invite, %{used: true}) do
Mix.shell().info("Invite for token #{token} was revoked.")
else
_ -> Mix.shell().error("No invite found with token #{token}")
Mix.shell().info("Invite for token #{token} was revoked.")
else
_ -> Mix.shell().error("No invite found with token #{token}")
@@
-377,8
+379,8
@@
defmodule Mix.Tasks.Pleroma.User do
def run(["delete_activities", nickname]) do
Common.start_pleroma()
def run(["delete_activities", nickname]) do
Common.start_pleroma()
- with %User{local: true} = user <- User.get_by_nickname(nickname) do
- User.delete_user_activities(user)
+ with %User{local: true} = user <- User.get_
cached_
by_nickname(nickname) do
+
{:ok, _} =
User.delete_user_activities(user)
Mix.shell().info("User #{nickname} statuses deleted.")
else
_ ->
Mix.shell().info("User #{nickname} statuses deleted.")
else
_ ->