Merge branch 'incoming-id-fixes' into 'develop'
Assorted transmogrifier fixes See merge request pleroma/pleroma!1831
This commit is contained in:
commit
e3b4a3e96b
|
@ -269,22 +269,21 @@ def listen(%{to: to, actor: actor, context: context, object: object} = params) d
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def accept(%{to: to, actor: actor, object: object} = params) do
|
def accept(params) do
|
||||||
# only accept false as false value
|
accept_or_reject("Accept", params)
|
||||||
local = !(params[:local] == false)
|
|
||||||
|
|
||||||
with data <- %{"to" => to, "type" => "Accept", "actor" => actor.ap_id, "object" => object},
|
|
||||||
{:ok, activity} <- insert(data, local),
|
|
||||||
:ok <- maybe_federate(activity) do
|
|
||||||
{:ok, activity}
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject(%{to: to, actor: actor, object: object} = params) do
|
def reject(params) do
|
||||||
# only accept false as false value
|
accept_or_reject("Reject", params)
|
||||||
local = !(params[:local] == false)
|
end
|
||||||
|
|
||||||
with data <- %{"to" => to, "type" => "Reject", "actor" => actor.ap_id, "object" => object},
|
def accept_or_reject(type, %{to: to, actor: actor, object: object} = params) do
|
||||||
|
local = Map.get(params, :local, true)
|
||||||
|
activity_id = Map.get(params, :activity_id, nil)
|
||||||
|
|
||||||
|
with data <-
|
||||||
|
%{"to" => to, "type" => type, "actor" => actor.ap_id, "object" => object}
|
||||||
|
|> Utils.maybe_put("id", activity_id),
|
||||||
{:ok, activity} <- insert(data, local),
|
{:ok, activity} <- insert(data, local),
|
||||||
:ok <- maybe_federate(activity) do
|
:ok <- maybe_federate(activity) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
|
@ -409,18 +408,24 @@ def delete(%User{ap_id: ap_id, follower_address: follower_address} = user) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, local \\ true) do
|
def delete(%Object{data: %{"id" => id, "actor" => actor}} = object, options \\ []) do
|
||||||
|
local = Keyword.get(options, :local, true)
|
||||||
|
activity_id = Keyword.get(options, :activity_id, nil)
|
||||||
|
actor = Keyword.get(options, :actor, actor)
|
||||||
|
|
||||||
user = User.get_cached_by_ap_id(actor)
|
user = User.get_cached_by_ap_id(actor)
|
||||||
to = (object.data["to"] || []) ++ (object.data["cc"] || [])
|
to = (object.data["to"] || []) ++ (object.data["cc"] || [])
|
||||||
|
|
||||||
with {:ok, object, activity} <- Object.delete(object),
|
with {:ok, object, activity} <- Object.delete(object),
|
||||||
data <- %{
|
data <-
|
||||||
"type" => "Delete",
|
%{
|
||||||
"actor" => actor,
|
"type" => "Delete",
|
||||||
"object" => id,
|
"actor" => actor,
|
||||||
"to" => to,
|
"object" => id,
|
||||||
"deleted_activity_id" => activity && activity.id
|
"to" => to,
|
||||||
},
|
"deleted_activity_id" => activity && activity.id
|
||||||
|
}
|
||||||
|
|> maybe_put("id", activity_id),
|
||||||
{:ok, activity} <- insert(data, local, false),
|
{:ok, activity} <- insert(data, local, false),
|
||||||
stream_out_participations(object, user),
|
stream_out_participations(object, user),
|
||||||
_ <- decrease_replies_count_if_reply(object),
|
_ <- decrease_replies_count_if_reply(object),
|
||||||
|
|
|
@ -514,7 +514,7 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => _id} = data,
|
%{"type" => "Accept", "object" => follow_object, "actor" => _actor, "id" => id} = data,
|
||||||
_options
|
_options
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
|
@ -528,7 +528,8 @@ def handle_incoming(
|
||||||
type: "Accept",
|
type: "Accept",
|
||||||
actor: followed,
|
actor: followed,
|
||||||
object: follow_activity.data["id"],
|
object: follow_activity.data["id"],
|
||||||
local: false
|
local: false,
|
||||||
|
activity_id: id
|
||||||
})
|
})
|
||||||
else
|
else
|
||||||
_e -> :error
|
_e -> :error
|
||||||
|
@ -536,7 +537,7 @@ def handle_incoming(
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => _id} = data,
|
%{"type" => "Reject", "object" => follow_object, "actor" => _actor, "id" => id} = data,
|
||||||
_options
|
_options
|
||||||
) do
|
) do
|
||||||
with actor <- Containment.get_actor(data),
|
with actor <- Containment.get_actor(data),
|
||||||
|
@ -550,7 +551,8 @@ def handle_incoming(
|
||||||
type: "Reject",
|
type: "Reject",
|
||||||
actor: followed,
|
actor: followed,
|
||||||
object: follow_activity.data["id"],
|
object: follow_activity.data["id"],
|
||||||
local: false
|
local: false,
|
||||||
|
activity_id: id
|
||||||
}) do
|
}) do
|
||||||
User.unfollow(follower, followed)
|
User.unfollow(follower, followed)
|
||||||
|
|
||||||
|
@ -637,7 +639,7 @@ def handle_incoming(
|
||||||
# an error or a tombstone. This would allow us to verify that a deletion actually took
|
# an error or a tombstone. This would allow us to verify that a deletion actually took
|
||||||
# place.
|
# place.
|
||||||
def handle_incoming(
|
def handle_incoming(
|
||||||
%{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => _id} = data,
|
%{"type" => "Delete", "object" => object_id, "actor" => actor, "id" => id} = data,
|
||||||
_options
|
_options
|
||||||
) do
|
) do
|
||||||
object_id = Utils.get_ap_id(object_id)
|
object_id = Utils.get_ap_id(object_id)
|
||||||
|
@ -646,7 +648,8 @@ def handle_incoming(
|
||||||
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
{:ok, %User{} = actor} <- User.get_or_fetch_by_ap_id(actor),
|
||||||
{:ok, object} <- get_obj_helper(object_id),
|
{:ok, object} <- get_obj_helper(object_id),
|
||||||
:ok <- Containment.contain_origin(actor.ap_id, object.data),
|
:ok <- Containment.contain_origin(actor.ap_id, object.data),
|
||||||
{:ok, activity} <- ActivityPub.delete(object, false) do
|
{:ok, activity} <-
|
||||||
|
ActivityPub.delete(object, local: false, activity_id: id, actor: actor.ap_id) do
|
||||||
{:ok, activity}
|
{:ok, activity}
|
||||||
else
|
else
|
||||||
nil ->
|
nil ->
|
||||||
|
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.OStatus.DeleteHandler do
|
||||||
def handle_delete(entry, _doc \\ nil) do
|
def handle_delete(entry, _doc \\ nil) do
|
||||||
with id <- XML.string_from_xpath("//id", entry),
|
with id <- XML.string_from_xpath("//id", entry),
|
||||||
%Object{} = object <- Object.normalize(id),
|
%Object{} = object <- Object.normalize(id),
|
||||||
{:ok, delete} <- ActivityPub.delete(object, false) do
|
{:ok, delete} <- ActivityPub.delete(object, local: false) do
|
||||||
delete
|
delete
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -682,6 +682,7 @@ test "it works for incoming update activities which lock the account" do
|
||||||
|
|
||||||
test "it works for incoming deletes" do
|
test "it works for incoming deletes" do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
|
deleting_user = insert(:user)
|
||||||
|
|
||||||
data =
|
data =
|
||||||
File.read!("test/fixtures/mastodon-delete.json")
|
File.read!("test/fixtures/mastodon-delete.json")
|
||||||
|
@ -694,11 +695,14 @@ test "it works for incoming deletes" do
|
||||||
data =
|
data =
|
||||||
data
|
data
|
||||||
|> Map.put("object", object)
|
|> Map.put("object", object)
|
||||||
|> Map.put("actor", activity.data["actor"])
|
|> Map.put("actor", deleting_user.ap_id)
|
||||||
|
|
||||||
{:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)
|
{:ok, %Activity{actor: actor, local: false, data: %{"id" => id}}} =
|
||||||
|
Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert id == data["id"]
|
||||||
refute Activity.get_by_id(activity.id)
|
refute Activity.get_by_id(activity.id)
|
||||||
|
assert actor == deleting_user.ap_id
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it fails for incoming deletes with spoofed origin" do
|
test "it fails for incoming deletes with spoofed origin" do
|
||||||
|
@ -905,6 +909,8 @@ test "it works for incoming accepts which were pre-accepted" do
|
||||||
|
|
||||||
assert activity.data["object"] == follow_activity.data["id"]
|
assert activity.data["object"] == follow_activity.data["id"]
|
||||||
|
|
||||||
|
assert activity.data["id"] == accept_data["id"]
|
||||||
|
|
||||||
follower = User.get_cached_by_id(follower.id)
|
follower = User.get_cached_by_id(follower.id)
|
||||||
|
|
||||||
assert User.following?(follower, followed) == true
|
assert User.following?(follower, followed) == true
|
||||||
|
@ -1009,6 +1015,7 @@ test "it works for incoming rejects which are orphaned" do
|
||||||
|
|
||||||
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
|
{:ok, activity} = Transmogrifier.handle_incoming(reject_data)
|
||||||
refute activity.local
|
refute activity.local
|
||||||
|
assert activity.data["id"] == reject_data["id"]
|
||||||
|
|
||||||
follower = User.get_cached_by_id(follower.id)
|
follower = User.get_cached_by_id(follower.id)
|
||||||
|
|
||||||
|
|
|
@ -40,9 +40,9 @@ test "it returns empty result if user or status search return undefined error",
|
||||||
test "search", %{conn: conn} do
|
test "search", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
user_two = insert(:user, %{nickname: "shp@shitposter.club"})
|
||||||
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu 天子"})
|
user_three = insert(:user, %{nickname: "shp@heldscal.la", name: "I love 2hu"})
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu private 天子"})
|
||||||
|
|
||||||
{:ok, _activity} =
|
{:ok, _activity} =
|
||||||
CommonAPI.post(user, %{
|
CommonAPI.post(user, %{
|
||||||
|
@ -70,8 +70,8 @@ test "search", %{conn: conn} do
|
||||||
get(conn, "/api/v2/search", %{"q" => "天子"})
|
get(conn, "/api/v2/search", %{"q" => "天子"})
|
||||||
|> json_response(200)
|
|> json_response(200)
|
||||||
|
|
||||||
[account] == results["accounts"]
|
[status] = results["statuses"]
|
||||||
assert account["id"] == to_string(user_three.id)
|
assert status["id"] == to_string(activity.id)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue