Merge remote-tracking branch 'upstream/develop' into refactor/following-relationships
authorEgor Kislitsyn <egor@kislitsyn.com>
Thu, 24 Oct 2019 07:42:14 +0000 (14:42 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Thu, 24 Oct 2019 07:55:36 +0000 (14:55 +0700)
22 files changed:
1  2 
lib/mix/tasks/pleroma/user.ex
lib/pleroma/user.ex
lib/pleroma/user/query.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/activity_pub_controller.ex
lib/pleroma/web/activity_pub/relay.ex
lib/pleroma/web/activity_pub/transmogrifier.ex
lib/pleroma/web/activity_pub/visibility.ex
lib/pleroma/web/common_api/common_api.ex
lib/pleroma/web/pleroma_api/controllers/account_controller.ex
test/support/factory.ex
test/tasks/database_test.exs
test/tasks/user_test.exs
test/user_test.exs
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/relay_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/admin_api/admin_api_controller_test.exs
test/web/mastodon_api/controllers/account_controller_test.exs
test/web/mastodon_api/controllers/follow_request_controller_test.exs
test/web/streamer/streamer_test.exs
test/web/twitter_api/util_controller_test.exs

Simple merge
index d3c767f334badbd71fbc778b419a7003003790d2,7bef6e2810c5ed08071933df8d46b9e1dc8fa157..03c02a47f3402662633e52b2b0a2c322a164f970
@@@ -155,13 -213,73 +213,67 @@@ defmodule Pleroma.User d
  
    @spec restrict_deactivated(Ecto.Query.t()) :: Ecto.Query.t()
    def restrict_deactivated(query) do
-     from(u in query,
-       where: not fragment("? \\? 'deactivated' AND ?->'deactivated' @> 'true'", u.info, u.info)
-     )
+     from(u in query, where: u.deactivated != ^true)
    end
  
 -  def following_count(%User{following: []}), do: 0
 -
 -  def following_count(%User{} = user) do
 -    user
 -    |> get_friends_query()
 -    |> Repo.aggregate(:count, :id)
 -  end
 +  defdelegate following_count(user), to: FollowingRelationship
  
+   @info_fields [
+     :banner,
+     :background,
+     :source_data,
+     :note_count,
+     :follower_count,
+     :following_count,
+     :locked,
+     :confirmation_pending,
+     :password_reset_pending,
+     :confirmation_token,
+     :default_scope,
+     :blocks,
+     :domain_blocks,
+     :mutes,
+     :muted_reblogs,
+     :muted_notifications,
+     :subscribers,
+     :deactivated,
+     :no_rich_text,
+     :ap_enabled,
+     :is_moderator,
+     :is_admin,
+     :show_role,
+     :settings,
+     :magic_key,
+     :uri,
+     :hide_followers_count,
+     :hide_follows_count,
+     :hide_followers,
+     :hide_follows,
+     :hide_favorites,
+     :unread_conversation_count,
+     :pinned_activities,
+     :email_notifications,
+     :mascot,
+     :emoji,
+     :pleroma_settings_store,
+     :fields,
+     :raw_fields,
+     :discoverable,
+     :invisible,
+     :skip_thread_containment,
+     :notification_settings
+   ]
+   def info_fields, do: @info_fields
+   defp truncate_fields_param(params) do
+     if Map.has_key?(params, :fields) do
+       Map.put(params, :fields, Enum.map(params[:fields], &truncate_field/1))
+     else
+       params
+     end
+   end
    defp truncate_if_exists(params, key, max_length) do
      if Map.has_key?(params, key) and is_binary(params[key]) do
        {value, _chopped} = String.split_at(params[key], max_length)
      name_limit = Pleroma.Config.get([:instance, :user_name_length], 100)
  
      struct
-     |> cast(params, [:bio, :name, :avatar])
+     |> cast(
+       params,
+       [
+         :bio,
+         :name,
+         :avatar,
 -        :following,
+         :locked,
+         :no_rich_text,
+         :default_scope,
+         :banner,
+         :hide_follows,
+         :hide_followers,
+         :hide_followers_count,
+         :hide_follows_count,
+         :hide_favorites,
+         :background,
+         :show_role,
+         :skip_thread_containment,
+         :fields,
+         :raw_fields,
+         :pleroma_settings_store,
+         :discoverable
+       ]
+     )
      |> unique_constraint(:nickname)
      |> validate_format(:nickname, local_nickname_regex())
      |> validate_length(:bio, max: bio_limit)
    def needs_update?(_), do: true
  
    @spec maybe_direct_follow(User.t(), User.t()) :: {:ok, User.t()} | {:error, String.t()}
-   def maybe_direct_follow(
-         %User{} = follower,
-         %User{local: true, info: %{locked: true}} = followed
-       ) do
 -  def maybe_direct_follow(%User{} = follower, %User{local: true, locked: true}) do
 -    {:ok, follower}
++  def maybe_direct_follow(%User{} = follower, %User{local: true, locked: true} = followed) do
 +    follow(follower, followed, "pending")
    end
  
    def maybe_direct_follow(%User{} = follower, %User{local: true} = followed) do
      set_cache(follower)
    end
  
 -  def follow(%User{} = follower, %User{} = followed) do
 +  defdelegate following(user), to: FollowingRelationship
 +
-   def follow(%User{} = follower, %User{info: info} = followed, state \\ "accept") do
++  def follow(%User{} = follower, %User{} = followed, state \\ "accept") do
      deny_follow_blocked = Pleroma.Config.get([:user, :deny_follow_blocked])
 -    ap_followers = followed.follower_address
  
      cond do
-       info.deactivated ->
-         {:error, "Could not follow user: You are deactivated."}
+       followed.deactivated ->
+         {:error, "Could not follow user: #{followed.nickname} is deactivated."}
  
        deny_follow_blocked and blocks?(followed, follower) ->
          {:error, "Could not follow user: #{followed.nickname} blocked you."}
      end
    end
  
 -  @spec following?(User.t(), User.t()) :: boolean
 -  def following?(%User{} = follower, %User{} = followed) do
 -    Enum.member?(follower.following, followed.follower_address)
 -  end
 +  defdelegate following?(follower, followed), to: FollowingRelationship
  
    def locked?(%User{} = user) do
-     user.info.locked || false
+     user.locked || false
    end
  
    def get_by_id(id) do
Simple merge
Simple merge
Simple merge
index bf5ba7883504612e7c103cdd8afeae196da6f49e,b66324e5e75975eeb1e83fbf763fb7d2271db20e..0c7883f332966a54f51dff8256a81605a8ab0c46
@@@ -72,26 -72,25 +72,26 @@@ defmodule Mix.Tasks.Pleroma.DatabaseTes
    describe "running update_users_following_followers_counts" do
      test "following and followers count are updated" do
        [user, user2] = insert_pair(:user)
-       {:ok, %User{info: info} = user} = User.follow(user, user2)
 -      {:ok, %User{following: following} = user} = User.follow(user, user2)
++      {:ok, %User{} = user} = User.follow(user, user2)
 +
 +      following = User.following(user)
  
        assert length(following) == 2
-       assert info.follower_count == 0
+       assert user.follower_count == 0
  
        {:ok, user} =
          user
-         |> User.change_info(&Ecto.Changeset.change(&1, %{follower_count: 3}))
 -        |> Ecto.Changeset.change(%{following: following ++ following, follower_count: 3})
++        |> Ecto.Changeset.change(%{follower_count: 3})
          |> Repo.update()
  
-       assert user.info.follower_count == 3
 -      assert length(user.following) == 4
+       assert user.follower_count == 3
  
        assert :ok == Mix.Tasks.Pleroma.Database.run(["update_users_following_followers_counts"])
  
        user = User.get_by_id(user.id)
  
 -      assert length(user.following) == 2
 +      assert length(User.following(user)) == 2
-       assert user.info.follower_count == 0
+       assert user.follower_count == 0
      end
    end
  
index c0e4ba85ceb10a5c3dd6aea166acc4e2822718ac,f024f92ae8c5ed2fdaa541bf5b845d25e9382985..bfd0ccbc588b0bbd59f5e70c379acff2d509a873
@@@ -155,8 -154,8 +155,8 @@@ defmodule Mix.Tasks.Pleroma.UserTest d
        assert message =~ "Successfully unsubscribed"
  
        user = User.get_cached_by_nickname(user.nickname)
 -      assert Enum.empty?(user.following)
 +      assert Enum.empty?(User.get_friends(user))
-       assert user.info.deactivated
+       assert user.deactivated
      end
  
      test "no user to unsubscribe" do
index f4224ad0a367fcbae7da9d7f194c66367a9820f0,92de31c748a3c5259fd772b0a00a55cc63e293c5..188295a863f71cfc02f90956b04a7af8aa8b4e31
@@@ -150,9 -151,9 +150,9 @@@ defmodule Pleroma.UserTest d
      user = User.get_cached_by_id(user.id)
  
      followed = User.get_cached_by_ap_id(followed.ap_id)
-     assert followed.info.follower_count == 1
+     assert followed.follower_count == 1
  
 -    assert User.ap_followers(followed) in user.following
 +    assert User.ap_followers(followed) in User.following(user)
    end
  
    test "can't follow a deactivated users" do
Simple merge
index c674e71f515677ecc4d6142281a82daf0e2183c7,400f3287d254bcc4ba92eceaa8493d5a237ee3e0..cb10151719a45b43ebaa11be20f4de2c3d964606
@@@ -215,8 -213,7 +215,8 @@@ defmodule Pleroma.Web.StreamerTest d
      test "it sends message if recipients invalid and thread containment is enabled but user's thread containment is disabled" do
        Pleroma.Config.put([:instance, :skip_thread_containment], false)
        author = insert(:user)
-       user = insert(:user, info: %{skip_thread_containment: true})
 -      user = insert(:user, following: [author.ap_id], skip_thread_containment: true)
++      user = insert(:user, skip_thread_containment: true)
 +      User.follow(user, author, "accept")
  
        activity =
          insert(:note_activity,