Merge remote-tracking branch 'pleroma/develop' into feature/disable-account
authorEgor Kislitsyn <egor@kislitsyn.com>
Mon, 22 Apr 2019 06:08:30 +0000 (13:08 +0700)
committerEgor Kislitsyn <egor@kislitsyn.com>
Mon, 22 Apr 2019 06:08:30 +0000 (13:08 +0700)
1  2 
config/config.exs
lib/pleroma/activity.ex
lib/pleroma/notification.ex
lib/pleroma/user.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/router.ex
lib/pleroma/web/twitter_api/controllers/util_controller.ex
lib/pleroma/web/twitter_api/twitter_api.ex
test/user_test.exs
test/web/twitter_api/util_controller_test.exs

Simple merge
index d06fd917d9921d06c12f93de02ba016bd13ed001,4a2ded51819f7dde23a89905609622735262fbb5..9c1c804e060640bb8555923abe80bb131af6ca00
@@@ -249,60 -260,4 +264,14 @@@ defmodule Pleroma.Activity d
      |> where([s], s.actor == ^actor)
      |> Repo.all()
    end
-   def increase_replies_count(id) do
-     Activity
-     |> where(id: ^id)
-     |> update([a],
-       set: [
-         data:
-           fragment(
-             """
-             jsonb_set(?, '{object, repliesCount}',
-               (coalesce((?->'object'->>'repliesCount')::int, 0) + 1)::varchar::jsonb, true)
-             """,
-             a.data,
-             a.data
-           )
-       ]
-     )
-     |> Repo.update_all([])
-     |> case do
-       {1, [activity]} -> activity
-       _ -> {:error, "Not found"}
-     end
-   end
-   def decrease_replies_count(id) do
-     Activity
-     |> where(id: ^id)
-     |> update([a],
-       set: [
-         data:
-           fragment(
-             """
-             jsonb_set(?, '{object, repliesCount}',
-               (greatest(0, (?->'object'->>'repliesCount')::int - 1))::varchar::jsonb, true)
-             """,
-             a.data,
-             a.data
-           )
-       ]
-     )
-     |> Repo.update_all([])
-     |> case do
-       {1, [activity]} -> activity
-       _ -> {:error, "Not found"}
-     end
-   end
 +
 +  def restrict_deactivated_users(query) do
 +    from(activity in query,
 +      where:
 +        fragment(
 +          "? not in (SELECT ap_id FROM users WHERE info->'deactivated' @> 'true')",
 +          activity.actor
 +        )
 +    )
 +  end
  end
Simple merge
Simple merge
Simple merge
index ac1675d0f774677f3b13362a2d745636f54bf771,eee6881eb7f49cf145df5f90a78b4d8307e22777..a5f9318533d49ba4dd9ada1c17498543f281d7ee
@@@ -5,10 -5,9 +5,10 @@@
  defmodule Pleroma.UserTest do
    alias Pleroma.Activity
    alias Pleroma.Builders.UserBuilder
-   alias Pleroma.Notification
+   alias Pleroma.Object
    alias Pleroma.Repo
    alias Pleroma.User
 +  alias Pleroma.Web.ActivityPub.ActivityPub
    alias Pleroma.Web.CommonAPI
  
    use Pleroma.DataCase
      assert addressed in recipients
    end
  
 -  test ".deactivate can de-activate then re-activate a user" do
 -    user = insert(:user)
 -    assert false == user.info.deactivated
 -    {:ok, user} = User.deactivate(user)
 -    assert true == user.info.deactivated
 -    {:ok, user} = User.deactivate(user, false)
 -    assert false == user.info.deactivated
 +  describe ".deactivate" do
 +    test "can de-activate then re-activate a user" do
 +      user = insert(:user)
 +      assert false == user.info.deactivated
 +      {:ok, user} = User.deactivate(user)
 +      assert true == user.info.deactivated
 +      {:ok, user} = User.deactivate(user, false)
 +      assert false == user.info.deactivated
 +    end
 +
 +    test "hide a user from followers " do
 +      user = insert(:user)
 +      user2 = insert(:user)
 +
 +      {:ok, user} = User.follow(user, user2)
 +      {:ok, _user} = User.deactivate(user)
 +
 +      info = User.get_cached_user_info(user2)
 +
 +      assert info.follower_count == 0
 +      assert {:ok, []} = User.get_followers(user2)
 +    end
 +
 +    test "hide a user from friends" do
 +      user = insert(:user)
 +      user2 = insert(:user)
 +
 +      {:ok, user2} = User.follow(user2, user)
 +      assert User.following_count(user2) == 1
 +
 +      {:ok, _user} = User.deactivate(user)
 +
 +      info = User.get_cached_user_info(user2)
 +
 +      assert info.following_count == 0
 +      assert User.following_count(user2) == 0
 +      assert {:ok, []} = User.get_friends(user2)
 +    end
 +
 +    test "hide a user's statuses from timelines and notifications" do
 +      user = insert(:user)
 +      user2 = insert(:user)
 +
 +      {:ok, user2} = User.follow(user2, user)
 +
 +      {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
 +
-       [notification] = Notification.for_user(user2)
-       assert notification.activity == activity
++      [notification] = Pleroma.Notification.for_user(user2)
++      assert notification.activity.id == activity.id
 +
 +      assert [activity] == ActivityPub.fetch_public_activities(%{})
 +
 +      assert [activity] ==
 +               ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
 +               |> ActivityPub.contain_timeline(user2)
 +
 +      {:ok, _user} = User.deactivate(user)
 +
 +      assert [] == ActivityPub.fetch_public_activities(%{})
-       assert [] == Notification.for_user(user2)
++      assert [] == Pleroma.Notification.for_user(user2)
 +
 +      assert [] ==
 +               ActivityPub.fetch_activities([user2.ap_id | user2.following], %{"user" => user2})
 +               |> ActivityPub.contain_timeline(user2)
 +    end
    end
  
    test ".delete_user_activities deletes all create activities" do