User search respect discoverable flag
authorstwf <steven.fuchs@dockyard.com>
Mon, 14 Sep 2020 15:40:52 +0000 (11:40 -0400)
committerstwf <steven.fuchs@dockyard.com>
Thu, 17 Sep 2020 16:15:50 +0000 (12:15 -0400)
lib/pleroma/user/search.ex
test/fixtures/tesla_mock/admin@mastdon.example.org.json
test/fixtures/tesla_mock/https___osada.macgirvin.com_channel_mike.json
test/support/factory.ex
test/web/admin_api/search_test.exs
test/web/mastodon_api/views/account_view_test.exs

index 7babd47ea542db084a171d373c2b1bc84aaac836..b8c6486729e04ab920c89ec9a9f8151f147eba57 100644 (file)
@@ -52,6 +52,7 @@ defmodule Pleroma.User.Search do
     |> base_query(following)
     |> filter_blocked_user(for_user)
     |> filter_invisible_users()
+    |> filter_discoverable_users()
     |> filter_internal_users()
     |> filter_blocked_domains(for_user)
     |> fts_search(query_string)
@@ -122,6 +123,10 @@ defmodule Pleroma.User.Search do
     from(q in query, where: q.invisible == false)
   end
 
+  defp filter_discoverable_users(query) do
+    from(q in query, where: q.discoverable == true)
+  end
+
   defp filter_internal_users(query) do
     from(q in query, where: q.actor_type != "Application")
   end
index a911b979a21650e3cdff58c4e2bcdc525c3859f1..f961ccb362994db0b23e5964ce5689c5f28ae4bc 100644 (file)
@@ -1,20 +1,24 @@
 {
-  "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1", {
-    "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
-    "sensitive": "as:sensitive",
-    "movedTo": "as:movedTo",
-    "Hashtag": "as:Hashtag",
-    "ostatus": "http://ostatus.org#",
-    "atomUri": "ostatus:atomUri",
-    "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
-    "conversation": "ostatus:conversation",
-    "toot": "http://joinmastodon.org/ns#",
-    "Emoji": "toot:Emoji",
-    "alsoKnownAs": {
-      "@id": "as:alsoKnownAs",
-      "@type": "@id"
+  "@context": [
+    "https://www.w3.org/ns/activitystreams",
+    "https://w3id.org/security/v1",
+    {
+      "manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
+      "sensitive": "as:sensitive",
+      "movedTo": "as:movedTo",
+      "Hashtag": "as:Hashtag",
+      "ostatus": "http://ostatus.org#",
+      "atomUri": "ostatus:atomUri",
+      "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
+      "conversation": "ostatus:conversation",
+      "toot": "http://joinmastodon.org/ns#",
+      "Emoji": "toot:Emoji",
+      "alsoKnownAs": {
+        "@id": "as:alsoKnownAs",
+        "@type": "@id"
+      }
     }
-  }],
+  ],
   "id": "http://mastodon.example.org/users/admin",
   "type": "Person",
   "following": "http://mastodon.example.org/users/admin/following",
@@ -23,6 +27,7 @@
   "outbox": "http://mastodon.example.org/users/admin/outbox",
   "preferredUsername": "admin",
   "name": null,
+  "discoverable": "true",
   "summary": "\u003cp\u003e\u003c/p\u003e",
   "url": "http://mastodon.example.org/@admin",
   "manuallyApprovesFollowers": false,
@@ -34,7 +39,8 @@
     "owner": "http://mastodon.example.org/users/admin",
     "publicKeyPem": "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtc4Tir+3ADhSNF6VKrtW\nOU32T01w7V0yshmQei38YyiVwVvFu8XOP6ACchkdxbJ+C9mZud8qWaRJKVbFTMUG\nNX4+6Q+FobyuKrwN7CEwhDALZtaN2IPbaPd6uG1B7QhWorrY+yFa8f2TBM3BxnUy\nI4T+bMIZIEYG7KtljCBoQXuTQmGtuffO0UwJksidg2ffCF5Q+K//JfQagJ3UzrR+\nZXbKMJdAw4bCVJYs4Z5EhHYBwQWiXCyMGTd7BGlmMkY6Av7ZqHKC/owp3/0EWDNz\nNqF09Wcpr3y3e8nA10X40MJqp/wR+1xtxp+YGbq/Cj5hZGBG7etFOmIpVBrDOhry\nBwIDAQAB\n-----END PUBLIC KEY-----\n"
   },
