mirror of
https://git.pleroma.social/pleroma/pleroma.git
synced 2024-12-22 16:16:34 +00:00
Formatting and add tests for blocks/unblocks
This commit is contained in:
parent
da9744eb84
commit
1e43de0f86
6 changed files with 127 additions and 11 deletions
|
@ -404,18 +404,22 @@ defmodule Pleroma.User do
|
||||||
from(
|
from(
|
||||||
u in User,
|
u in User,
|
||||||
select_merge: %{
|
select_merge: %{
|
||||||
search_distance: fragment(
|
search_distance:
|
||||||
"? <-> (? || ?)",
|
fragment(
|
||||||
^query,
|
"? <-> (? || ?)",
|
||||||
u.nickname,
|
^query,
|
||||||
u.name
|
u.nickname,
|
||||||
)}
|
u.name
|
||||||
|
)
|
||||||
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
q = from(s in subquery(inner),
|
q =
|
||||||
order_by: s.search_distance,
|
from(
|
||||||
limit: 20
|
s in subquery(inner),
|
||||||
)
|
order_by: s.search_distance,
|
||||||
|
limit: 20
|
||||||
|
)
|
||||||
|
|
||||||
Repo.all(q)
|
Repo.all(q)
|
||||||
end
|
end
|
||||||
|
|
|
@ -266,7 +266,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
handle_incoming(data)
|
handle_incoming(data)
|
||||||
end
|
end
|
||||||
|
|
||||||
def handle_incoming(%{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = data) do
|
def handle_incoming(
|
||||||
|
%{"type" => "Block", "object" => blocked, "actor" => blocker, "id" => id} = data
|
||||||
|
) do
|
||||||
with %User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
with %User{local: true} = blocked = User.get_cached_by_ap_id(blocked),
|
||||||
%User{} = blocker = User.get_or_fetch_by_ap_id(blocker),
|
%User{} = blocker = User.get_or_fetch_by_ap_id(blocker),
|
||||||
{:ok, activity} <- ActivityPub.block(blocker, blocked, false) do
|
{:ok, activity} <- ActivityPub.block(blocker, blocked, false) do
|
||||||
|
@ -277,6 +279,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|
||||||
e -> :error
|
e -> :error
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# TODO
|
# TODO
|
||||||
# Accept
|
# Accept
|
||||||
# Undo for non-Announce
|
# Undo for non-Announce
|
||||||
|
|
|
@ -357,6 +357,7 @@ defmodule Pleroma.Web.ActivityPub.Utils do
|
||||||
"object" => block_activity.data
|
"object" => block_activity.data
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
#### Create-related helpers
|
#### Create-related helpers
|
||||||
|
|
||||||
def make_create_data(params, additional) do
|
def make_create_data(params, additional) do
|
||||||
|
|
29
test/fixtures/mastodon-block-activity.json
vendored
Normal file
29
test/fixtures/mastodon-block-activity.json
vendored
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
{
|
||||||
|
"type": "Block",
|
||||||
|
"signature": {
|
||||||
|
"type": "RsaSignature2017",
|
||||||
|
"signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==",
|
||||||
|
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||||
|
"created": "2018-02-17T13:29:31Z"
|
||||||
|
},
|
||||||
|
"object": "http://localtesting.pleroma.lol/users/lain",
|
||||||
|
"nickname": "lain",
|
||||||
|
"id": "http://mastodon.example.org/users/admin#follows/2",
|
||||||
|
"actor": "http://mastodon.example.org/users/admin",
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"Emoji": "toot:Emoji"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
33
test/fixtures/mastodon-unblock-activity.json
vendored
Normal file
33
test/fixtures/mastodon-unblock-activity.json
vendored
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{
|
||||||
|
"@context": [
|
||||||
|
"https://www.w3.org/ns/activitystreams",
|
||||||
|
"https://w3id.org/security/v1",
|
||||||
|
{
|
||||||
|
"toot": "http://joinmastodon.org/ns#",
|
||||||
|
"sensitive": "as:sensitive",
|
||||||
|
"ostatus": "http://ostatus.org#",
|
||||||
|
"movedTo": "as:movedTo",
|
||||||
|
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||||
|
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||||
|
"conversation": "ostatus:conversation",
|
||||||
|
"atomUri": "ostatus:atomUri",
|
||||||
|
"Hashtag": "as:Hashtag",
|
||||||
|
"Emoji": "toot:Emoji"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"signature": {
|
||||||
|
"type": "RsaSignature2017",
|
||||||
|
"signatureValue": "Kn1/UkAQGJVaXBfWLAHcnwHg8YMAUqlEaBuYLazAG+pz5hqivsyrBmPV186Xzr+B4ZLExA9+SnOoNx/GOz4hBm0kAmukNSILAsUd84tcJ2yT9zc1RKtembK4WiwOw7li0+maeDN0HaB6t+6eTqsCWmtiZpprhXD8V1GGT8yG7X24fQ9oFGn+ng7lasbcCC0988Y1eGqNe7KryxcPuQz57YkDapvtONzk8gyLTkZMV4De93MyRHq6GVjQVIgtiYabQAxrX6Q8C+4P/jQoqdWJHEe+MY5JKyNaT/hMPt2Md1ok9fZQBGHlErk22/zy8bSN19GdG09HmIysBUHRYpBLig==",
|
||||||
|
"creator": "http://mastodon.example.org/users/admin#main-key",
|
||||||
|
"created": "2018-02-17T13:29:31Z"
|
||||||
|
},
|
||||||
|
"type": "Undo",
|
||||||
|
"object": {
|
||||||
|
"type": "Block",
|
||||||
|
"object": "http://localtesting.pleroma.lol/users/lain",
|
||||||
|
"nickname": "lain",
|
||||||
|
"id": "http://mastodon.example.org/users/admin#follows/2",
|
||||||
|
"actor": "http://mastodon.example.org/users/admin"
|
||||||
|
},
|
||||||
|
"actor": "http://mastodon.example.org/users/admin"
|
||||||
|
}
|
|
@ -280,10 +280,56 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
||||||
|
|
||||||
assert data["type"] == "Undo"
|
assert data["type"] == "Undo"
|
||||||
assert data["object"]["type"] == "Follow"
|
assert data["object"]["type"] == "Follow"
|
||||||
|
assert data["object"]["object"] == user.ap_id
|
||||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||||
|
|
||||||
refute User.following?(User.get_by_ap_id(data["actor"]), user)
|
refute User.following?(User.get_by_ap_id(data["actor"]), user)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "it works for incoming blocks" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|> Map.put("object", user.ap_id)
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||||
|
|
||||||
|
assert data["type"] == "Block"
|
||||||
|
assert data["object"] == user.ap_id
|
||||||
|
assert data["actor"] == "https://mastodon.example.org/users/admin"
|
||||||
|
|
||||||
|
blocker = User.get_by_ap_id(data["actor"])
|
||||||
|
|
||||||
|
assert User.blocks?(blocker, user.ap_id)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "it works for incoming unblocks" do
|
||||||
|
user = insert(:user)
|
||||||
|
|
||||||
|
block_data =
|
||||||
|
File.read!("test/fixtures/mastodon-block-activity.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|> Map.put("object", user.ap_id)
|
||||||
|
|
||||||
|
{:ok, %Activity{data: _, local: false}} = Transmogrifier.handle_incoming(block_data)
|
||||||
|
|
||||||
|
data =
|
||||||
|
File.read!("test/fixtures/mastodon-unblock-activity.json")
|
||||||
|
|> Poison.decode!()
|
||||||
|
|> Map.put("object", block_data)
|
||||||
|
|
||||||
|
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||||
|
assert data["type"] == "Undo"
|
||||||
|
assert data["object"]["type"] == "Block"
|
||||||
|
assert data["object"]["object"] == user.ap_id
|
||||||
|
assert data["actor"] == "https://mastodon.example.org/users/admin"
|
||||||
|
|
||||||
|
blocker = User.get_by_ap_id(data["actor"])
|
||||||
|
|
||||||
|
refute User.blocks?(blocker, user.ap_id)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "prepare outgoing" do
|
describe "prepare outgoing" do
|
||||||
|
|
Loading…
Reference in a new issue