logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma
commit: ed5a1bbdfcc8b85330c7d4c8f8e08b6c2599ffa5
parent: 0fe715f3ba0f787154ab8e86c8745d7f09affdcb
Author: lambda <pleromagit@rogerbraun.net>
Date:   Thu,  7 Mar 2019 09:33:54 +0000

Merge branch 'preserve-link-headers' into 'develop'

Preserves parameters in link headers

Closes #716

See merge request pleroma/pleroma!908

Diffstat:

Mlib/pleroma/web/mastodon_api/mastodon_api_controller.ex5+++++
Mtest/web/mastodon_api/mastodon_api_controller_test.exs32++++++++++++++++++++++++++++++++
2 files changed, 37 insertions(+), 0 deletions(-)

diff --git a/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex b/lib/pleroma/web/mastodon_api/mastodon_api_controller.ex @@ -190,6 +190,11 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController do end defp add_link_headers(conn, method, activities, param \\ nil, params \\ %{}) do + params = + conn.params + |> Map.drop(["since_id", "max_id"]) + |> Map.merge(params) + last = List.last(activities) first = List.first(activities) diff --git a/test/web/mastodon_api/mastodon_api_controller_test.exs b/test/web/mastodon_api/mastodon_api_controller_test.exs @@ -1955,4 +1955,36 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do |> json_response(400) end end + + describe "link headers" do + test "preserves parameters in link headers", %{conn: conn} do + user = insert(:user) + other_user = insert(:user) + + {:ok, activity1} = + CommonAPI.post(other_user, %{ + "status" => "hi @#{user.nickname}", + "visibility" => "public" + }) + + {:ok, activity2} = + CommonAPI.post(other_user, %{ + "status" => "hi @#{user.nickname}", + "visibility" => "public" + }) + + notification1 = Repo.get_by(Notification, activity_id: activity1.id) + notification2 = Repo.get_by(Notification, activity_id: activity2.id) + + conn = + conn + |> assign(:user, user) + |> get("/api/v1/notifications", %{media_only: true}) + + assert [link_header] = get_resp_header(conn, "link") + assert link_header =~ ~r/media_only=true/ + assert link_header =~ ~r/since_id=#{notification2.id}/ + assert link_header =~ ~r/max_id=#{notification1.id}/ + end + end end