Browse Source

Change user.discoverable field to user.is_discoverable

merge-requests/3092/head
Mark Felder 3 years ago
parent
commit
8bacdc3680
23 changed files with 52 additions and 37 deletions
  1. +4
    -4
      lib/pleroma/user.ex
  2. +1
    -1
      lib/pleroma/user/search.ex
  3. +2
    -2
      lib/pleroma/web/activity_pub/activity_pub.ex
  4. +1
    -1
      lib/pleroma/web/activity_pub/views/user_view.ex
  5. +1
    -1
      lib/pleroma/web/admin_api/views/account_view.ex
  6. +2
    -2
      lib/pleroma/web/api_spec/operations/account_operation.ex
  7. +1
    -1
      lib/pleroma/web/api_spec/operations/chat_operation.ex
  8. +2
    -2
      lib/pleroma/web/api_spec/schemas/account.ex
  9. +1
    -1
      lib/pleroma/web/api_spec/schemas/chat.ex
  10. +1
    -1
      lib/pleroma/web/api_spec/schemas/status.ex
  11. +1
    -1
      lib/pleroma/web/mastodon_api/controllers/account_controller.ex
  12. +1
    -1
      lib/pleroma/web/mastodon_api/views/account_view.ex
  13. +1
    -1
      lib/pleroma/web/metadata/restrict_indexing.ex
  14. +15
    -0
      priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs
  15. +1
    -1
      test/support/factory.ex
  16. +1
    -1
      test/user_search_test.exs
  17. +2
    -2
      test/user_test.exs
  18. +1
    -1
      test/web/admin_api/search_test.exs
  19. +4
    -4
      test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs
  20. +1
    -1
      test/web/mastodon_api/controllers/account_controller_test.exs
  21. +2
    -2
      test/web/mastodon_api/views/account_view_test.exs
  22. +4
    -4
      test/web/metadata/metadata_test.exs
  23. +2
    -2
      test/web/metadata/restrict_indexing_test.exs

+ 4
- 4
lib/pleroma/user.ex View File

@@ -136,7 +136,7 @@ defmodule Pleroma.User do
field(:pleroma_settings_store, :map, default: %{}) field(:pleroma_settings_store, :map, default: %{})
field(:fields, {:array, :map}, default: []) field(:fields, {:array, :map}, default: [])
field(:raw_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(:invisible, :boolean, default: false)
field(:allow_following_move, :boolean, default: true) field(:allow_following_move, :boolean, default: true)
field(:skip_thread_containment, :boolean, default: false) field(:skip_thread_containment, :boolean, default: false)
@@ -448,7 +448,7 @@ defmodule Pleroma.User do
:follower_count, :follower_count,
:fields, :fields,
:following_count, :following_count,
:discoverable,
:is_discoverable,
:invisible, :invisible,
:actor_type, :actor_type,
:also_known_as, :also_known_as,
@@ -495,7 +495,7 @@ defmodule Pleroma.User do
:fields, :fields,
:raw_fields, :raw_fields,
:pleroma_settings_store, :pleroma_settings_store,
:discoverable,
:is_discoverable,
:actor_type, :actor_type,
:also_known_as, :also_known_as,
:accepts_chat_messages :accepts_chat_messages
@@ -1618,7 +1618,7 @@ defmodule Pleroma.User do
pleroma_settings_store: %{}, pleroma_settings_store: %{},
fields: [], fields: [],
raw_fields: [], raw_fields: [],
discoverable: false,
is_discoverable: false,
also_known_as: [] also_known_as: []
}) })
end end


+ 1
- 1
lib/pleroma/user/search.ex View File

@@ -164,7 +164,7 @@ defmodule Pleroma.User.Search do
end end


defp filter_discoverable_users(query) do defp filter_discoverable_users(query) do
from(q in query, where: q.discoverable == true)
from(q in query, where: q.is_discoverable == true)
end end


defp filter_internal_users(query) do defp filter_internal_users(query) do


+ 2
- 2
lib/pleroma/web/activity_pub/activity_pub.ex View File

