Replace User.toggle_confirmation/1 with User.confirm/1, fixes #2235
This commit is contained in:
parent
c3112fd13a
commit
dc38dc8472
|
@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- Users with the `discoverable` field set to false will not show up in searches.
|
- Users with the `discoverable` field set to false will not show up in searches.
|
||||||
- Minimum lifetime for ephmeral activities changed to 10 minutes and made configurable (`:min_lifetime` option).
|
- Minimum lifetime for ephmeral activities changed to 10 minutes and made configurable (`:min_lifetime` option).
|
||||||
- Introduced optional dependencies on `ffmpeg`, `ImageMagick`, `exiftool` software packages. Please refer to `docs/installation/optional/media_graphics_packages.md`.
|
- Introduced optional dependencies on `ffmpeg`, `ImageMagick`, `exiftool` software packages. Please refer to `docs/installation/optional/media_graphics_packages.md`.
|
||||||
|
- Changed `mix pleroma.user toggle_confirmed` to `mix pleroma.user confirm`
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
- Media preview proxy (requires `ffmpeg` and `ImageMagick` to be installed and media proxy to be enabled; see `:media_preview_proxy` config for more details).
|
- Media preview proxy (requires `ffmpeg` and `ImageMagick` to be installed and media proxy to be enabled; see `:media_preview_proxy` config for more details).
|
||||||
|
|
|
@ -264,13 +264,13 @@
|
||||||
=== "OTP"
|
=== "OTP"
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
./bin/pleroma_ctl user toggle_confirmed <nickname>
|
./bin/pleroma_ctl user confirm <nickname>
|
||||||
```
|
```
|
||||||
|
|
||||||
=== "From Source"
|
=== "From Source"
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
mix pleroma.user toggle_confirmed <nickname>
|
mix pleroma.user confirm <nickname>
|
||||||
```
|
```
|
||||||
|
|
||||||
## Set confirmation status for all regular active users
|
## Set confirmation status for all regular active users
|
||||||
|
|
|
@ -345,11 +345,11 @@ def run(["delete_activities", nickname]) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def run(["toggle_confirmed", nickname]) do
|
def run(["confirm", nickname]) do
|
||||||
start_pleroma()
|
start_pleroma()
|
||||||
|
|
||||||
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
with %User{} = user <- User.get_cached_by_nickname(nickname) do
|
||||||
{:ok, user} = User.toggle_confirmation(user)
|
{:ok, user} = User.confirm(user)
|
||||||
|
|
||||||
message = if user.confirmation_pending, do: "needs", else: "doesn't need"
|
message = if user.confirmation_pending, do: "needs", else: "doesn't need"
|
||||||
|
|
||||||
|
|
|
@ -2113,18 +2113,6 @@ def touch_last_digest_emailed_at(user) do
|
||||||
updated_user
|
updated_user
|
||||||
end
|
end
|
||||||
|
|
||||||
@spec toggle_confirmation(User.t()) :: {:ok, User.t()} | {:error, Changeset.t()}
|
|
||||||
def toggle_confirmation(%User{} = user) do
|
|
||||||
user
|
|
||||||
|> confirmation_changeset(need_confirmation: !user.confirmation_pending)
|
|
||||||
|> update_and_set_cache()
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec toggle_confirmation([User.t()]) :: [{:ok, User.t()} | {:error, Changeset.t()}]
|
|
||||||
def toggle_confirmation(users) do
|
|
||||||
Enum.map(users, &toggle_confirmation/1)
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec need_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()}
|
@spec need_confirmation(User.t(), boolean()) :: {:ok, User.t()} | {:error, Changeset.t()}
|
||||||
def need_confirmation(%User{} = user, bool) do
|
def need_confirmation(%User{} = user, bool) do
|
||||||
user
|
user
|
||||||
|
|
|
@ -655,7 +655,7 @@ def reload_emoji(conn, _params) do
|
||||||
def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
|
def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do
|
||||||
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
|
||||||
|
|
||||||
User.toggle_confirmation(users)
|
User.confirm(users)
|
||||||
|
|
||||||
ModerationLog.insert_log(%{actor: admin, subject: users, action: "confirm_email"})
|
ModerationLog.insert_log(%{actor: admin, subject: users, action: "confirm_email"})
|
||||||
|
|
||||||
|
|
|
@ -457,24 +457,24 @@ test "it prints an error message when user is not exist" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "running toggle_confirmed" do
|
describe "running confirm" do
|
||||||
test "user is confirmed" do
|
test "user is confirmed" do
|
||||||
%{id: id, nickname: nickname} = insert(:user, confirmation_pending: false)
|
%{id: id, nickname: nickname} = insert(:user, confirmation_pending: false)
|
||||||
|
|
||||||
assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
|
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
|
||||||
assert_received {:mix_shell, :info, [message]}
|
assert_received {:mix_shell, :info, [message]}
|
||||||
assert message == "#{nickname} needs confirmation."
|
assert message == "#{nickname} doesn't need confirmation."
|
||||||
|
|
||||||
user = Repo.get(User, id)
|
user = Repo.get(User, id)
|
||||||
assert user.confirmation_pending
|
refute user.confirmation_pending
|
||||||
assert user.confirmation_token
|
refute user.confirmation_token
|
||||||
end
|
end
|
||||||
|
|
||||||
test "user is not confirmed" do
|
test "user is not confirmed" do
|
||||||
%{id: id, nickname: nickname} =
|
%{id: id, nickname: nickname} =
|
||||||
insert(:user, confirmation_pending: true, confirmation_token: "some token")
|
insert(:user, confirmation_pending: true, confirmation_token: "some token")
|
||||||
|
|
||||||
assert :ok = Mix.Tasks.Pleroma.User.run(["toggle_confirmed", nickname])
|
assert :ok = Mix.Tasks.Pleroma.User.run(["confirm", nickname])
|
||||||
assert_received {:mix_shell, :info, [message]}
|
assert_received {:mix_shell, :info, [message]}
|
||||||
assert message == "#{nickname} doesn't need confirmation."
|
assert message == "#{nickname} doesn't need confirmation."
|
||||||
|
|
||||||
|
@ -484,7 +484,7 @@ test "user is not confirmed" do
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it prints an error message when user is not exist" do
|
test "it prints an error message when user is not exist" do
|
||||||
Mix.Tasks.Pleroma.User.run(["toggle_confirmed", "foo"])
|
Mix.Tasks.Pleroma.User.run(["confirm", "foo"])
|
||||||
|
|
||||||
assert_received {:mix_shell, :error, [message]}
|
assert_received {:mix_shell, :error, [message]}
|
||||||
assert message =~ "No local user"
|
assert message =~ "No local user"
|
||||||
|
|
|
@ -1940,24 +1940,6 @@ test "Only includes users with no read notifications" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "toggle_confirmation/1" do
|
|
||||||
test "if user is confirmed" do
|
|
||||||
user = insert(:user, confirmation_pending: false)
|
|
||||||
{:ok, user} = User.toggle_confirmation(user)
|
|
||||||
|
|
||||||
assert user.confirmation_pending
|
|
||||||
assert user.confirmation_token
|
|
||||||
end
|
|
||||||
|
|
||||||
test "if user is unconfirmed" do
|
|
||||||
user = insert(:user, confirmation_pending: true, confirmation_token: "some token")
|
|
||||||
{:ok, user} = User.toggle_confirmation(user)
|
|
||||||
|
|
||||||
refute user.confirmation_pending
|
|
||||||
refute user.confirmation_token
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "ensure_keys_present" do
|
describe "ensure_keys_present" do
|
||||||
test "it creates keys for a user and stores them in info" do
|
test "it creates keys for a user and stores them in info" do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
Loading…
Reference in New Issue