Change user.discoverable field to user.is_discoverable
authorMark Felder <feld@FreeBSD.org>
Tue, 13 Oct 2020 14:45:08 +0000 (09:45 -0500)
committerMark Felder <feld@FreeBSD.org>
Tue, 13 Oct 2020 14:45:08 +0000 (09:45 -0500)
23 files changed:
lib/pleroma/user.ex
lib/pleroma/user/search.ex
lib/pleroma/web/activity_pub/activity_pub.ex
lib/pleroma/web/activity_pub/views/user_view.ex
lib/pleroma/web/admin_api/views/account_view.ex
lib/pleroma/web/api_spec/operations/account_operation.ex
lib/pleroma/web/api_spec/operations/chat_operation.ex
lib/pleroma/web/api_spec/schemas/account.ex
lib/pleroma/web/api_spec/schemas/chat.ex
lib/pleroma/web/api_spec/schemas/status.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/metadata/restrict_indexing.ex
priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs [new file with mode: 0644]
test/support/factory.ex
test/user_search_test.exs
test/user_test.exs
test/web/admin_api/search_test.exs
test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
test/web/mastodon_api/controllers/account_controller_test.exs
test/web/mastodon_api/views/account_view_test.exs
test/web/metadata/metadata_test.exs
test/web/metadata/restrict_indexing_test.exs

index 09ea8079391b6b8c7c882ee7d19778e58c1bce42..c4640f928b3d3f1c25d50ab7ac2baa8594b401ae 100644 (file)
@@ -136,7 +136,7 @@ defmodule Pleroma.User do
     field(:pleroma_settings_store, :map, default: %{})
     field(:fields, {:array, :map}, default: [])
     field(:raw_fields, {:array, :map}, default: [])
-    field(:discoverable, :boolean, default: false)
+    field(:is_discoverable, :boolean, default: false)
     field(:invisible, :boolean, default: false)
     field(:allow_following_move, :boolean, default: true)
     field(:skip_thread_containment, :boolean, default: false)
@@ -448,7 +448,7 @@ defmodule Pleroma.User do
         :follower_count,
         :fields,
         :following_count,
-        :discoverable,
+        :is_discoverable,
         :invisible,
         :actor_type,
         :also_known_as,
@@ -495,7 +495,7 @@ defmodule Pleroma.User do
         :fields,
         :raw_fields,
         :pleroma_settings_store,
-        :discoverable,
+        :is_discoverable,
         :actor_type,
         :also_known_as,
         :accepts_chat_messages
@@ -1618,7 +1618,7 @@ defmodule Pleroma.User do
       pleroma_settings_store: %{},
       fields: [],
       raw_fields: [],
-      discoverable: false,
+      is_discoverable: false,
       also_known_as: []
     })
   end
index 35a828008ceb34e6b6653b34d47df68b65c54d53..2dab672112b9636c1e62fda0beb630f37d162216 100644 (file)
@@ -164,7 +164,7 @@ defmodule Pleroma.User.Search do
   end
 
   defp filter_discoverable_users(query) do
-    from(q in query, where: q.discoverable == true)
+    from(q in query, where: q.is_discoverable == true)
   end
 
   defp filter_internal_users(query) do
index eb44cffec14eddb5634a3973a1f6625fbcd14acb..236fefbb6afbc0cf0f1f0b9bd78002899504c948 100644 (file)
@@ -1232,7 +1232,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
     capabilities = data["capabilities"] || %{}
     accepts_chat_messages = capabilities["acceptsChatMessages"]
     data = Transmogrifier.maybe_fix_user_object(data)
-    discoverable = data["discoverable"] || false
+    is_discoverable = data["is_discoverable"] || false
     invisible = data["invisible"] || false
     actor_type = data["type"] || "Person"
 
@@ -1258,7 +1258,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
       fields: fields,
       emoji: emojis,
       locked: locked,
