Merge remote-tracking branch 'remotes/upstream/develop' into 1335-user-api-id-fields...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 21 Nov 2019 13:47:52 +0000 (16:47 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 21 Nov 2019 13:47:52 +0000 (16:47 +0300)
# Conflicts:
# lib/pleroma/user/search.ex
# test/user_test.exs

1  2 
lib/pleroma/user.ex
lib/pleroma/user/search.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
mix.exs
test/user_test.exs
test/web/mastodon_api/controllers/account_controller_test.exs

Simple merge
index 2b3c7b5b4f08129b36a6dfe7984c3e511b6db94b,b1bb9d4da0aa65ad14c14a1fe131f88380ecdc19..6b55df483b76944ba6276f25033ea30f76841628
@@@ -98,13 -99,13 +99,17 @@@ defmodule Pleroma.User.Search d
    defp base_query(_user, false), do: User
    defp base_query(user, true), do: User.get_followers_query(user)
  
 -  defp filter_blocked_user(query, %User{blocks: blocks})
 -       when length(blocks) > 0 do
 -    from(q in query, where: not (q.ap_id in ^blocks))
+   defp filter_invisible_users(query) do
+     from(q in query, where: q.invisible == false)
+   end
 +  defp filter_blocked_user(query, %User{} = blocker) do
 +    query
 +    |> join(:left, [u], b in Pleroma.UserRelationship,
 +      as: :blocks,
 +      on: b.relationship_type == ^:block and b.source_id == ^blocker.id and u.id == b.target_id
 +    )
 +    |> where([blocks: b], is_nil(b.target_id))
    end
  
    defp filter_blocked_user(query, _), do: query
diff --cc mix.exs
Simple merge
index ae90edbe956eadbf39929f2088f0ce4b74feeb4c,e6302b5255c87d04dcb6ce12f7d83fac51193d4a..1f30622010e580334a0c55787af7f7791c1f62d3
@@@ -25,56 -25,25 +25,75 @@@ defmodule Pleroma.UserTest d
  
    clear_config([:instance, :account_activation_required])
  
+   describe "service actors" do
+     test "returns invisible actor" do
+       uri = "#{Pleroma.Web.Endpoint.url()}/internal/fetch-test"
+       followers_uri = "#{uri}/followers"
+       user = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
+       assert %User{
+                nickname: "internal.fetch-test",
+                invisible: true,
+                local: true,
+                ap_id: ^uri,
+                follower_address: ^followers_uri
+              } = user
+       user2 = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
+       assert user.id == user2.id
+     end
+   end
 +  describe "AP ID user relationships" do
 +    setup do
 +      {:ok, user: insert(:user)}
 +    end
 +
 +    test "outgoing_relations_ap_ids/1", %{user: user} do
 +      rel_types = [:block, :mute, :notification_mute, :reblog_mute, :inverse_subscription]
 +
 +      ap_ids_by_rel =
 +        Enum.into(
 +          rel_types,
 +          %{},
 +          fn rel_type ->
 +            rel_records =
 +              insert_list(2, :user_relationship, %{source: user, relationship_type: rel_type})
 +
 +            ap_ids = Enum.map(rel_records, fn rr -> Repo.preload(rr, :target).target.ap_id end)
 +            {rel_type, Enum.sort(ap_ids)}
 +          end
 +        )
 +
 +      assert ap_ids_by_rel[:block] == Enum.sort(User.blocked_users_ap_ids(user))
 +      assert ap_ids_by_rel[:block] == Enum.sort(Enum.map(User.blocked_users(user), & &1.ap_id))
 +
 +      assert ap_ids_by_rel[:mute] == Enum.sort(User.muted_users_ap_ids(user))
 +      assert ap_ids_by_rel[:mute] == Enum.sort(Enum.map(User.muted_users(user), & &1.ap_id))
 +
 +      assert ap_ids_by_rel[:notification_mute] ==
 +               Enum.sort(User.notification_muted_users_ap_ids(user))
 +
 +      assert ap_ids_by_rel[:notification_mute] ==
 +               Enum.sort(Enum.map(User.notification_muted_users(user), & &1.ap_id))
 +
 +      assert ap_ids_by_rel[:reblog_mute] == Enum.sort(User.reblog_muted_users_ap_ids(user))
 +
 +      assert ap_ids_by_rel[:reblog_mute] ==
 +               Enum.sort(Enum.map(User.reblog_muted_users(user), & &1.ap_id))
 +
 +      assert ap_ids_by_rel[:inverse_subscription] == Enum.sort(User.subscriber_users_ap_ids(user))
 +
 +      assert ap_ids_by_rel[:inverse_subscription] ==
 +               Enum.sort(Enum.map(User.subscriber_users(user), & &1.ap_id))
 +
 +      outgoing_relations_ap_ids = User.outgoing_relations_ap_ids(user, rel_types)
 +
 +      assert ap_ids_by_rel ==
 +               Enum.into(outgoing_relations_ap_ids, %{}, fn {k, v} -> {k, Enum.sort(v)} end)
 +    end
 +  end
 +
    describe "when tags are nil" do
      test "tagging a user" do
        user = insert(:user, %{tags: nil})