From dc38dc847207e4724265fbeb111d0a236b75f93f Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Tue, 13 Oct 2020 21:52:06 -0500 Subject: [PATCH] Replace User.toggle_confirmation/1 with User.confirm/1, fixes #2235 --- CHANGELOG.md | 1 + docs/administration/CLI_tasks/user.md | 4 ++-- lib/mix/tasks/pleroma/user.ex | 4 ++-- lib/pleroma/user.ex | 12 ------------ .../controllers/admin_api_controller.ex | 2 +- test/mix/tasks/pleroma/user_test.exs | 14 +++++++------- test/pleroma/user_test.exs | 18 ------------------ 7 files changed, 13 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8fc1750d1..c546dd0bf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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. - 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`. +- Changed `mix pleroma.user toggle_confirmed` to `mix pleroma.user confirm` ### 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). diff --git a/docs/administration/CLI_tasks/user.md b/docs/administration/CLI_tasks/user.md index c64ed4f22..b57dce0e7 100644 --- a/docs/administration/CLI_tasks/user.md +++ b/docs/administration/CLI_tasks/user.md @@ -264,13 +264,13 @@ === "OTP" ```sh - ./bin/pleroma_ctl user toggle_confirmed + ./bin/pleroma_ctl user confirm ``` === "From Source" ```sh - mix pleroma.user toggle_confirmed + mix pleroma.user confirm ``` ## Set confirmation status for all regular active users diff --git a/lib/mix/tasks/pleroma/user.ex b/lib/mix/tasks/pleroma/user.ex index e06262804..c454f1d28 100644 --- a/lib/mix/tasks/pleroma/user.ex +++ b/lib/mix/tasks/pleroma/user.ex @@ -345,11 +345,11 @@ def run(["delete_activities", nickname]) do end end - def run(["toggle_confirmed", nickname]) do + def run(["confirm", nickname]) do start_pleroma() 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" diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 0978cc02c..0dabb2a1e 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -2113,18 +2113,6 @@ def touch_last_digest_emailed_at(user) do updated_user 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()} def need_confirmation(%User{} = user, bool) do user diff --git a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex index bdd3e195d..c2bd441ee 100644 --- a/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex +++ b/lib/pleroma/web/admin_api/controllers/admin_api_controller.ex @@ -655,7 +655,7 @@ def reload_emoji(conn, _params) do def confirm_email(%{assigns: %{user: admin}} = conn, %{"nicknames" => nicknames}) do 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"}) diff --git a/test/mix/tasks/pleroma/user_test.exs b/test/mix/tasks/pleroma/user_test.exs index b8c423c48..f58690dbe 100644 --- a/test/mix/tasks/pleroma/user_test.exs +++ b/test/mix/tasks/pleroma/user_test.exs @@ -457,24 +457,24 @@ test "it prints an error message when user is not exist" do end end - describe "running toggle_confirmed" do + describe "running confirm" do test "user is confirmed" do %{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 message == "#{nickname} needs confirmation." + assert message == "#{nickname} doesn't need confirmation." user = Repo.get(User, id) - assert user.confirmation_pending - assert user.confirmation_token + refute user.confirmation_pending + refute user.confirmation_token end test "user is not confirmed" do %{id: id, nickname: nickname} = 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 message == "#{nickname} doesn't need confirmation." @@ -484,7 +484,7 @@ test "user is not confirmed" do end 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 message =~ "No local user" diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs index 18a143919..2c8ad2089 100644 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@ -1940,24 +1940,6 @@ test "Only includes users with no read notifications" do 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 test "it creates keys for a user and stores them in info" do user = insert(:user)