[#2791] AccountView: renamed `:force` option to `:skip_visibility_check`.
authorIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 23 Jul 2020 12:08:30 +0000 (15:08 +0300)
committerIvan Tashkinov <ivantashkinov@gmail.com>
Thu, 23 Jul 2020 12:08:30 +0000 (15:08 +0300)
12 files changed:
lib/pleroma/web/activity_pub/utils.ex
lib/pleroma/web/admin_api/views/account_view.ex
lib/pleroma/web/chat_channel.ex
lib/pleroma/web/mastodon_api/views/account_view.ex
lib/pleroma/web/pleroma_api/views/chat_view.ex
test/web/activity_pub/activity_pub_test.exs
test/web/activity_pub/transmogrifier_test.exs
test/web/activity_pub/utils_test.exs
test/web/admin_api/views/report_view_test.exs
test/web/mastodon_api/views/account_view_test.exs
test/web/mastodon_api/views/status_view_test.exs
test/web/pleroma_api/views/chat_view_test.exs

index 11c64cffd820a6091ee7a74b450ba188ffc6aee7..713b0ca1f3ea1a3bcf14accd02dcf928f7373fa9 100644 (file)
@@ -729,7 +729,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
           "actor" =>
             AccountView.render(
               "show.json",
-              %{user: activity_actor, force: true}
+              %{user: activity_actor, skip_visibility_check: true}
             )
         }
 
index 4ae030b84f5aa1b553bc468fe22a04d0212ed87e..88fbb53159a24abafc911fdd17665f97f808bd17 100644 (file)
@@ -105,7 +105,7 @@ defmodule Pleroma.Web.AdminAPI.AccountView do
   end
 
   def merge_account_views(%User{} = user) do
-    MastodonAPI.AccountView.render("show.json", %{user: user, force: true})
+    MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true})
     |> Map.merge(AdminAPI.AccountView.render("show.json", %{user: user}))
   end
 
index 08d0e80f9d1d39a17fc5944fcebc4fffb141c03a..3b1469c19a042d31b030d37d6761ed312f7b3558 100644 (file)
@@ -24,7 +24,7 @@ defmodule Pleroma.Web.ChatChannel do
 
     if String.length(text) in 1..Pleroma.Config.get([:instance, :chat_limit]) do
       author = User.get_cached_by_nickname(user_name)
-      author_json = AccountView.render("show.json", user: author, force: true)
+      author_json = AccountView.render("show.json", user: author, skip_visibility_check: true)
 
       message = ChatChannelState.add_message(%{text: text, author: author_json})
 
index b929d5a036af2dbbd59d588f84ce33f27b8dce43..864c0417f14a2694ac9cb0583d118ceb4d4806c4 100644 (file)
@@ -39,11 +39,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
 
   @doc """
   Renders specified user account.
-    :force option skips visibility check and renders any user (local or remote)
+    :skip_visibility_check option skips visibility check and renders any user (local or remote)
       regardless of [:pleroma, :restrict_unauthenticated] setting.
     :for option specifies the requester and can be a User record or nil.
+      Only use `user: user, for: user` when `user` is the actual requester of own profile.
   """
-  def render("show.json", %{user: _user, force: true} = opts) do
+  def render("show.json", %{user: _user, skip_visibility_check: true} = opts) do
     do_render("show.json", opts)
   end
 
@@ -56,7 +57,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountView do
   end
 
   def render("show.json", _) do
-    raise "In order to prevent account accessibility issues, :force or :for option is required."
+    raise "In order to prevent account accessibility issues, " <>
+            ":skip_visibility_check or :for option is required."
   end
 
   def render("mention.json", %{user: user}) do
index 2ae7c8122afc7fd1bc706b8b3d5d9e2411953955..04dc20d511b918fae999fb57aa2f6e953976204d 100644 (file)
@@ -38,7 +38,7 @@ defmodule Pleroma.Web.PleromaAPI.ChatView do
     if Map.has_key?(account_view_opts, :for) do
       account_view_opts
     else
-      Map.put(account_view_opts, :force, true)
+      Map.put(account_view_opts, :skip_visibility_check, true)
     end
   end
 end
