Merge branch 'fix/invisible-repeats' into 'develop'
Do not include activities of invisible users unless explicitly requested Closes #1833 See merge request pleroma/pleroma!2620
This commit is contained in:
commit
cd2abcc0e3
@ -45,7 +45,7 @@ defmodule Pleroma.User.Query do
|
|||||||
is_admin: boolean(),
|
is_admin: boolean(),
|
||||||
is_moderator: boolean(),
|
is_moderator: boolean(),
|
||||||
super_users: boolean(),
|
super_users: boolean(),
|
||||||
exclude_service_users: boolean(),
|
invisible: boolean(),
|
||||||
followers: User.t(),
|
followers: User.t(),
|
||||||
friends: User.t(),
|
friends: User.t(),
|
||||||
recipients_from_activity: [String.t()],
|
recipients_from_activity: [String.t()],
|
||||||
@ -89,8 +89,8 @@ defmodule Pleroma.User.Query do
|
|||||||
where(query, [u], ilike(field(u, ^key), ^"%#{value}%"))
|
where(query, [u], ilike(field(u, ^key), ^"%#{value}%"))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({:exclude_service_users, _}, query) do
|
defp compose_query({:invisible, bool}, query) when is_boolean(bool) do
|
||||||
where(query, [u], not like(u.ap_id, "%/relay") and not like(u.ap_id, "%/internal/fetch"))
|
where(query, [u], u.invisible == ^bool)
|
||||||
end
|
end
|
||||||
|
|
||||||
defp compose_query({key, value}, query)
|
defp compose_query({key, value}, query)
|
||||||
|
@ -1030,6 +1030,17 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp exclude_invisible_actors(query, %{"invisible_actors" => true}), do: query
|
||||||
|
|
||||||
|
defp exclude_invisible_actors(query, _opts) do
|
||||||
|
invisible_ap_ids =
|
||||||
|
User.Query.build(%{invisible: true, select: [:ap_id]})
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.map(fn %{ap_id: ap_id} -> ap_id end)
|
||||||
|
|
||||||
|
from([activity] in query, where: activity.actor not in ^invisible_ap_ids)
|
||||||
|
end
|
||||||
|
|
||||||
defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do
|
defp exclude_id(query, %{"exclude_id" => id}) when is_binary(id) do
|
||||||
from(activity in query, where: activity.id != ^id)
|
from(activity in query, where: activity.id != ^id)
|
||||||
end
|
end
|
||||||
@ -1135,6 +1146,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|
|||||||
|> restrict_instance(opts)
|
|> restrict_instance(opts)
|
||||||
|> Activity.restrict_deactivated_users()
|
|> Activity.restrict_deactivated_users()
|
||||||
|> exclude_poll_votes(opts)
|
|> exclude_poll_votes(opts)
|
||||||
|
|> exclude_invisible_actors(opts)
|
||||||
|> exclude_visibility(opts)
|
|> exclude_visibility(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@ defmodule Pleroma.Web.AdminAPI.Search do
|
|||||||
query =
|
query =
|
||||||
params
|
params
|
||||||
|> Map.drop([:page, :page_size])
|
|> Map.drop([:page, :page_size])
|
||||||
|> Map.put(:exclude_service_users, true)
|
|> Map.put(:invisible, false)
|
||||||
|> User.Query.build()
|
|> User.Query.build()
|
||||||
|> order_by([u], u.nickname)
|
|> order_by([u], u.nickname)
|
||||||
|
|
||||||
@ -31,7 +31,6 @@ defmodule Pleroma.Web.AdminAPI.Search do
|
|||||||
count = Repo.aggregate(query, :count, :id)
|
count = Repo.aggregate(query, :count, :id)
|
||||||
|
|
||||||
results = Repo.all(paginated_query)
|
results = Repo.all(paginated_query)
|
||||||
|
|
||||||
{:ok, results, count}
|
{:ok, results, count}
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -65,7 +65,8 @@ defmodule Mix.Tasks.Pleroma.RelayTest do
|
|||||||
"type" => "Undo",
|
"type" => "Undo",
|
||||||
"actor_id" => follower_id,
|
"actor_id" => follower_id,
|
||||||
"limit" => 1,
|
"limit" => 1,
|
||||||
"skip_preload" => true
|
"skip_preload" => true,
|
||||||
|
"invisible_actors" => true
|
||||||
})
|
})
|
||||||
|
|
||||||
assert undo_activity.data["type"] == "Undo"
|
assert undo_activity.data["type"] == "Undo"
|
||||||
|
@ -757,8 +757,8 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "pagination works correctly with service users", %{conn: conn} do
|
test "pagination works correctly with service users", %{conn: conn} do
|
||||||
service1 = insert(:user, ap_id: Web.base_url() <> "/relay")
|
service1 = User.get_or_create_service_actor_by_ap_id(Web.base_url() <> "/meido", "meido")
|
||||||
service2 = insert(:user, ap_id: Web.base_url() <> "/internal/fetch")
|
|
||||||
insert_list(25, :user)
|
insert_list(25, :user)
|
||||||
|
|
||||||
assert %{"count" => 26, "page_size" => 10, "users" => users1} =
|
assert %{"count" => 26, "page_size" => 10, "users" => users1} =
|
||||||
@ -767,8 +767,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
assert Enum.count(users1) == 10
|
assert Enum.count(users1) == 10
|
||||||
assert service1 not in [users1]
|
assert service1 not in users1
|
||||||
assert service2 not in [users1]
|
|
||||||
|
|
||||||
assert %{"count" => 26, "page_size" => 10, "users" => users2} =
|
assert %{"count" => 26, "page_size" => 10, "users" => users2} =
|
||||||
conn
|
conn
|
||||||
@ -776,8 +775,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
assert Enum.count(users2) == 10
|
assert Enum.count(users2) == 10
|
||||||
assert service1 not in [users2]
|
assert service1 not in users2
|
||||||
assert service2 not in [users2]
|
|
||||||
|
|
||||||
assert %{"count" => 26, "page_size" => 10, "users" => users3} =
|
assert %{"count" => 26, "page_size" => 10, "users" => users3} =
|
||||||
conn
|
conn
|
||||||
@ -785,8 +783,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
assert Enum.count(users3) == 6
|
assert Enum.count(users3) == 6
|
||||||
assert service1 not in [users3]
|
assert service1 not in users3
|
||||||
assert service2 not in [users3]
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "renders empty array for the second page", %{conn: conn} do
|
test "renders empty array for the second page", %{conn: conn} do
|
||||||
|
Loading…
Reference in New Issue
Block a user