[#2456] Dropped support for embedded `pleroma/account/relationship` in statuses and...
authorIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 9 May 2020 15:05:44 +0000 (18:05 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Sat, 9 May 2020 15:05:44 +0000 (18:05 +0300)
14 files changed:
lib/pleroma/web/admin_api/views/account_view.ex
lib/pleroma/web/admin_api/views/report_view.ex
lib/pleroma/web/admin_api/views/status_view.ex
lib/pleroma/web/controller_helper.ex
lib/pleroma/web/mastodon_api/controllers/account_controller.ex
lib/pleroma/web/mastodon_api/controllers/notification_controller.ex
lib/pleroma/web/mastodon_api/controllers/search_controller.ex
lib/pleroma/web/mastodon_api/controllers/status_controller.ex
lib/pleroma/web/mastodon_api/controllers/timeline_controller.ex
lib/pleroma/web/mastodon_api/views/notification_view.ex
lib/pleroma/web/mastodon_api/views/status_view.ex
lib/pleroma/web/pleroma_api/controllers/account_controller.ex
lib/pleroma/web/pleroma_api/controllers/pleroma_api_controller.ex
test/web/mastodon_api/controllers/timeline_controller_test.exs

index a16a3ebf042bd138825d4b46718847d769d8a6b0..8471b0f099262534c72a90c8f806180b8042fbe7 100644 (file)
@@ -6,7 +6,9 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
   use Pleroma.Web, :view
 
   alias Pleroma.User
+  alias Pleroma.Web.AdminAPI
   alias Pleroma.Web.AdminAPI.AccountView
+  alias Pleroma.Web.MastodonAPI
   alias Pleroma.Web.MediaProxy
 
   def render("index.json", %{users: users, count: count, page_size: page_size}) do
@@ -119,6 +121,13 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
     }
   end
 
+  def merge_account_views(%User{} = user) do
+    MastodonAPI.AccountView.render("show.json", %{user: user, skip_relationships: true})
+    |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user}))
+  end
+
+  def merge_account_views(_), do: %{}
+
   defp parse_error([]), do: ""
 
   defp parse_error(errors) do
index 215e311008fc8c081e461cd8737066341cee8b1c..f432b8c2c9e20da80512dd5e823ebf6e190232a2 100644 (file)
@@ -10,9 +10,10 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
   alias Pleroma.Web.AdminAPI
   alias Pleroma.Web.AdminAPI.Report
   alias Pleroma.Web.CommonAPI.Utils
-  alias Pleroma.Web.MastodonAPI
   alias Pleroma.Web.MastodonAPI.StatusView
 
+  defdelegate merge_account_views(user), to: AdminAPI.AccountView
+
   def render("index.json", %{reports: reports}) do
     %{
       reports:
@@ -71,11 +72,4 @@ defmodule Pleroma.Web.AdminAPI.ReportView do
       created_at: Utils.to_masto_date(inserted_at)
     }
   end
-
-  defp merge_account_views(%User{} = user) do
-    MastodonAPI.AccountView.render("show.json", %{user: user, skip_relationships: true})
-    |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user}))
-  end
-
-  defp merge_account_views(_), do: %{}
 end
index a76fad990ad96032ae4a590327c64a8898ea0924..500800be2b33306fa7ba255f1398bb10b26402d9 100644 (file)
@@ -7,26 +7,19 @@ defmodule Pleroma.Web.AdminAPI.StatusView do
 
   require Pleroma.Constants
 
-  alias Pleroma.User
   alias Pleroma.Web.AdminAPI
   alias Pleroma.Web.MastodonAPI
-  alias Pleroma.Web.MastodonAPI.StatusView
+
+  defdelegate merge_account_views(user), to: AdminAPI.AccountView
 
   def render("index.json", opts) do
     safe_render_many(opts.activities, __MODULE__, "show.json", opts)
   end
 
   def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
-    user = StatusView.get_user(activity.data["actor"])
+    user = MastodonAPI.StatusView.get_user(activity.data["actor"])
 
