From: Ivan Tashkinov Date: Mon, 21 Oct 2019 08:58:22 +0000 (+0300) Subject: [#1304] Merged `develop`, handled User.Info.invisible. X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=7c7f90bc4f361b8bf4b49790640a4aa490ee619f;p=akkoma [#1304] Merged `develop`, handled User.Info.invisible. --- diff --git a/lib/pleroma/user.ex b/lib/pleroma/user.ex index 00a1df133..e8038c1c1 100644 --- a/lib/pleroma/user.ex +++ b/lib/pleroma/user.ex @@ -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 @@ defmodule Pleroma.User do 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 @@ defmodule Pleroma.User do :fields, :raw_fields, :discoverable, + :invisible, :skip_thread_containment, :notification_settings ] @@ -321,7 +323,8 @@ defmodule Pleroma.User do :follower_count, :fields, :following_count, - :discoverable + :discoverable, + :invisible ] ) |> validate_required([:name, :ap_id]) @@ -2021,4 +2024,13 @@ defmodule Pleroma.User 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 diff --git a/lib/pleroma/web/activity_pub/relay.ex b/lib/pleroma/web/activity_pub/relay.ex index de80612f1..a9434d75c 100644 --- a/lib/pleroma/web/activity_pub/relay.ex +++ b/lib/pleroma/web/activity_pub/relay.ex @@ -14,7 +14,7 @@ defmodule Pleroma.Web.ActivityPub.Relay 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 diff --git a/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs index 72c852d2b..87b1e2c8c 100644 --- a/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs +++ b/priv/repo/migrations/20191009154608_copy_users_info_fields_to_users.exs @@ -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 @@ defmodule Pleroma.Repo.Migrations.CopyUsersInfoFieldsToUsers 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 diff --git a/priv/repo/migrations/20191017225002_drop_websub_tables.exs b/priv/repo/migrations/20191017225002_drop_websub_tables.exs index 9e483b2a1..4cf67a59c 100644 --- a/priv/repo/migrations/20191017225002_drop_websub_tables.exs +++ b/priv/repo/migrations/20191017225002_drop_websub_tables.exs @@ -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 diff --git a/test/user_test.exs b/test/user_test.exs index c78e1512a..92de31c74 100644 --- a/test/user_test.exs +++ b/test/user_test.exs @@ -1233,7 +1233,7 @@ defmodule Pleroma.UserTest 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 diff --git a/test/web/activity_pub/views/user_view_test.exs b/test/web/activity_pub/views/user_view_test.exs index 392b717b1..3299be2d5 100644 --- a/test/web/activity_pub/views/user_view_test.exs +++ b/test/web/activity_pub/views/user_view_test.exs @@ -75,7 +75,7 @@ defmodule Pleroma.Web.ActivityPub.UserViewTest 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