@@ -1232,7 +1232,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
capabilities = data["capabilities"] || %{} capabilities = data["capabilities"] || %{}
accepts_chat_messages = capabilities["acceptsChatMessages"] accepts_chat_messages = capabilities["acceptsChatMessages"]
data = Transmogrifier.maybe_fix_user_object(data) data = Transmogrifier.maybe_fix_user_object(data)
discoverable = data["discoverable"] || false
is_discoverable = data["is_discoverable"] || false
invisible = data["invisible"] || false invisible = data["invisible"] || false
actor_type = data["type"] || "Person" actor_type = data["type"] || "Person"


@@ -1258,7 +1258,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
fields: fields, fields: fields,
emoji: emojis, emoji: emojis,
locked: locked, locked: locked,
discoverable: discoverable,
is_discoverable: is_discoverable,
invisible: invisible, invisible: invisible,
avatar: avatar, avatar: avatar,
name: data["name"], name: data["name"],


+ 1
- 1
lib/pleroma/web/activity_pub/views/user_view.ex View File

@@ -110,7 +110,7 @@ defmodule Pleroma.Web.ActivityPub.UserView do
"endpoints" => endpoints, "endpoints" => endpoints,
"attachment" => fields, "attachment" => fields,
"tag" => emoji_tags, "tag" => emoji_tags,
"discoverable" => user.discoverable,
"is_discoverable" => user.is_discoverable,
"capabilities" => capabilities "capabilities" => capabilities
} }
|> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user)) |> Map.merge(maybe_make_image(&User.avatar_url/2, "icon", user))


+ 1
- 1
lib/pleroma/web/admin_api/views/account_view.ex View File

@@ -52,7 +52,7 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
:skip_thread_containment, :skip_thread_containment,
:pleroma_settings_store, :pleroma_settings_store,
:raw_fields, :raw_fields,
:discoverable,
:is_discoverable,
:actor_type :actor_type
]) ])
|> Map.merge(%{ |> Map.merge(%{


+ 2
- 2
lib/pleroma/web/api_spec/operations/account_operation.ex View File

@@ -606,7 +606,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
description: "Sets the background image of the user.", description: "Sets the background image of the user.",
format: :binary format: :binary
}, },
discoverable: %Schema{
is_discoverable: %Schema{
allOf: [BooleanLike], allOf: [BooleanLike],
nullable: true, nullable: true,
description: description:
@@ -630,7 +630,7 @@ defmodule Pleroma.Web.ApiSpec.AccountOperation do
pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}}, pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
skip_thread_containment: false, skip_thread_containment: false,
allow_following_move: false, allow_following_move: false,
discoverable: false,
is_discoverable: false,
actor_type: "Person" actor_type: "Person"
} }
} }


+ 1
- 1
lib/pleroma/web/api_spec/operations/chat_operation.ex View File

@@ -253,7 +253,7 @@ defmodule Pleroma.Web.ApiSpec.ChatOperation do
"sensitive" => false, "sensitive" => false,
"note" => "lain", "note" => "lain",
"pleroma" => %{ "pleroma" => %{
"discoverable" => false,
"is_discoverable" => false,
"actor_type" => "Person" "actor_type" => "Person"
}, },
"fields" => [] "fields" => []


+ 2
- 2
lib/pleroma/web/api_spec/schemas/account.ex View File