-      discoverable: discoverable,
+      is_discoverable: is_discoverable,
       invisible: invisible,
       avatar: avatar,
       name: data["name"],
index 3a4564912c2d1508bac155bc79b23f857c528a1d..81cd7e81d33ee1b0ba84f3b50805059e6e2caa88 100644 (file)
@@ -110,7 +110,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
       "endpoints" => endpoints,
       "attachment" => fields,
       "tag" => emoji_tags,
-      "discoverable" => user.discoverable,
+      "is_discoverable" => user.is_discoverable,
       "capabilities" => capabilities
     }
     |> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))
index 9c477feabb49812c96dcade416a9f65b52431015..5f3a78a0ffc6f6ae7fd0c59c8e9d7cd092b5b0c2 100644 (file)
@@ -52,7 +52,7 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
       :skip_thread_containment,
       :pleroma_settings_store,
       :raw_fields,
-      :discoverable,
+      :is_discoverable,
       :actor_type
     ])
     |> Map.merge(%{
index d90ddb78714151d513b798bc99e11e1db275dca0..1696b19a5856f6cbce27082087fd7d017240a6e0 100644 (file)
@@ -606,7 +606,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
           description: "Sets the background image of the user.",
           format: :binary
         },
-        discoverable: %Schema{
+        is_discoverable: %Schema{
           allOf: [BooleanLike],
           nullable: true,
           description:
@@ -630,7 +630,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
         pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
         skip_thread_containment: false,
         allow_following_move: false,
-        discoverable: false,
+        is_discoverable: false,
         actor_type: "Person"
       }
     }
index 0dcfdb35467ef2e04f5493ef04546bb124bffd9b..18693a5d7f183ebb71c106cf549efd4f2178de66 100644 (file)
@@ -253,7 +253,7 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
               "sensitive" => false,
               "note" => "lain",
               "pleroma" => %{
-                "discoverable" => false,
+                "is_discoverable" => false,
                 "actor_type" => "Person"
               },
               "fields" => []
index ca79f0747861b93bb63e5d40022878369ffad247..459e7dba6f5fe9dda4432c80a897f6ac6932cab1 100644 (file)
@@ -124,7 +124,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
             type: :object,
             properties: %{
               actor_type: ActorType,
-              discoverable: %Schema{
+              is_discoverable: %Schema{
                 type: :boolean,
                 description:
                   "whether the user allows discovery of the account in search results and other services."
@@ -205,7 +205,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
         "note" => "foobar",
         "pleroma" => %{
           "actor_type" => "Person",
-          "discoverable" => false,
+          "is_discoverable" => false,
           "no_rich_text" => false,
           "show_role" => true
         },
index b4986b734e9b7613504aa299a7b4b4cd0c226a95..da245d0de8909d3a97ac44782720bbb87a413350 100644 (file)
@@ -44,7 +44,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Chat do
           "sensitive" => false,
           "note" => "lain",
           "pleroma" => %{
-            "discoverable" => false,
+            "is_discoverable" => false,
             "actor_type" => "Person"
           },
           "fields" => []
index 947e42890744d80117615417361bd881f1e9c709..52b870d63f1c8f50e1de6f890f78f8931bf4fe07 100644 (file)
@@ -284,7 +284,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
         "source" => %{
           "fields" => [],
           "note" => "Tester Number 6",
-          "pleroma" => %{"actor_type" => "Person", "discoverable" => false},
+          "pleroma" => %{"actor_type" => "Person", "is_discoverable" => false},
           "sensitive" => false
         },
         "statuses_count" => 1,
index 95d8452df0447f08c540d2b5a8cbbb0a7b81958c..e06ff930772072b3a43b1c408f68310e6157fb08 100644 (file)
@@ -186,7 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
         :show_role,
         :skip_thread_containment,
         :allow_following_move,
-        :discoverable,
+        :is_discoverable,
         :accepts_chat_messages
       ]
       |> Enum.reduce(%{}, fn key, acc ->
index 121ba1693155adf30f4c17b9be4d0c9b111bf001..0636d9cc1164798f4295521bc0d2ad24ab75a995 100644 (file)
@@ -261,7 +261,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
         sensitive: false,
         fields: user.raw_fields,
         pleroma: %{
-          discoverable: user.discoverable,
+          is_discoverable: user.is_discoverable,
           actor_type: user.actor_type
         }
       },
index a1dcb6e15145ea0da013a139a8723a6bb580c51a..900c2434de216363fb9243a91a654d9f7619983d 100644 (file)
@@ -10,7 +10,7 @@ defmodule Pleroma.Web.Metadata.Providers.RestrictIndexing do
   """
 
   @impl true
-  def build_tags(%{user: %{local: true, discoverable: true}}), do: []
+  def build_tags(%{user: %{local: true, is_discoverable: true}}), do: []
 
   def build_tags(_) do
     [
diff --git a/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs b/priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs
new file mode 100644 (file)
index 0000000..3fdc190
--- /dev/null
@@ -0,0 +1,15 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Repo.Migrations.RefactorDiscoverableUserField do
+  use Ecto.Migration
+
+  def up do
+    execute("ALTER TABLE users RENAME COLUMN discoverable TO is_discoverable;")
+  end
+
+  def down do
+    execute("ALTER TABLE users RENAME COLUMN is_discoverable TO discoverable;")
+  end
+end
index fb82be0c4d4908b2cb32471a110d8ce9927a61a9..80b882ee413d5b4a6de7f7dcf3723428eacac4ec 100644 (file)
@@ -31,7 +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,
+      is_discoverable: true,
       last_digest_emailed_at: NaiveDateTime.utc_now(),
       last_refreshed_at: NaiveDateTime.utc_now(),
       notification_settings: %Pleroma.User.NotificationSetting{},
index c4b8050055b04c167ed4e0afeacd65c1f40feb67..31d787ffa0ed35e2ef817c99956a2ee1d5241e7d 100644 (file)
@@ -66,7 +66,7 @@ defmodule Pleroma.UserSearchTest do
     end
 
     test "excludes users when discoverable is false" do
-      insert(:user, %{nickname: "john 3000", discoverable: false})
+      insert(:user, %{nickname: "john 3000", is_discoverable: false})
       insert(:user, %{nickname: "john 3001"})
 
       users = User.search("john")
index d506f704708a6c7f501bf51db735b8f5cd301b21..7d7bf4b78ad35b46d8ae4c22dfa235ea6c3831a5 100644 (file)
@@ -1467,7 +1467,7 @@ defmodule Pleroma.UserTest do
         pleroma_settings_store: %{"q" => "x"},
         fields: [%{"gg" => "qq"}],
         raw_fields: [%{"gg" => "qq"}],
-        discoverable: true,
+        is_discoverable: true,
         also_known_as: ["https://lol.olo/users/loll"]
       })
 
@@ -1509,7 +1509,7 @@ defmodule Pleroma.UserTest do
              pleroma_settings_store: %{},
              fields: [],
              raw_fields: [],
-             discoverable: false,
+             is_discoverable: false,
              also_known_as: []
            } = user
   end
index d88867c5272e0242b0978d809999dcc6c2df191d..ceec64f1e73ec81c78015f5bbe41d5d38ffd90a3 100644 (file)
@@ -180,7 +180,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do
 
     test "it returns non-discoverable users" do
       insert(:user)
-      insert(:user, discoverable: false)
+      insert(:user, is_discoverable: false)
 
       {:ok, _results, total} = Search.user()
 
index 2e67047266089c1d30989fbfffc6be72c4448bbf..d31cc27cc88344cfa5cac26836d6fed7ac377b3b 100644 (file)
@@ -147,14 +147,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
     end
 
     test "updates the user's discoverable status", %{conn: conn} do
-      assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
+      assert %{"source" => %{"pleroma" => %{"is_discoverable" => true}}} =
                conn
-               |> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
+               |> patch("/api/v1/accounts/update_credentials", %{is_discoverable: "true"})
                |> json_response_and_validate_schema(:ok)
 
-      assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
+      assert %{"source" => %{"pleroma" => %{"is_discoverable" => false}}} =
                conn
-               |> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
+               |> patch("/api/v1/accounts/update_credentials", %{is_discoverable: "false"})
                |> json_response_and_validate_schema(:ok)
     end
 
index f7f1369e48e35d70a19d925a2a3c2d2f66a05b00..f7eb97dbb515bf9d9e62e02cf5a55062958ccab3 100644 (file)
@@ -1278,7 +1278,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
                  "note" => "",
                  "pleroma" => %{
                    "actor_type" => "Person",
-                   "discoverable" => false,
+                   "is_discoverable" => false,
                    "no_rich_text" => false,
                    "show_role" => true
                  },
index a5f39b215dd6e5ad92ba2962b49506ed21abaa60..3b0454df24cb73d033e1b7a31e1048aecd05666b 100644 (file)
@@ -69,7 +69,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         sensitive: false,
         pleroma: %{
           actor_type: "Person",
-          discoverable: true
+          is_discoverable: true
         },
         fields: []
       },
@@ -167,7 +167,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         sensitive: false,
         pleroma: %{
           actor_type: "Service",
-          discoverable: true
+          is_discoverable: true
         },
         fields: []
       },
index ca6cbe67faa875c7cf69da661884d4808cdd90b4..8fb946540d92a8774e9abe14fcd43255350e3e1f 100644 (file)
@@ -16,14 +16,14 @@ defmodule Pleroma.Web.MetadataTest do
     end
 
     test "for local user" do
-      user = insert(:user, discoverable: false)
+      user = insert(:user, is_discoverable: false)
 
       assert Pleroma.Web.Metadata.build_tags(%{user: user}) =~
                "<meta content=\"noindex, noarchive\" name=\"robots\">"
     end
 
     test "for local user set to discoverable" do
-      user = insert(:user, discoverable: true)
+      user = insert(:user, is_discoverable: true)
 
       refute Pleroma.Web.Metadata.build_tags(%{user: user}) =~
                "<meta content=\"noindex, noarchive\" name=\"robots\">"
@@ -33,14 +33,14 @@ defmodule Pleroma.Web.MetadataTest do
   describe "no metadata for private instances" do
     test "for local user set to discoverable" do
       clear_config([:instance, :public], false)
-      user = insert(:user, bio: "This is my secret fedi account bio", discoverable: true)
+      user = insert(:user, bio: "This is my secret fedi account bio", is_discoverable: true)
 
       assert "" = Pleroma.Web.Metadata.build_tags(%{user: user})
     end
 
     test "search exclusion metadata is included" do
       clear_config([:instance, :public], false)
-      user = insert(:user, bio: "This is my secret fedi account bio", discoverable: false)
+      user = insert(:user, bio: "This is my secret fedi account bio", is_discoverable: false)
 
       assert ~s(<meta content="noindex, noarchive" name="robots">) ==
                Pleroma.Web.Metadata.build_tags(%{user: user})
index 6b3a653724dcca51d29815b560a1afcc7388b1eb..282d132c8104a672f52087fb52316d24c91de170 100644 (file)
@@ -14,13 +14,13 @@ defmodule Pleroma.Web.Metadata.Providers.RestrictIndexingTest do
 
     test "for local user" do
       assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
-               user: %Pleroma.User{local: true, discoverable: true}
+               user: %Pleroma.User{local: true, is_discoverable: true}
              }) == []
     end
 
     test "for local user when discoverable is false" do
       assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
-               user: %Pleroma.User{local: true, discoverable: false}
+               user: %Pleroma.User{local: true, is_discoverable: false}
              }) == [{:meta, [name: "robots", content: "noindex, noarchive"], []}]
     end
   end