From 24ff99ffaf24e4f1e6b58003ce4656d4d2160a7d Mon Sep 17 00:00:00 2001 From: Thomas Citharel Date: Mon, 23 Aug 2021 10:34:33 +0200 Subject: [PATCH] Search should return only groups, don't show user profiles Closes #845 Signed-off-by: Thomas Citharel --- lib/graphql/api/search.ex | 6 +++++- test/graphql/api/search_test.exs | 8 +++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/lib/graphql/api/search.ex b/lib/graphql/api/search.ex index 090eccf1..f5b34225 100644 --- a/lib/graphql/api/search.ex +++ b/lib/graphql/api/search.ex @@ -94,9 +94,13 @@ defmodule Mobilizon.GraphQL.API.Search do @spec process_from_username(String.t()) :: Page.t() defp process_from_username(search) do case ActivityPubActor.find_or_make_actor_from_nickname(search) do - {:ok, actor} -> + {:ok, %Actor{type: :Group} = actor} -> %Page{total: 1, elements: [actor]} + # Don't return anything else than groups + {:ok, %Actor{}} -> + %Page{total: 0, elements: []} + {:error, _err} -> Logger.debug(fn -> "Unable to find or make actor '#{search}'" end) diff --git a/test/graphql/api/search_test.exs b/test/graphql/api/search_test.exs index 2d0b1351..bfd1f4b3 100644 --- a/test/graphql/api/search_test.exs +++ b/test/graphql/api/search_test.exs @@ -16,9 +16,11 @@ defmodule Mobilizon.GraphQL.API.SearchTest do test "search an user by username" do with_mock ActivityPubActor, - find_or_make_actor_from_nickname: fn "toto@domain.tld" -> {:ok, %Actor{id: 42}} end do - assert {:ok, %Page{total: 1, elements: [%Actor{id: 42}]}} == - Search.search_actors(%{term: "toto@domain.tld"}, 1, 10, :Person) + find_or_make_actor_from_nickname: fn "toto@domain.tld" -> + {:ok, %Actor{id: 42, type: :Group}} + end do + assert {:ok, %Page{total: 1, elements: [%Actor{id: 42, type: :Group}]}} == + Search.search_actors(%{term: "toto@domain.tld"}, 1, 10, :Group) assert_called(ActivityPubActor.find_or_make_actor_from_nickname("toto@domain.tld")) end