@@ -124,7 +124,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
type: :object, type: :object,
properties: %{ properties: %{
actor_type: ActorType, actor_type: ActorType,
discoverable: %Schema{
is_discoverable: %Schema{
type: :boolean, type: :boolean,
description: description:
"whether the user allows discovery of the account in search results and other services." "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", "note" => "foobar",
"pleroma" => %{ "pleroma" => %{
"actor_type" => "Person", "actor_type" => "Person",
"discoverable" => false,
"is_discoverable" => false,
"no_rich_text" => false, "no_rich_text" => false,
"show_role" => true "show_role" => true
}, },


+ 1
- 1
lib/pleroma/web/api_spec/schemas/chat.ex View File

@@ -44,7 +44,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Chat do
"sensitive" => false, "sensitive" => false,
"note" => "lain", "note" => "lain",
"pleroma" => %{ "pleroma" => %{
"discoverable" => false,
"is_discoverable" => false,
"actor_type" => "Person" "actor_type" => "Person"
}, },
"fields" => [] "fields" => []


+ 1
- 1
lib/pleroma/web/api_spec/schemas/status.ex View File

@@ -284,7 +284,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Status do
"source" => %{ "source" => %{
"fields" => [], "fields" => [],
"note" => "Tester Number 6", "note" => "Tester Number 6",
"pleroma" => %{"actor_type" => "Person", "discoverable" => false},
"pleroma" => %{"actor_type" => "Person", "is_discoverable" => false},
"sensitive" => false "sensitive" => false
}, },
"statuses_count" => 1, "statuses_count" => 1,


+ 1
- 1
lib/pleroma/web/mastodon_api/controllers/account_controller.ex View File

@@ -186,7 +186,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
:show_role, :show_role,
:skip_thread_containment, :skip_thread_containment,
:allow_following_move, :allow_following_move,
:discoverable,
:is_discoverable,
:accepts_chat_messages :accepts_chat_messages
] ]
|> Enum.reduce(%{}, fn key, acc -> |> Enum.reduce(%{}, fn key, acc ->


+ 1
- 1
lib/pleroma/web/mastodon_api/views/account_view.ex View File

@@ -261,7 +261,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
sensitive: false, sensitive: false,
fields: user.raw_fields, fields: user.raw_fields,
pleroma: %{ pleroma: %{
discoverable: user.discoverable,
is_discoverable: user.is_discoverable,
actor_type: user.actor_type actor_type: user.actor_type
} }
}, },


+ 1
- 1
lib/pleroma/web/metadata/restrict_indexing.ex View File

@@ -10,7 +10,7 @@ defmodule Pleroma.Web.Metadata.Providers.RestrictIndexing do
""" """


@impl true @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 def build_tags(_) do
[ [


+ 15
- 0
priv/repo/migrations/20201013144052_refactor_discoverable_user_field.exs View File

@@ -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

+ 1
- 1
test/support/factory.ex View File

@@ -31,7 +31,7 @@ defmodule Pleroma.Factory do
nickname: sequence(:nickname, &"nick#{&1}"), nickname: sequence(:nickname, &"nick#{&1}"),
password_hash: Pbkdf2.hash_pwd_salt("test"), password_hash: Pbkdf2.hash_pwd_salt("test"),
bio: sequence(:bio, &"Tester Number #{&1}"), bio: sequence(:bio, &"Tester Number #{&1}"),
discoverable: true,
is_discoverable: true,
last_digest_emailed_at: NaiveDateTime.utc_now(), last_digest_emailed_at: NaiveDateTime.utc_now(),
last_refreshed_at: NaiveDateTime.utc_now(), last_refreshed_at: NaiveDateTime.utc_now(),
notification_settings: %Pleroma.User.NotificationSetting{}, notification_settings: %Pleroma.User.NotificationSetting{},


+ 1
- 1
test/user_search_test.exs View File

@@ -66,7 +66,7 @@ defmodule Pleroma.UserSearchTest do
end end


test "excludes users when discoverable is false" do 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"}) insert(:user, %{nickname: "john 3001"})


users = User.search("john") users = User.search("john")


+ 2
- 2
test/user_test.exs View File

@@ -1467,7 +1467,7 @@ defmodule Pleroma.UserTest do
pleroma_settings_store: %{"q" => "x"}, pleroma_settings_store: %{"q" => "x"},
fields: [%{"gg" => "qq"}], fields: [%{"gg" => "qq"}],
raw_fields: [%{"gg" => "qq"}], raw_fields: [%{"gg" => "qq"}],
discoverable: true,
is_discoverable: true,
also_known_as: ["https://lol.olo/users/loll"] also_known_as: ["https://lol.olo/users/loll"]
}) })


@@ -1509,7 +1509,7 @@ defmodule Pleroma.UserTest do
pleroma_settings_store: %{}, pleroma_settings_store: %{},
fields: [], fields: [],
raw_fields: [], raw_fields: [],
discoverable: false,
is_discoverable: false,
also_known_as: [] also_known_as: []
} = user } = user
end end


+ 1
- 1
test/web/admin_api/search_test.exs View File

@@ -180,7 +180,7 @@ defmodule Pleroma.Web.AdminAPI.SearchTest do


test "it returns non-discoverable users" do test "it returns non-discoverable users" do
insert(:user) insert(:user)
insert(:user, discoverable: false)
insert(:user, is_discoverable: false)


{:ok, _results, total} = Search.user() {:ok, _results, total} = Search.user()




+ 4
- 4
test/web/mastodon_api/controllers/account_controller/update_credentials_test.exs View File

@@ -147,14 +147,14 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
end end


test "updates the user's discoverable status", %{conn: conn} do test "updates the user's discoverable status", %{conn: conn} do
assert %{"source" => %{"pleroma" => %{"discoverable" => true}}} =
assert %{"source" => %{"pleroma" => %{"is_discoverable" => true}}} =
conn conn
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "true"})
|> patch("/api/v1/accounts/update_credentials", %{is_discoverable: "true"})
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)


assert %{"source" => %{"pleroma" => %{"discoverable" => false}}} =
assert %{"source" => %{"pleroma" => %{"is_discoverable" => false}}} =
conn conn
|> patch("/api/v1/accounts/update_credentials", %{discoverable: "false"})
|> patch("/api/v1/accounts/update_credentials", %{is_discoverable: "false"})
|> json_response_and_validate_schema(:ok) |> json_response_and_validate_schema(:ok)
end end




+ 1
- 1
test/web/mastodon_api/controllers/account_controller_test.exs View File

@@ -1278,7 +1278,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
"note" => "", "note" => "",
"pleroma" => %{ "pleroma" => %{
"actor_type" => "Person", "actor_type" => "Person",
"discoverable" => false,
"is_discoverable" => false,
"no_rich_text" => false, "no_rich_text" => false,
"show_role" => true "show_role" => true
}, },


+ 2
- 2
test/web/mastodon_api/views/account_view_test.exs View File

@@ -69,7 +69,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
sensitive: false, sensitive: false,
pleroma: %{ pleroma: %{
actor_type: "Person", actor_type: "Person",
discoverable: true
is_discoverable: true
}, },
fields: [] fields: []
}, },
@@ -167,7 +167,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
sensitive: false, sensitive: false,
pleroma: %{ pleroma: %{
actor_type: "Service", actor_type: "Service",
discoverable: true
is_discoverable: true
}, },
fields: [] fields: []
}, },


+ 4
- 4
test/web/metadata/metadata_test.exs View File

@@ -16,14 +16,14 @@ defmodule Pleroma.Web.MetadataTest do
end end


test "for local user" do test "for local user" do
user = insert(:user, discoverable: false)
user = insert(:user, is_discoverable: false)


assert Pleroma.Web.Metadata.build_tags(%{user: user}) =~ assert Pleroma.Web.Metadata.build_tags(%{user: user}) =~
"<meta content=\"noindex, noarchive\" name=\"robots\">" "<meta content=\"noindex, noarchive\" name=\"robots\">"
end end


test "for local user set to discoverable" do 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}) =~ refute Pleroma.Web.Metadata.build_tags(%{user: user}) =~
"<meta content=\"noindex, noarchive\" name=\"robots\">" "<meta content=\"noindex, noarchive\" name=\"robots\">"
@@ -33,14 +33,14 @@ defmodule Pleroma.Web.MetadataTest do
describe "no metadata for private instances" do describe "no metadata for private instances" do
test "for local user set to discoverable" do test "for local user set to discoverable" do
clear_config([:instance, :public], false) 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}) assert "" = Pleroma.Web.Metadata.build_tags(%{user: user})
end end


test "search exclusion metadata is included" do test "search exclusion metadata is included" do
clear_config([:instance, :public], false) 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">) == assert ~s(<meta content="noindex, noarchive" name="robots">) ==
Pleroma.Web.Metadata.build_tags(%{user: user}) Pleroma.Web.Metadata.build_tags(%{user: user})


+ 2
- 2
test/web/metadata/restrict_indexing_test.exs View File

@@ -14,13 +14,13 @@ defmodule Pleroma.Web.Metadata.Providers.RestrictIndexingTest do


test "for local user" do test "for local user" do
assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{ assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{
user: %Pleroma.User{local: true, discoverable: true}
user: %Pleroma.User{local: true, is_discoverable: true}
}) == [] }) == []
end end


test "for local user when discoverable is false" do test "for local user when discoverable is false" do
assert Pleroma.Web.Metadata.Providers.RestrictIndexing.build_tags(%{ 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"], []}] }) == [{:meta, [name: "robots", content: "noindex, noarchive"], []}]
end end
end end


Loading…
Cancel
Save