index 34905a928a8c619bb4003fa01158137cadb1413b..d6eab7337c7022f1fb7056d596a8fc9e45ad9ced 100644 (file)
@@ -1179,7 +1179,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
         "id" => activity_ap_id,
         "content" => content,
         "published" => activity_with_object.object.data["published"],
-        "actor" => AccountView.render("show.json", %{user: target_account, force: true})
+        "actor" =>
+          AccountView.render("show.json", %{user: target_account, skip_visibility_check: true})
       }
 
       assert %Activity{
index 01e18eace001a33c6e69610fc7b1fb287410bc43..2d089b19bacc4538f6848441c23eea55602ef057 100644 (file)
@@ -710,7 +710,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
         "id" => activity.data["id"],
         "content" => "test post",
         "published" => object.data["published"],
-        "actor" => AccountView.render("show.json", %{user: user, force: true})
+        "actor" => AccountView.render("show.json", %{user: user, skip_visibility_check: true})
       }
 
       message = %{
index ab984d486fb6d4cadd2e258520a19033817e288f..d5021354595756eeb7d4f20b546db953d622857a 100644 (file)
@@ -482,7 +482,8 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
         "id" => activity_ap_id,
         "content" => content,
         "published" => activity.object.data["published"],
-        "actor" => AccountView.render("show.json", %{user: target_account, force: true})
+        "actor" =>
+          AccountView.render("show.json", %{user: target_account, skip_visibility_check: true})
       }
 
       assert %{
index e171509e59ec20b5a5fe0a3c85fedfbb59b6aeef..5a02292be77a1d66ee621c77d27db13187fa3a7f 100644 (file)
@@ -24,12 +24,15 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
       content: nil,
       actor:
         Map.merge(
-          MastodonAPI.AccountView.render("show.json", %{user: user, force: true}),
+          MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
           AdminAPI.AccountView.render("show.json", %{user: user})
         ),
       account:
         Map.merge(
-          MastodonAPI.AccountView.render("show.json", %{user: other_user, force: true}),
+          MastodonAPI.AccountView.render("show.json", %{
+            user: other_user,
+            skip_visibility_check: true
+          }),
           AdminAPI.AccountView.render("show.json", %{user: other_user})
         ),
       statuses: [],
@@ -59,12 +62,15 @@ defmodule Pleroma.Web.AdminAPI.ReportViewTest do
       content: nil,
       actor:
         Map.merge(
-          MastodonAPI.AccountView.render("show.json", %{user: user, force: true}),
+          MastodonAPI.AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
           AdminAPI.AccountView.render("show.json", %{user: user})
         ),
       account:
         Map.merge(
-          MastodonAPI.AccountView.render("show.json", %{user: other_user, force: true}),
+          MastodonAPI.AccountView.render("show.json", %{
+            user: other_user,
+            skip_visibility_check: true
+          }),
           AdminAPI.AccountView.render("show.json", %{user: other_user})
         ),
       statuses: [StatusView.render("show.json", %{activity: activity})],
index 2b18c2e432f667f299f79cc4a0cb8912ce3a8dd6..8f37efa3c3e2b8df5fa13bfa7955ac5f898fbb3c 100644 (file)
@@ -95,7 +95,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       }
     }
 
-    assert expected == AccountView.render("show.json", %{user: user, force: true})
+    assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
   end
 
   test "Favicon is nil when :instances_favicons is disabled" do
@@ -108,12 +108,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
                favicon:
                  "https://shitposter.club/plugins/Qvitter/img/gnusocial-favicons/favicon-16x16.png"
              }
-           } = AccountView.render("show.json", %{user: user, force: true})
+           } = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
 
     Config.put([:instances_favicons, :enabled], false)
 
     assert %{pleroma: %{favicon: nil}} =
-             AccountView.render("show.json", %{user: user, force: true})
+             AccountView.render("show.json", %{user: user, skip_visibility_check: true})
   end
 
   test "Represent the user account for the account owner" do
@@ -190,7 +190,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
       }
     }
 
-    assert expected == AccountView.render("show.json", %{user: user, force: true})
+    assert expected == AccountView.render("show.json", %{user: user, skip_visibility_check: true})
   end
 
   test "Represent a Funkwhale channel" do
@@ -199,7 +199,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         "https://channels.tests.funkwhale.audio/federation/actors/compositions"
       )
 