-    StatusView.render("show.json", opts)
+    MastodonAPI.StatusView.render("show.json", opts)
     |> Map.merge(%{account: merge_account_views(user)})
   end
-
-  defp merge_account_views(%User{} = user) do
-    MastodonAPI.AccountView.render("show.json", %{user: user, skip_relationships: true})
-    |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user}))
-  end
-
-  defp merge_account_views(_), do: %{}
 end
index f0b4c087a1905e50e4b91d5baec26cf95342b49e..61fdec0304aa989738576b8d083d2860ab92aa40 100644 (file)
@@ -103,9 +103,4 @@ defmodule Pleroma.Web.ControllerHelper do
   def put_if_exist(map, _key, nil), do: map
 
   def put_if_exist(map, key, value), do: Map.put(map, key, value)
-
-  @doc "Whether to skip `account.pleroma.relationship` rendering for statuses/notifications"
-  def skip_relationships?(params) do
-    not truthy_param?(params["with_relationships"])
-  end
 end
index b9ed2d7b27e3ef34160c26503277b46f898e2d66..489441da50da2cf8545172e63c8dbd228ca53d2a 100644 (file)
@@ -10,8 +10,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       add_link_headers: 2,
       truthy_param?: 1,
       assign_account_by_id: 2,
-      json_response: 3,
-      skip_relationships?: 1
+      json_response: 3
     ]
 
   alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
@@ -247,8 +246,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountController do
       |> render("index.json",
         activities: activities,
         for: reading_user,
-        as: :activity,
-        skip_relationships: skip_relationships?(params)
+        as: :activity
       )
     else
       _e -> render_error(conn, :not_found, "Can't find user")
index 596b85617a061d3a56ee56d08e01256ab58ca9e5..bcd12c73f74678e36897152c6d982691520a30af 100644 (file)
@@ -5,7 +5,7 @@
 defmodule Pleroma.Web.MastodonAPI.NotificationController do
   use Pleroma.Web, :controller
 
-  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2, skip_relationships?: 1]
+  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
 
   alias Pleroma.Notification
   alias Pleroma.Plugs.OAuthScopesPlug
@@ -50,8 +50,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationController do
     |> add_link_headers(notifications)
     |> render("index.json",
       notifications: notifications,
-      for: user,
-      skip_relationships: skip_relationships?(params)
+      for: user
     )
   end
 
index 6663c870708408d9cf68e6f603b066260abe5c64..5d3318ce06ff657a7406ef306059fe0794bd62a1 100644 (file)
@@ -5,8 +5,6 @@
 defmodule Pleroma.Web.MastodonAPI.SearchController do
   use Pleroma.Web, :controller
 
-  import Pleroma.Web.ControllerHelper, only: [skip_relationships?: 1]
-
   alias Pleroma.Activity
   alias Pleroma.Plugs.OAuthScopesPlug
   alias Pleroma.Plugs.RateLimiter
