forked from AkkomaGang/akkoma
Merge branch 'backport/issue-1296' into 'maint/1.1'
backport 1296 fix to maint/1.1 See merge request pleroma/pleroma!1790
This commit is contained in:
commit
1dd6d81ddf
6 changed files with 3 additions and 140 deletions
|
@ -9,6 +9,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
||||||
- 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.
|
- ActivityPub: Correct addressing of Undo.
|
||||||
|
|
||||||
|
### Removed
|
||||||
|
- ActivityPub: The `/objects/:uuid/likes` endpoint.
|
||||||
|
|
||||||
## [1.0.90] - 2019-09-30
|
## [1.0.90] - 2019-09-30
|
||||||
### Security
|
### Security
|
||||||
- Mastodon API: respect post privacy in `/api/v1/statuses/:id/{favourited,reblogged}_by`
|
- Mastodon API: respect post privacy in `/api/v1/statuses/:id/{favourited,reblogged}_by`
|
||||||
|
|
|
@ -64,36 +64,6 @@ def object(conn, %{"uuid" => uuid}) do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def object_likes(conn, %{"uuid" => uuid, "page" => page}) do
|
|
||||||
with ap_id <- o_status_url(conn, :object, uuid),
|
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(ap_id),
|
|
||||||
{_, true} <- {:public?, Visibility.is_public?(object)},
|
|
||||||
likes <- Utils.get_object_likes(object) do
|
|
||||||
{page, _} = Integer.parse(page)
|
|
||||||
|
|
||||||
conn
|
|
||||||
|> put_resp_content_type("application/activity+json")
|
|
||||||
|> json(ObjectView.render("likes.json", ap_id, likes, page))
|
|
||||||
else
|
|
||||||
{:public?, false} ->
|
|
||||||
{:error, :not_found}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def object_likes(conn, %{"uuid" => uuid}) do
|
|
||||||
with ap_id <- o_status_url(conn, :object, uuid),
|
|
||||||
%Object{} = object <- Object.get_cached_by_ap_id(ap_id),
|
|
||||||
{_, true} <- {:public?, Visibility.is_public?(object)},
|
|
||||||
likes <- Utils.get_object_likes(object) do
|
|
||||||
conn
|
|
||||||
|> put_resp_content_type("application/activity+json")
|
|
||||||
|> json(ObjectView.render("likes.json", ap_id, likes))
|
|
||||||
else
|
|
||||||
{:public?, false} ->
|
|
||||||
{:error, :not_found}
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
def activity(conn, %{"uuid" => uuid}) do
|
def activity(conn, %{"uuid" => uuid}) do
|
||||||
with ap_id <- o_status_url(conn, :activity, uuid),
|
with ap_id <- o_status_url(conn, :activity, uuid),
|
||||||
%Activity{} = activity <- Activity.normalize(ap_id),
|
%Activity{} = activity <- Activity.normalize(ap_id),
|
||||||
|
|
|
@ -263,16 +263,6 @@ def get_existing_like(actor, %{data: %{"id" => id}}) do
|
||||||
|> Repo.one()
|
|> Repo.one()
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc """
|
|
||||||
Returns like activities targeting an object
|
|
||||||
"""
|
|
||||||
def get_object_likes(%{data: %{"id" => id}}) do
|
|
||||||
id
|
|
||||||
|> Activity.Queries.by_object_id()
|
|
||||||
|> Activity.Queries.by_type("Like")
|
|
||||||
|> Repo.all()
|
|
||||||
end
|
|
||||||
|
|
||||||
@spec make_like_data(User.t(), map(), String.t()) :: map()
|
@spec make_like_data(User.t(), map(), String.t()) :: map()
|
||||||
def make_like_data(
|
def make_like_data(
|
||||||
%User{ap_id: ap_id} = actor,
|
%User{ap_id: ap_id} = actor,
|
||||||
|
|
|
@ -36,40 +36,4 @@ def render("object.json", %{object: %Activity{} = activity}) do
|
||||||
|
|
||||||
Map.merge(base, additional)
|
Map.merge(base, additional)
|
||||||
end
|
end
|
||||||
|
|
||||||
def render("likes.json", ap_id, likes, page) do
|
|
||||||
collection(likes, "#{ap_id}/likes", page)
|
|
||||||
|> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header())
|
|
||||||
end
|
|
||||||
|
|
||||||
def render("likes.json", ap_id, likes) do
|
|
||||||
%{
|
|
||||||
"id" => "#{ap_id}/likes",
|
|
||||||
"type" => "OrderedCollection",
|
|
||||||
"totalItems" => length(likes),
|
|
||||||
"first" => collection(likes, "#{ap_id}/likes", 1)
|
|
||||||
}
|
|
||||||
|> Map.merge(Pleroma.Web.ActivityPub.Utils.make_json_ld_header())
|
|
||||||
end
|
|
||||||
|
|
||||||
def collection(collection, iri, page) do
|
|
||||||
offset = (page - 1) * 10
|
|
||||||
items = Enum.slice(collection, offset, 10)
|
|
||||||
items = Enum.map(items, fn object -> Transmogrifier.prepare_object(object.data) end)
|
|
||||||
total = length(collection)
|
|
||||||
|
|
||||||
map = %{
|
|
||||||
"id" => "#{iri}?page=#{page}",
|
|
||||||
"type" => "OrderedCollectionPage",
|
|
||||||
"partOf" => iri,
|
|
||||||
"totalItems" => total,
|
|
||||||
"orderedItems" => items
|
|
||||||
}
|
|
||||||
|
|
||||||
if offset + length(items) < total do
|
|
||||||
Map.put(map, "next", "#{iri}?page=#{page + 1}")
|
|
||||||
else
|
|
||||||
map
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -541,7 +541,6 @@ defmodule Pleroma.Web.Router do
|
||||||
pipe_through(:ostatus)
|
pipe_through(:ostatus)
|
||||||
|
|
||||||
get("/users/:nickname/outbox", ActivityPubController, :outbox)
|
get("/users/:nickname/outbox", ActivityPubController, :outbox)
|
||||||
get("/objects/:uuid/likes", ActivityPubController, :object_likes)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
pipeline :activitypub_client do
|
pipeline :activitypub_client do
|
||||||
|
|
|
@ -220,69 +220,6 @@ test "cached purged after object deletion", %{conn: conn} do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "/object/:uuid/likes" do
|
|
||||||
setup do
|
|
||||||
like = insert(:like_activity)
|
|
||||||
like_object_ap_id = Object.normalize(like).data["id"]
|
|
||||||
|
|
||||||
uuid =
|
|
||||||
like_object_ap_id
|
|
||||||
|> String.split("/")
|
|
||||||
|> List.last()
|
|
||||||
|
|
||||||
[id: like.data["id"], uuid: uuid]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it returns the like activities in a collection", %{conn: conn, id: id, uuid: uuid} do
|
|
||||||
result =
|
|
||||||
conn
|
|
||||||
|> put_req_header("accept", "application/activity+json")
|
|
||||||
|> get("/objects/#{uuid}/likes")
|
|
||||||
|> json_response(200)
|
|
||||||
|
|
||||||
assert List.first(result["first"]["orderedItems"])["id"] == id
|
|
||||||
assert result["type"] == "OrderedCollection"
|
|
||||||
assert result["totalItems"] == 1
|
|
||||||
refute result["first"]["next"]
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it does not crash when page number is exceeded total pages", %{conn: conn, uuid: uuid} do
|
|
||||||
result =
|
|
||||||
conn
|
|
||||||
|> put_req_header("accept", "application/activity+json")
|
|
||||||
|> get("/objects/#{uuid}/likes?page=2")
|
|
||||||
|> json_response(200)
|
|
||||||
|
|
||||||
assert result["type"] == "OrderedCollectionPage"
|
|
||||||
assert result["totalItems"] == 1
|
|
||||||
refute result["next"]
|
|
||||||
assert Enum.empty?(result["orderedItems"])
|
|
||||||
end
|
|
||||||
|
|
||||||
test "it contains the next key when likes count is more than 10", %{conn: conn} do
|
|
||||||
note = insert(:note_activity)
|
|
||||||
insert_list(11, :like_activity, note_activity: note)
|
|
||||||
|
|
||||||
uuid =
|
|
||||||
note
|
|
||||||
|> Object.normalize()
|
|
||||||
|> Map.get(:data)
|
|
||||||
|> Map.get("id")
|
|
||||||
|> String.split("/")
|
|
||||||
|> List.last()
|
|
||||||
|
|
||||||
result =
|
|
||||||
conn
|
|
||||||
|> put_req_header("accept", "application/activity+json")
|
|
||||||
|> get("/objects/#{uuid}/likes?page=1")
|
|
||||||
|> json_response(200)
|
|
||||||
|
|
||||||
assert result["totalItems"] == 11
|
|
||||||
assert length(result["orderedItems"]) == 10
|
|
||||||
assert result["next"]
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
describe "/activities/:uuid" do
|
describe "/activities/:uuid" do
|
||||||
test "it returns a json representation of the activity", %{conn: conn} do
|
test "it returns a json representation of the activity", %{conn: conn} do
|
||||||
activity = insert(:note_activity)
|
activity = insert(:note_activity)
|
||||||
|
|
Loading…
Reference in a new issue