-  "attachment": [{
+  "attachment": [
+    {
       "type": "PropertyValue",
       "name": "foo",
       "value": "bar"
@@ -58,5 +64,7 @@
     "mediaType": "image/png",
     "url": "https://cdn.niu.moe/accounts/headers/000/033/323/original/850b3448fa5fd477.png"
   },
-  "alsoKnownAs": ["http://example.org/users/foo"]
-}
+  "alsoKnownAs": [
+    "http://example.org/users/foo"
+  ]
+}
\ No newline at end of file
index c42f3a53ca13794483ccf601fe93e6975bb2d612..ca76d6e17a9b2b969a76f0b431054a6ed241165b 100644 (file)
@@ -8,6 +8,7 @@
     "preferredUsername": "mike",
     "name": "Mike Macgirvin (Osada)",
     "updated": "2018-08-29T03:09:11Z",
+    "discoverable": "true",
     "icon": {
         "type": "Image",
         "mediaType": "image/jpeg",
@@ -51,4 +52,4 @@
         "created": "2018-10-17T07:16:28Z",
         "signatureValue": "WbfFVIPImkd3yNu6brz0CvZaeV242rwAbH0vy8DM4vfnXCxLr5Uv/Wj9gwP+tbooTxGaahAKBeqlGkQp8RLEo37LATrKMRLA/0V6DeeV+C5ORWR9B4WxyWiD3s/9Wf+KesFMtktNLAcMZ5PfnOS/xNYerhnpkp/gWPxtkglmLIWJv+w18A5zZ01JCxsO4QljHbhYaEUPHUfQ97abrkLECeam+FThVwdO6BFCtbjoNXHfzjpSZL/oKyBpi5/fpnqMqOLOQPs5WgBBZJvjEYYkQcoPTyxYI5NGpNbzIjGHPQNuACnOelH16A7L+q4swLWDIaEFeXQ2/5bmqVKZDZZ6usNP4QyTVszwd8jqo27qcDTNibXDUTsTdKpNQvM/3UncBuzuzmUV3FczhtGshIU1/pRVZiQycpVqPlGLvXhP/yZCe+1siyqDd+3uMaS2vkHTObSl5r+VYof+c+TcjrZXHSWnQTg8/X3zkoBWosrQ93VZcwjzMxQoARYv6rphbOoTz7RPmGAXYUt3/PDWkqDlmQDwCpLNNkJo1EidyefZBdD9HXQpCBO0ZU0NHb0JmPvg/+zU0krxlv70bm3RHA/maBETVjroIWzt7EwQEg5pL2hVnvSBG+1wF3BtRVe77etkPOHxLnYYIcAMLlVKCcgDd89DPIziQyruvkx1busHI08="
     }
-}
+}
\ No newline at end of file
index 2fdfabbc5a228c0157a418d3ebdfde250c3f28cc..fb82be0c4d4908b2cb32471a110d8ce9927a61a9 100644 (file)
@@ -31,6 +31,7 @@ defmodule Pleroma.Factory do
       nickname: sequence(:nickname, &"nick#{&1}"),
       password_hash: Pbkdf2.hash_pwd_salt("test"),
       bio: sequence(:bio, &"Tester Number #{&1}"),
+      discoverable: true,
       last_digest_emailed_at: NaiveDateTime.utc_now(),
       last_refreshed_at: NaiveDateTime.utc_now(),
       notification_settings: %Pleroma.User.NotificationSetting{},
index b974cedd5a2dd7ce11566bef41b76a0534c2036e..d88867c5272e0242b0978d809999dcc6c2df191d 100644 (file)
@@ -177,5 +177,14 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
       assert total == 3
       assert count == 1
     end
+
+    test "it returns non-discoverable users" do
+      insert(:user)
+      insert(:user, discoverable: false)
+
+      {:ok, _results, total} = Search.user()
+
+      assert total == 2
+    end
   end
 end
index c5f491d6bd69da77ab2a7e5584e3bacf14739351..a54b765efdb8a110349d5f01781292a6e0b9d399 100644 (file)
@@ -68,7 +68,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         sensitive: false,
         pleroma: %{
           actor_type: "Person",
-          discoverable: false
+          discoverable: true
         },
         fields: []
       },
@@ -166,7 +166,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         sensitive: false,
         pleroma: %{
           actor_type: "Service",
-          discoverable: false
+          discoverable: true
         },
         fields: []
       },