Fix not being able to pin unlisted posts
authorrinpatch <rinpatch@sdf.org>
Sat, 29 Jun 2019 19:24:03 +0000 (22:24 +0300)
committerrinpatch <rinpatch@sdf.org>
Sat, 29 Jun 2019 19:27:42 +0000 (22:27 +0300)
Closes #1038

CHANGELOG.md
lib/pleroma/web/common_api/common_api.ex
test/web/common_api/common_api_test.exs

index a6ec8674d669e9fd31da9a2508980fb562910db0..e30ab803cd5912b9a8f1d1e2dd5d0f3ff4057ffc 100644 (file)
@@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
 ## [Unreleased]
 ### Added
 - MRF: Support for priming the mediaproxy cache (`Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy`)
+### Fixed
+- Not being able to pin unlisted posts
 
 ## [1.0.0] - 2019-06-29
 ### Security
index f8df1e2eafd64f782e01d905f22bdc09ef27956b..f71c67a3d8383ac75bfb2cf3bce7c26e45501b85 100644 (file)
@@ -11,6 +11,7 @@ defmodule Pleroma.Web.CommonAPI do
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.ActivityPub.Utils
+  alias Pleroma.Web.ActivityPub.Visibility
 
   import Pleroma.Web.CommonAPI.Utils
 
@@ -284,12 +285,11 @@ defmodule Pleroma.Web.CommonAPI do
            },
            object: %Object{
              data: %{
-               "to" => object_to,
                "type" => "Note"
              }
            }
          } = activity <- get_by_id_or_ap_id(id_or_ap_id),
-         true <- Enum.member?(object_to, "https://www.w3.org/ns/activitystreams#Public"),
+         true <- Visibility.is_public?(activity),
          %{valid?: true} = info_changeset <-
            User.Info.add_pinnned_activity(user.info, activity),
          changeset <-
index e96106f1114777ca284f80921e9319b22d92a319..6f57bbe1f7b0d568e0852007de286dacad50391b 100644 (file)
@@ -188,6 +188,11 @@ defmodule Pleroma.Web.CommonAPITest do
       assert %User{info: %{pinned_activities: [^id]}} = user
     end
 
+    test "unlisted statuses can be pinned", %{user: user} do
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})
+      assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+    end
+
     test "only self-authored can be pinned", %{activity: activity} do
       user = insert(:user)