Change user.discoverable field to user.is_discoverable

This commit is contained in:
Mark Felder 2020-10-13 09:45:08 -05:00
parent eea879eb36
commit 8bacdc3680
23 changed files with 52 additions and 37 deletions

View 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 @@ def remote_user_changeset(struct \\ %User{local: false}, params) do
:follower_count,
:fields,
:following_count,
:discoverable,
:is_discoverable,
:invisible,
:actor_type,
:also_known_as,
@ -495,7 +495,7 @@ def update_changeset(struct, params \\ %{}) do
:fields,
:raw_fields,
:pleroma_settings_store,
:discoverable,
:is_discoverable,
:actor_type,
:also_known_as,
:accepts_chat_messages
@ -1618,7 +1618,7 @@ def purge_user_changeset(user) do
pleroma_settings_store: %{},
fields: [],
raw_fields: [],
discoverable: false,
is_discoverable: false,
also_known_as: []
})
end

View file

@ -164,7 +164,7 @@ defp filter_invisible_users(query) 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

View file

@ -1232,7 +1232,7 @@ defp object_to_user_data(data) 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 @@ defp object_to_user_data(data) do
fields: fields,
emoji: emojis,
locked: locked,
discoverable: discoverable,
is_discoverable: is_discoverable,
invisible: invisible,
avatar: avatar,
name: data["name"],

View file

@ -110,7 +110,7 @@ def render("user.json", %{user: user}) 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))

View file

@ -52,7 +52,7 @@ def render("credentials.json", %{user: user, for: for_user}) do
:skip_thread_containment,
:pleroma_settings_store,
:raw_fields,
:discoverable,
:is_discoverable,
:actor_type
])
|> Map.merge(%{

View file

@ -606,7 +606,7 @@ defp update_credentials_request 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 @@ defp update_credentials_request do
pleroma_settings_store: %{"pleroma-fe" => %{"key" => "val"}},
skip_thread_containment: false,
allow_following_move: false,
discoverable: false,
is_discoverable: false,
actor_type: "Person"
}
}

View file

@ -253,7 +253,7 @@ def chats_response do
"sensitive" => false,
"note" => "lain",
"pleroma" => %{
"discoverable" => false,
"is_discoverable" => false,
"actor_type" => "Person"
},
"fields" => []

View 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
},

View 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" => []

View 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,

View file

@ -186,7 +186,7 @@ def update_credentials(%{assigns: %{user: user}, body_params: params} = conn, _p
:show_role,
:skip_thread_containment,
:allow_following_move,
:discoverable,
:is_discoverable,
:accepts_chat_messages
]
|> Enum.reduce(%{}, fn key, acc ->

View file

@ -261,7 +261,7 @@ defp do_render("show.json", %{user: user} = opts) do
sensitive: false,
fields: user.raw_fields,
pleroma: %{
discoverable: user.discoverable,
is_discoverable: user.is_discoverable,
actor_type: user.actor_type
}
},

View 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
[

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

View file

@ -31,7 +31,7 @@ def user_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{},

View file

@ -66,7 +66,7 @@ test "excludes invisible users from results" 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")

View file

@ -1467,7 +1467,7 @@ test "delete/1 purges a user when they wouldn't be fully deleted" 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 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
pleroma_settings_store: %{},
fields: [],
raw_fields: [],
discoverable: false,
is_discoverable: false,
also_known_as: []
} = user
end

View file

@ -180,7 +180,7 @@ test "it returns unapproved user" do
test "it returns non-discoverable users" do
insert(:user)
insert(:user, discoverable: false)
insert(:user, is_discoverable: false)
{:ok, _results, total} = Search.user()

View file

@ -147,14 +147,14 @@ test "updates the user's hide_followers status", %{conn: conn} 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

View file

@ -1278,7 +1278,7 @@ test "registration from trusted app" do
"note" => "",
"pleroma" => %{
"actor_type" => "Person",
"discoverable" => false,
"is_discoverable" => false,
"no_rich_text" => false,
"show_role" => true
},

View file

@ -69,7 +69,7 @@ test "Represent a user account" do
sensitive: false,
pleroma: %{
actor_type: "Person",
discoverable: true
is_discoverable: true
},
fields: []
},
@ -167,7 +167,7 @@ test "Represent a Service(bot) account" do
sensitive: false,
pleroma: %{
actor_type: "Service",
discoverable: true
is_discoverable: true
},
fields: []
},

View file

@ -16,14 +16,14 @@ test "for remote user" 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 @@ test "for local user set to discoverable" 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})

View file

@ -14,13 +14,13 @@ test "for remote user" 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