Merge branch 'backport/undo-fixes' into 'maint/1.1'

backport: undo fixes

See merge request pleroma/pleroma!1789
This commit is contained in:
kaniini 2019-10-04 21:29:01 +00:00
commit 923dff21b3
4 changed files with 16 additions and 8 deletions

View file

@ -7,6 +7,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
### Fixed ### Fixed
- Mastodon API: Inability to get some local users by nickname in `/api/v1/accounts/:id_or_nickname` - Mastodon API: Inability to get some local users by nickname in `/api/v1/accounts/:id_or_nickname`
- Mastodon API: Blocks are now treated consistently between the Streaming API and the Timeline APIs - Mastodon API: Blocks are now treated consistently between the Streaming API and the Timeline APIs
- ActivityPub: Correct addressing of Undo.
## [1.0.90] - 2019-09-30 ## [1.0.90] - 2019-09-30
### Security ### Security

View file

@ -472,14 +472,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
""" """
def make_unannounce_data( def make_unannounce_data(
%User{ap_id: ap_id} = user, %User{ap_id: ap_id} = user,
%Activity{data: %{"context" => context}} = activity, %Activity{data: %{"context" => context, "object" => object}} = activity,
activity_id activity_id
) do ) do
object = Object.normalize(object)
%{ %{
"type" => "Undo", "type" => "Undo",
"actor" => ap_id, "actor" => ap_id,
"object" => activity.data, "object" => activity.data,
"to" => [user.follower_address, activity.data["actor"]], "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()], "cc" => [Pleroma.Constants.as_public()],
"context" => context "context" => context
} }
@ -488,14 +490,16 @@ defmodule Pleroma.Web.ActivityPub.Utils do
def make_unlike_data( def make_unlike_data(
%User{ap_id: ap_id} = user, %User{ap_id: ap_id} = user,
%Activity{data: %{"context" => context}} = activity, %Activity{data: %{"context" => context, "object" => object}} = activity,
activity_id activity_id
) do ) do
object = Object.normalize(object)
%{ %{
"type" => "Undo", "type" => "Undo",
"actor" => ap_id, "actor" => ap_id,
"object" => activity.data, "object" => activity.data,
"to" => [user.follower_address, activity.data["actor"]], "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()], "cc" => [Pleroma.Constants.as_public()],
"context" => context "context" => context
} }

View file

@ -760,10 +760,11 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
{:ok, like_activity, object} = ActivityPub.like(user, object) {:ok, like_activity, object} = ActivityPub.like(user, object)
assert object.data["like_count"] == 1 assert object.data["like_count"] == 1
{:ok, _, _, object} = ActivityPub.unlike(user, object) {:ok, unlike_activity, _, object} = ActivityPub.unlike(user, object)
assert object.data["like_count"] == 0 assert object.data["like_count"] == 0
assert Activity.get_by_id(like_activity.id) == nil assert Activity.get_by_id(like_activity.id) == nil
assert note_activity.actor in unlike_activity.recipients
end end
end end
@ -806,7 +807,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
assert unannounce_activity.data["to"] == [ assert unannounce_activity.data["to"] == [
User.ap_followers(user), User.ap_followers(user),
announce_activity.data["actor"] object.data["actor"]
] ]
assert unannounce_activity.data["type"] == "Undo" assert unannounce_activity.data["type"] == "Undo"

View file

@ -94,11 +94,13 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
user = insert(:user) user = insert(:user)
like_activity = insert(:like_activity, data_attrs: %{"context" => "test context"}) like_activity = insert(:like_activity, data_attrs: %{"context" => "test context"})
object = Object.normalize(like_activity.data["object"])
assert Utils.make_unlike_data(user, like_activity, nil) == %{ assert Utils.make_unlike_data(user, like_activity, nil) == %{
"type" => "Undo", "type" => "Undo",
"actor" => user.ap_id, "actor" => user.ap_id,
"object" => like_activity.data, "object" => like_activity.data,
"to" => [user.follower_address, like_activity.data["actor"]], "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()], "cc" => [Pleroma.Constants.as_public()],
"context" => like_activity.data["context"] "context" => like_activity.data["context"]
} }
@ -107,7 +109,7 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do
"type" => "Undo", "type" => "Undo",
"actor" => user.ap_id, "actor" => user.ap_id,
"object" => like_activity.data, "object" => like_activity.data,
"to" => [user.follower_address, like_activity.data["actor"]], "to" => [user.follower_address, object.data["actor"]],
"cc" => [Pleroma.Constants.as_public()], "cc" => [Pleroma.Constants.as_public()],
"context" => like_activity.data["context"], "context" => like_activity.data["context"],
"id" => "9mJEZK0tky1w2xD2vY" "id" => "9mJEZK0tky1w2xD2vY"