[#1304] Merged `develop`, handled User.Info.invisible.

This commit is contained in:
Ivan Tashkinov 2019-10-21 11:58:22 +03:00
parent a11a7176d5
commit 7c7f90bc4f
6 changed files with 23 additions and 6 deletions

View File

@ -103,6 +103,7 @@ defmodule Pleroma.User do
field(:fields, {:array, :map}, default: nil)
field(:raw_fields, {:array, :map}, default: [])
field(:discoverable, :boolean, default: false)
field(:invisible, :boolean, default: false)
field(:skip_thread_containment, :boolean, default: false)
field(:notification_settings, :map,
@ -142,7 +143,7 @@ def superuser?(%User{local: true, is_admin: true}), do: true
def superuser?(%User{local: true, is_moderator: true}), do: true
def superuser?(_), do: false
def invisible?(%User{info: %User.Info{invisible: true}}), do: true
def invisible?(%User{invisible: true}), do: true
def invisible?(_), do: false
def avatar_url(user, options \\ []) do
@ -264,6 +265,7 @@ def following_count(%User{} = user) do
:fields,
:raw_fields,
:discoverable,
:invisible,
:skip_thread_containment,
:notification_settings
]
@ -321,7 +323,8 @@ def remote_user_creation(params) do
:follower_count,
:fields,
:following_count,
:discoverable
:discoverable,
:invisible
]
)
|> validate_required([:name, :ap_id])
@ -2021,4 +2024,13 @@ def remove_reblog_mute(user, ap_id) do
|> cast(params, [:muted_reblogs])
|> update_and_set_cache()
end
def set_invisible(user, invisible) do
params = %{invisible: invisible}
user
|> cast(params, [:invisible])
|> validate_required([:invisible])
|> update_and_set_cache()
end
end

View File

@ -14,7 +14,7 @@ def get_actor do
"#{Pleroma.Web.Endpoint.url()}/relay"
|> User.get_or_create_service_actor_by_ap_id()
{:ok, actor} = User.update_info(actor, &User.Info.set_invisible(&1, true))
{:ok, actor} = User.set_invisible(actor, true)
actor
end

View File

@ -42,6 +42,7 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do
:fields,
:raw_fields,
:discoverable,
:invisible,
:skip_thread_containment,
:notification_settings
]
@ -77,6 +78,7 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers do
:hide_follows,
:hide_favorites,
:discoverable,
:invisible,
:skip_thread_containment
]
@ -132,6 +134,7 @@ def change do
add(:fields, {:array, :map}, default: nil)
add(:raw_fields, {:array, :map}, default: [])
add(:discoverable, :boolean, default: false, null: false)
add(:invisible, :boolean, default: false, null: false)
add(:notification_settings, :map, default: %{})
add(:skip_thread_containment, :boolean, default: false, null: false)
end

View File

@ -1,8 +1,10 @@
defmodule Pleroma.Repo.Migrations.DropWebsubTables do
use Ecto.Migration
def change do
def up do
drop_if_exists(table(:websub_client_subscriptions))
drop_if_exists(table(:websub_server_subscriptions))
end
def down, do: :noop
end

View File

@ -1233,7 +1233,7 @@ test "returns true for local admins" do
describe "invisible?/1" do
test "returns true for an invisible user" do
user = insert(:user, local: true, info: %{invisible: true})
user = insert(:user, local: true, invisible: true)
assert User.invisible?(user)
end

View File

@ -75,7 +75,7 @@ test "Does not add an avatar image if the user hasn't set one" do
end
test "renders an invisible user with the invisible property set to true" do
user = insert(:user, %{info: %{invisible: true}})
user = insert(:user, invisible: true)
assert %{"invisible" => true} = UserView.render("service.json", %{user: user})
end