Merge branch 'develop' into refactor/approval_pending_user_field
authorMark Felder <feld@feld.me>
Mon, 18 Jan 2021 18:05:05 +0000 (12:05 -0600)
committerMark Felder <feld@feld.me>
Mon, 18 Jan 2021 18:05:05 +0000 (12:05 -0600)
1  2 
lib/pleroma/user.ex
lib/pleroma/user/query.ex
lib/pleroma/web/admin_api/views/account_view.ex
test/pleroma/user_test.exs
test/pleroma/web/admin_api/controllers/user_controller_test.exs
test/pleroma/web/admin_api/search_test.exs
test/pleroma/web/mastodon_api/controllers/account_controller_test.exs
test/pleroma/web/o_auth/o_auth_controller_test.exs
test/pleroma/web/twitter_api/twitter_api_test.exs

index f6eca010939e347b2943d200b24fb48df895d332,9efc278876a57ed016cf93bfce6eaa3c6c95eb38..d81abbd2b7838131920d30e8a2955bdd7bf22507
@@@ -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")
    @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
      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,
      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),
        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: [],
Simple merge
index 1a876d2721739ee5962fc5a778a51aff81e4b5e1,10d2e698b76dfe4f368742ec5cac2d16a1f966b8..34bf2e67ac6f53e2c09a19983b545d9d68ccf390
@@@ -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
index c6d8e1463d8ca69507dac72db0ed5dceefb3113a,ac9db9ffb53ffd62b4477ec0c0a1a0a70db35635..617d9b755fff0b8b6eb734382d31a3dc37c68101
@@@ -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()
      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()
          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"],
               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: [],
      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
index ed094823bad81cdf5f56749a606a82be335b9c2f,569343ed5847f067d872eb61efb212ca7159a922..7f37247a91a9c78b5766c94ed69470b3e15c5ae3
@@@ -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
        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"])
        "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"
index 1c310bb07193effd84cbaa5a6060128abd502eee,2d929e532b436559693132f4bd1a616e1346f40e..2f5bfda985faed8b07f278025aae4e583df7488b
@@@ -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