From: Mark Felder Date: Mon, 18 Jan 2021 18:05:05 +0000 (-0600) Subject: Merge branch 'develop' into refactor/approval_pending_user_field X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=44a86951a339fdb0146a237ca5178c83823629c7;p=akkoma Merge branch 'develop' into refactor/approval_pending_user_field --- 44a86951a339fdb0146a237ca5178c83823629c7 diff --cc lib/pleroma/user.ex index f6eca0109,9efc27887..d81abbd2b --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@@ -110,9 -110,9 +110,9 @@@ defmodule Pleroma.User d field(:follower_count, :integer, default: 0) field(:following_count, :integer, default: 0) field(:is_locked, :boolean, default: false) - field(:confirmation_pending, :boolean, default: false) + field(:is_confirmed, :boolean, default: true) field(:password_reset_pending, :boolean, default: false) - field(:approval_pending, :boolean, default: false) + field(:is_approved, :boolean, default: true) field(:registration_reason, :string, default: nil) field(:confirmation_token, :string, default: nil) field(:default_scope, :string, default: "public") @@@ -288,9 -288,9 +288,9 @@@ @spec account_status(User.t()) :: account_status() def account_status(%User{deactivated: true}), do: :deactivated def account_status(%User{password_reset_pending: true}), do: :password_reset_pending - def account_status(%User{local: true, approval_pending: true}), do: :approval_pending + def account_status(%User{local: true, is_approved: false}), do: :approval_pending - def account_status(%User{local: true, confirmation_pending: true}) do + def account_status(%User{local: true, is_confirmed: false}) do if Config.get([:instance, :account_activation_required]) do :confirmation_pending else @@@ -704,23 -704,23 +704,23 @@@ reason_limit = Config.get([:instance, :registration_reason_length], 500) params = Map.put_new(params, :accepts_chat_messages, true) - need_confirmation? = - if is_nil(opts[:need_confirmation]) do - Config.get([:instance, :account_activation_required]) + confirmed? = + if is_nil(opts[:confirmed]) do + !Config.get([:instance, :account_activation_required]) else - opts[:need_confirmation] + opts[:confirmed] end - need_approval? = - if is_nil(opts[:need_approval]) do - Config.get([:instance, :account_approval_required]) + approved? = + if is_nil(opts[:approved]) do + !Config.get([:instance, :account_approval_required]) else - opts[:need_approval] + opts[:approved] end struct - |> confirmation_changeset(need_confirmation: need_confirmation?) + |> confirmation_changeset(set_confirmation: confirmed?) - |> approval_changeset(need_approval: need_approval?) + |> approval_changeset(set_approval: approved?) |> cast(params, [ :bio, :raw_bio, @@@ -821,7 -821,7 +821,7 @@@ end end - def post_register_action(%User{is_approved: true, confirmation_pending: false} = user) do - def post_register_action(%User{approval_pending: false, is_confirmed: true} = user) do ++ def post_register_action(%User{is_approved: true, is_confirmed: true} = user) do with {:ok, user} <- autofollow_users(user), {:ok, _} <- autofollowing_users(user), {:ok, user} <- set_cache(user), @@@ -1682,9 -1682,9 +1682,9 @@@ follower_count: 0, following_count: 0, is_locked: false, - confirmation_pending: false, + is_confirmed: true, password_reset_pending: false, - approval_pending: false, + is_approved: true, registration_reason: nil, confirmation_token: nil, domain_blocks: [], diff --cc lib/pleroma/web/admin_api/views/account_view.ex index 1a876d272,10d2e698b..34bf2e67a --- a/lib/pleroma/web/admin_api/views/account_view.ex +++ b/lib/pleroma/web/admin_api/views/account_view.ex @@@ -77,8 -77,8 +77,8 @@@ defmodule Pleroma.Web.AdminAPI.AccountV "local" => user.local, "roles" => User.roles(user), "tags" => user.tags || [], - "confirmation_pending" => user.confirmation_pending, + "is_confirmed" => user.is_confirmed, - "approval_pending" => user.approval_pending, + "is_approved" => user.is_approved, "url" => user.uri || user.ap_id, "registration_reason" => user.registration_reason, "actor_type" => user.actor_type diff --cc test/pleroma/user_test.exs index c6d8e1463,ac9db9ffb..617d9b755 --- a/test/pleroma/user_test.exs +++ b/test/pleroma/user_test.exs @@@ -1465,9 -1465,9 +1465,9 @@@ defmodule Pleroma.UserTest d end) end - test "sends approval emails when `approval_pending: true`" do + test "sends approval emails when `is_approved: false`" do admin = insert(:user, is_admin: true) - user = insert(:user, confirmation_pending: true, is_approved: false) - user = insert(:user, is_confirmed: false, approval_pending: true) ++ user = insert(:user, is_confirmed: false, is_approved: false) User.confirm(user) ObanHelpers.perform_all() @@@ -1494,7 -1494,7 +1494,7 @@@ end test "confirming a confirmed user does not trigger post-register actions" do - user = insert(:user, confirmation_pending: false, is_approved: false) - user = insert(:user, is_confirmed: true, approval_pending: true) ++ user = insert(:user, is_confirmed: true, is_approved: false) User.confirm(user) ObanHelpers.perform_all() @@@ -1616,9 -1616,9 +1616,9 @@@ follower_count: 9, following_count: 9001, is_locked: true, - confirmation_pending: true, + is_confirmed: false, password_reset_pending: true, - approval_pending: true, + is_approved: false, registration_reason: "ahhhhh", confirmation_token: "qqqq", domain_blocks: ["lain.com"], @@@ -1658,9 -1658,9 +1658,9 @@@ follower_count: 0, following_count: 0, is_locked: false, - confirmation_pending: false, + is_confirmed: true, password_reset_pending: false, - approval_pending: false, + is_approved: true, registration_reason: nil, confirmation_token: nil, domain_blocks: [], @@@ -1755,10 -1755,10 +1755,10 @@@ end test "returns :approval_pending for unapproved user" do - user = insert(:user, local: true, approval_pending: true) + user = insert(:user, local: true, is_approved: false) assert User.account_status(user) == :approval_pending - user = insert(:user, local: true, confirmation_pending: true, is_approved: false) - user = insert(:user, local: true, is_confirmed: false, approval_pending: true) ++ user = insert(:user, local: true, is_confirmed: false, is_approved: false) assert User.account_status(user) == :approval_pending end end diff --cc test/pleroma/web/admin_api/controllers/user_controller_test.exs index ed094823b,569343ed5..7f37247a9 --- a/test/pleroma/web/admin_api/controllers/user_controller_test.exs +++ b/test/pleroma/web/admin_api/controllers/user_controller_test.exs @@@ -635,11 -635,11 +635,11 @@@ defmodule Pleroma.Web.AdminAPI.UserCont end test "only unconfirmed users", %{conn: conn} do - sad_user = insert(:user, nickname: "sadboy", confirmation_pending: true) - old_user = insert(:user, nickname: "oldboy", confirmation_pending: true) + sad_user = insert(:user, nickname: "sadboy", is_confirmed: false) + old_user = insert(:user, nickname: "oldboy", is_confirmed: false) - insert(:user, nickname: "happyboy", approval_pending: false) + insert(:user, nickname: "happyboy", is_approved: true) - insert(:user, confirmation_pending: false) + insert(:user, is_confirmed: true) result = conn @@@ -649,8 -649,8 +649,8 @@@ users = Enum.map([old_user, sad_user], fn user -> user_response(user, %{ - "confirmation_pending" => true, + "is_confirmed" => false, - "approval_pending" => false + "is_approved" => true }) end) |> Enum.sort_by(& &1["nickname"]) @@@ -960,8 -960,8 +960,8 @@@ "tags" => [], "avatar" => User.avatar_url(user) |> MediaProxy.url(), "display_name" => HTML.strip_tags(user.name || user.nickname), - "confirmation_pending" => false, + "is_confirmed" => true, - "approval_pending" => false, + "is_approved" => true, "url" => user.ap_id, "registration_reason" => nil, "actor_type" => "Person" diff --cc test/pleroma/web/mastodon_api/controllers/account_controller_test.exs index 1c310bb07,2d929e532..2f5bfda98 --- a/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/account_controller_test.exs @@@ -1027,8 -1027,8 +1027,8 @@@ defmodule Pleroma.Web.MastodonAPI.Accou user = Repo.preload(token_from_db, :user).user assert user - refute user.confirmation_pending + assert user.is_confirmed - refute user.approval_pending + assert user.is_approved end test "registers but does not log in with :account_activation_required", %{conn: conn} do