@@ -71,7 +69,6 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
 
   defp search_options(params, user) do
     [
-      skip_relationships: skip_relationships?(params),
       resolve: params[:resolve],
       following: params[:following],
       limit: params[:limit],
@@ -100,8 +97,7 @@ defmodule Pleroma.Web.MastodonAPI.SearchController do
     StatusView.render("index.json",
       activities: statuses,
       for: options[:for_user],
-      as: :activity,
-      skip_relationships: options[:skip_relationships]
+      as: :activity
     )
   end
 
index 12e3ba15e22a1755a7a4428e41d66f4cb05c22a0..2b2e4a89623f868ef7c399293ec6f02b06af7b22 100644 (file)
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
   use Pleroma.Web, :controller
 
   import Pleroma.Web.ControllerHelper,
-    only: [try_render: 3, add_link_headers: 2, skip_relationships?: 1]
+    only: [try_render: 3, add_link_headers: 2]
 
   require Ecto.Query
 
@@ -102,7 +102,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
 
   `ids` query param is required
   """
-  def index(%{assigns: %{user: user}} = conn, %{"ids" => ids} = params) do
+  def index(%{assigns: %{user: user}} = conn, %{"ids" => ids} = _params) do
     limit = 100
 
     activities =
@@ -114,8 +114,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
     render(conn, "index.json",
       activities: activities,
       for: user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 
@@ -370,8 +369,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
     |> render("index.json",
       activities: activities,
       for: user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 
@@ -393,8 +391,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusController do
     |> render("index.json",
       activities: activities,
       for: user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 end
index 2d67e19da616f143e88beaa7da5590d558f2a90f..61cc6ab49e6fa2f092754d93fb6d2818d67620f2 100644 (file)
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
   use Pleroma.Web, :controller
 
   import Pleroma.Web.ControllerHelper,
-    only: [add_link_headers: 2, add_link_headers: 3, truthy_param?: 1, skip_relationships?: 1]
+    only: [add_link_headers: 2, add_link_headers: 3, truthy_param?: 1]
 
   alias Pleroma.Pagination
   alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
@@ -59,8 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
     |> render("index.json",
       activities: activities,
       for: user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 
@@ -83,8 +82,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
     |> render("index.json",
       activities: activities,
       for: user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 
@@ -118,8 +116,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
       |> render("index.json",
         activities: activities,
         for: user,
-        as: :activity,
-        skip_relationships: skip_relationships?(params)
+        as: :activity
       )
     end
   end
@@ -166,8 +163,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
     |> render("index.json",
       activities: activities,
       for: user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 
@@ -195,8 +191,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineController do
       render(conn, "index.json",
         activities: activities,
         for: user,
-        as: :activity,
-        skip_relationships: skip_relationships?(params)
+        as: :activity
       )
     else
       _e -> render_error(conn, :forbidden, "Error.")
index e518bdedb09f6f2f26dfdd4557356e83a79eb456..0349bcc839cc88ced670baac868124c21e321c0e 100644 (file)
@@ -15,8 +15,6 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
   alias Pleroma.Web.MastodonAPI.StatusView
 
   def render("index.json", %{notifications: notifications, for: reading_user} = opts) do
-    opts = Map.merge(%{skip_relationships: true}, opts)
-
     activities = Enum.map(notifications, & &1.activity)
 
     parent_activities =
@@ -53,9 +51,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
             |> Enum.filter(& &1)
             |> Kernel.++(move_activities_targets)
 
-          UserRelationship.view_relationships_option(reading_user, actors,
-            source_mutes_only: opts[:skip_relationships]
-          )
+          UserRelationship.view_relationships_option(reading_user, actors, source_mutes_only: true)
       end
 
     opts =
@@ -73,8 +69,6 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
           for: reading_user
         } = opts
       ) do
-    opts = Map.merge(%{skip_relationships: true}, opts)
-
     actor = User.get_cached_by_ap_id(activity.data["actor"])
 
     parent_activity_fn = fn ->
@@ -87,15 +81,15 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
 
     mastodon_type = Activity.mastodon_notification_type(activity)
 
-    render_opts = %{
-      relationships: opts[:relationships],
-      skip_relationships: opts[:skip_relationships]
-    }
+    # Note: :relationships contain user mutes (needed for :muted flag in :status)
+    status_render_opts = %{relationships: opts[:relationships]}
+
+    account_render_opts = %{skip_relationships: true}
 
     with %{id: _} = account <-
            AccountView.render(
              "show.json",
-             Map.merge(render_opts, %{user: actor, for: reading_user})
+             Map.merge(account_render_opts, %{user: actor, for: reading_user})
            ) do
       response = %{
         id: to_string(notification.id),
@@ -109,21 +103,20 @@ defmodule Pleroma.Web.MastodonAPI.NotificationView do
 
       case mastodon_type do
         "mention" ->
-          put_status(response, activity, reading_user, render_opts)
+          put_status(response, activity, reading_user, status_render_opts)
 
         "favourite" ->
-          put_status(response, parent_activity_fn.(), reading_user, render_opts)
+          put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
 
         "reblog" ->
-          put_status(response, parent_activity_fn.(), reading_user, render_opts)
+          put_status(response, parent_activity_fn.(), reading_user, status_render_opts)
 
         "move" ->
-          # Note: :skip_relationships option being applied to _account_ rendering (here)
-          put_target(response, activity, reading_user, render_opts)
+          put_target(response, activity, reading_user, account_render_opts)
 
         "pleroma:emoji_reaction" ->
           response
-          |> put_status(parent_activity_fn.(), reading_user, render_opts)
+          |> put_status(parent_activity_fn.(), reading_user, status_render_opts)
           |> put_emoji(activity)
 
         type when type in ["follow", "follow_request"] ->
index 0bcc84d4444e3f055a171946985a3e68bdf480df..8762f23fd6ecc40c0cce9165c7ba29c7c25294cd 100644 (file)
@@ -76,8 +76,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
   end
 
   def render("index.json", opts) do
-    opts = Map.merge(%{skip_relationships: true}, opts)
-
     reading_user = opts[:for]
 
     # To do: check AdminAPIControllerTest on the reasons behind nil activities in the list
@@ -109,9 +107,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
             |> Enum.map(&get_user(&1.data["actor"], false))
             |> Enum.filter(& &1)
 
-          UserRelationship.view_relationships_option(reading_user, actors,
-            source_mutes_only: opts[:skip_relationships]
-          )
+          UserRelationship.view_relationships_option(reading_user, actors, source_mutes_only: true)
       end
 
     opts =
@@ -127,8 +123,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         "show.json",
         %{activity: %{data: %{"type" => "Announce", "object" => _object}} = activity} = opts
       ) do
-    opts = Map.merge(%{skip_relationships: true}, opts)
-
     user = get_user(activity.data["actor"])
     created_at = Utils.to_masto_date(activity.data["published"])
     activity_object = Object.normalize(activity)
@@ -167,8 +161,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         AccountView.render("show.json", %{
           user: user,
           for: opts[:for],
-          relationships: opts[:relationships],
-          skip_relationships: opts[:skip_relationships]
+          skip_relationships: true
         }),
       in_reply_to_id: nil,
       in_reply_to_account_id: nil,
@@ -202,8 +195,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
   end
 
   def render("show.json", %{activity: %{data: %{"object" => _object}} = activity} = opts) do
-    opts = Map.merge(%{skip_relationships: true}, opts)
-
     object = Object.normalize(activity)
 
     user = get_user(activity.data["actor"])
@@ -337,8 +328,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusView do
         AccountView.render("show.json", %{
           user: user,
           for: opts[:for],
-          relationships: opts[:relationships],
-          skip_relationships: opts[:skip_relationships]
+          skip_relationships: true
         }),
       in_reply_to_id: reply_to && to_string(reply_to.id),
       in_reply_to_account_id: reply_to_user && to_string(reply_to_user.id),
index be7477867b3592766fa10170331922c90c50c6a9..3c6a951b9866f7b63bd57c0b8f28ae0d1ea77e45 100644 (file)
@@ -6,7 +6,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
   use Pleroma.Web, :controller
 
   import Pleroma.Web.ControllerHelper,
-    only: [json_response: 3, add_link_headers: 2, assign_account_by_id: 2, skip_relationships?: 1]
+    only: [json_response: 3, add_link_headers: 2, assign_account_by_id: 2]
 
   alias Ecto.Changeset
   alias Pleroma.Plugs.EnsurePublicOrAuthenticatedPlug
@@ -139,8 +139,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountController do
     |> render("index.json",
       activities: activities,
       for: for_user,
-      as: :activity,
-      skip_relationships: skip_relationships?(params)
+      as: :activity
     )
   end
 
index 80ecdf67e43755252fb590301a2ce3f067134711..b61a6791b2868a90fc99a53d3b3fbdb92ebee43a 100644 (file)
@@ -5,7 +5,7 @@
 defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
   use Pleroma.Web, :controller
 
-  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2, skip_relationships?: 1]
+  import Pleroma.Web.ControllerHelper, only: [add_link_headers: 2]
 
   alias Pleroma.Activity
   alias Pleroma.Conversation.Participation
@@ -151,8 +151,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
       |> render("index.json",
         activities: activities,
         for: user,
-        as: :activity,
-        skip_relationships: skip_relationships?(params)
+        as: :activity
       )
     else
       _error ->
@@ -207,7 +206,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
     end
   end
 
-  def mark_notifications_as_read(%{assigns: %{user: user}} = conn, %{"max_id" => max_id} = params) do
+  def mark_notifications_as_read(%{assigns: %{user: user}} = conn, %{"max_id" => max_id}) do
     with notifications <- Notification.set_read_up_to(user, max_id) do
       notifications = Enum.take(notifications, 80)
 
@@ -215,8 +214,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIController do
       |> put_view(NotificationView)
       |> render("index.json",
         notifications: notifications,
-        for: user,
-        skip_relationships: skip_relationships?(params)
+        for: user
       )
     end
   end
index b8bb83af7fb3e19c1cee5c01b30b10bf6ce239e8..47541979dea727737e0baa748f79fbf1707a7cce 100644 (file)
@@ -20,7 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
   describe "home" do
     setup do: oauth_access(["read:statuses"])
 
-    test "does NOT render account/pleroma/relationship by default", %{
+    test "does NOT embed account/pleroma/relationship in statuses", %{
       user: user,
       conn: conn
     } do
@@ -39,84 +39,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
              end)
     end
 
-    test "embeds account relationships with `with_relationships=true`", %{user: user, conn: conn} do
-      uri = "/api/v1/timelines/home?with_relationships=true"
-
-      following = insert(:user, nickname: "followed")
-      third_user = insert(:user, nickname: "repeated")
-
-      {:ok, _activity} = CommonAPI.post(following, %{"status" => "post"})
-      {:ok, activity} = CommonAPI.post(third_user, %{"status" => "repeated post"})
-      {:ok, _, _} = CommonAPI.repeat(activity.id, following)
-
-      ret_conn = get(conn, uri)
-
-      assert Enum.empty?(json_response(ret_conn, :ok))
-
-      {:ok, _user} = User.follow(user, following)
-
-      ret_conn = get(conn, uri)
-
-      assert [
-               %{
-                 "reblog" => %{
-                   "content" => "repeated post",
-                   "account" => %{
-                     "pleroma" => %{
-                       "relationship" => %{"following" => false, "followed_by" => false}
-                     }
-                   }
-                 },
-                 "account" => %{
-                   "pleroma" => %{
-                     "relationship" => %{"following" => true}
-                   }
-                 }
-               },
-               %{
-                 "content" => "post",
-                 "account" => %{
-                   "acct" => "followed",
-                   "pleroma" => %{
-                     "relationship" => %{"following" => true}
-                   }
-                 }
-               }
-             ] = json_response(ret_conn, :ok)
-
-      {:ok, _user} = User.follow(third_user, user)
-
-      ret_conn = get(conn, uri)
-
-      assert [
-               %{
-                 "reblog" => %{
-                   "content" => "repeated post",
-                   "account" => %{
-                     "acct" => "repeated",
-                     "pleroma" => %{
-                       "relationship" => %{"following" => false, "followed_by" => true}
-                     }
-                   }
-                 },
-                 "account" => %{
-                   "pleroma" => %{
-                     "relationship" => %{"following" => true}
-                   }
-                 }
-               },
-               %{
-                 "content" => "post",
-                 "account" => %{
-                   "acct" => "followed",
-                   "pleroma" => %{
-                     "relationship" => %{"following" => true}
-                   }
-                 }
-               }
-             ] = json_response(ret_conn, :ok)
-    end
-
     test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
       {:ok, public_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "public"})
       {:ok, direct_activity} = CommonAPI.post(user, %{"status" => ".", "visibility" => "direct"})