-    assert represented = AccountView.render("show.json", %{user: user, force: true})
+    assert represented =
+             AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+
     assert represented.acct == "compositions@channels.tests.funkwhale.audio"
     assert represented.url == "https://channels.tests.funkwhale.audio/channels/compositions"
   end
@@ -224,7 +226,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
     assert expected == AccountView.render("mention.json", %{user: user})
   end
 
-  test "demands :for or :force option for account rendering" do
+  test "demands :for or :skip_visibility_check option for account rendering" do
     clear_config([:restrict_unauthenticated, :profiles, :local], false)
 
     user = insert(:user)
@@ -232,9 +234,11 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
     assert %{id: ^user_id} = AccountView.render("show.json", %{user: user, for: nil})
     assert %{id: ^user_id} = AccountView.render("show.json", %{user: user, for: user})
-    assert %{id: ^user_id} = AccountView.render("show.json", %{user: user, force: true})
 
-    assert_raise RuntimeError, ~r/:force or :for option is required/, fn ->
+    assert %{id: ^user_id} =
+             AccountView.render("show.json", %{user: user, skip_visibility_check: true})
+
+    assert_raise RuntimeError, ~r/:skip_visibility_check or :for option is required/, fn ->
       AccountView.render("show.json", %{user: user})
     end
   end
@@ -361,13 +365,13 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
 
   test "doesn't sanitize display names" do
     user = insert(:user, name: "<marquee> username </marquee>")
-    result = AccountView.render("show.json", %{user: user, force: true})
+    result = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
     assert result.display_name == "<marquee> username </marquee>"
   end
 
   test "never display nil user follow counts" do
     user = insert(:user, following_count: 0, follower_count: 0)
-    result = AccountView.render("show.json", %{user: user, force: true})
+    result = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
 
     assert result.following_count == 0
     assert result.followers_count == 0
@@ -391,7 +395,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
                followers_count: 0,
                following_count: 0,
                pleroma: %{hide_follows_count: true, hide_followers_count: true}
-             } = AccountView.render("show.json", %{user: user, force: true})
+             } = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
     end
 
     test "shows when follows/followers are hidden" do
@@ -404,7 +408,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
                followers_count: 1,
                following_count: 1,
                pleroma: %{hide_follows: true, hide_followers: true}
-             } = AccountView.render("show.json", %{user: user, force: true})
+             } = AccountView.render("show.json", %{user: user, skip_visibility_check: true})
     end
 
     test "shows actual follower/following count to the account owner" do
@@ -547,7 +551,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
         emoji: %{"joker_smile" => "https://evil.website/society.png"}
       )
 
-    AccountView.render("show.json", %{user: user, force: true})
+    AccountView.render("show.json", %{user: user, skip_visibility_check: true})
     |> Enum.all?(fn
       {key, url} when key in [:avatar, :avatar_static, :header, :header_static] ->
         String.starts_with?(url, Pleroma.Web.base_url())
index d44e3f6e6c2fb7aa8a74b2848b057622b190924d..d97d818bb050d37ec6ae97b7e6add1db78d07b8d 100644 (file)
@@ -177,7 +177,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
       id: to_string(note.id),
       uri: object_data["id"],
       url: Pleroma.Web.Router.Helpers.o_status_url(Pleroma.Web.Endpoint, :notice, note),
-      account: AccountView.render("show.json", %{user: user, force: true}),
+      account: AccountView.render("show.json", %{user: user, skip_visibility_check: true}),
       in_reply_to_id: nil,
       in_reply_to_account_id: nil,
       card: nil,
index 46d47cd4f81d519e788c606ff170004773dcbf2a..02484b705b7ccd380fd60d41d1eb5b5ea2602ba1 100644 (file)
@@ -26,7 +26,8 @@ defmodule Pleroma.Web.PleromaAPI.ChatViewTest do
 
     assert represented_chat == %{
              id: "#{chat.id}",
-             account: AccountView.render("show.json", user: recipient, force: true),
+             account:
+               AccountView.render("show.json", user: recipient, skip_visibility_check: true),
              unread: 0,
              last_message: nil,
              updated_at: Utils.to_masto_date(chat.updated_at)