Merge branch 'develop' into 'fix/2411-mutes-api'
# Conflicts: # CHANGELOG.md # docs/development/API/differences_in_mastoapi_responses.md
This commit is contained in:
commit
d289ad8579
187 changed files with 1031 additions and 509 deletions
|
|
@ -1103,7 +1103,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert %{"error" => "{\"email\":[\"Invalid email\"]}"} =
|
||||
json_response_and_validate_schema(conn, 400)
|
||||
|
||||
Pleroma.Config.put([User, :email_blacklist], [])
|
||||
clear_config([User, :email_blacklist], [])
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.InstanceControllerTest do
|
|||
assert result["pleroma"]["metadata"]["federation"]
|
||||
assert result["pleroma"]["metadata"]["fields_limits"]
|
||||
assert result["pleroma"]["vapid_public_key"]
|
||||
assert result["pleroma"]["stats"]["mau"] == 0
|
||||
|
||||
assert email == from_config_email
|
||||
assert thumbnail == from_config_thumbnail
|
||||
|
|
|
|||
|
|
@ -55,7 +55,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
end
|
||||
|
||||
test "updates a scheduled activity" do
|
||||
Pleroma.Config.put([ScheduledActivity, :enabled], true)
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||
|
||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||
|
|
@ -103,7 +103,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityControllerTest do
|
|||
end
|
||||
|
||||
test "deletes a scheduled activity" do
|
||||
Pleroma.Config.put([ScheduledActivity, :enabled], true)
|
||||
clear_config([ScheduledActivity, :enabled], true)
|
||||
%{user: user, conn: conn} = oauth_access(["write:statuses"])
|
||||
scheduled_at = Timex.shift(NaiveDateTime.utc_now(), minutes: 60)
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
use Oban.Testing, repo: Pleroma.Repo
|
||||
|
||||
alias Pleroma.Activity
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
|
|
@ -29,7 +28,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
setup do: oauth_access(["write:statuses"])
|
||||
|
||||
test "posting a status does not increment reblog_count when relaying", %{conn: conn} do
|
||||
Config.put([:instance, :federating], true)
|
||||
clear_config([:instance, :federating], true)
|
||||
Config.get([:instance, :allow_relay], true)
|
||||
|
||||
response =
|
||||
|
|
@ -151,8 +150,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
|
||||
test "Get MRF reason when posting a status is rejected by one", %{conn: conn} do
|
||||
Config.put([:mrf_keyword, :reject], ["GNO"])
|
||||
Config.put([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
|
||||
clear_config([:mrf_keyword, :reject], ["GNO"])
|
||||
clear_config([:mrf, :policies], [Pleroma.Web.ActivityPub.MRF.KeywordPolicy])
|
||||
|
||||
assert %{"error" => "[KeywordPolicy] Matches with rejected keyword"} =
|
||||
conn
|
||||
|
|
@ -264,6 +263,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
fake_conn =
|
||||
conn
|
||||
|> assign(:user, refresh_record(conn.assigns.user))
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/statuses", %{
|
||||
"status" =>
|
||||
|
|
@ -1204,7 +1204,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
describe "cards" do
|
||||
setup do
|
||||
Config.put([:rich_media, :enabled], true)
|
||||
clear_config([:rich_media, :enabled], true)
|
||||
|
||||
oauth_access(["read:statuses"])
|
||||
end
|
||||
|
|
|
|||
|
|
@ -90,6 +90,65 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
}
|
||||
] = result
|
||||
end
|
||||
|
||||
test "filtering", %{conn: conn, user: user} do
|
||||
local_user = insert(:user)
|
||||
{:ok, user, local_user} = User.follow(user, local_user)
|
||||
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Status"})
|
||||
with_media = create_with_media_activity(local_user)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
{:ok, _user, remote_user} = User.follow(user, remote_user)
|
||||
remote_activity = create_remote_activity(remote_user)
|
||||
|
||||
without_filter_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in without_filter_ids
|
||||
assert remote_activity.id in without_filter_ids
|
||||
assert with_media.id in without_filter_ids
|
||||
|
||||
only_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in only_local_ids
|
||||
refute remote_activity.id in only_local_ids
|
||||
assert with_media.id in only_local_ids
|
||||
|
||||
only_local_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?local=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_local_media_ids
|
||||
refute remote_activity.id in only_local_media_ids
|
||||
assert with_media.id in only_local_media_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/home?remote=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/home?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/home?remote=true&local=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "public" do
|
||||
|
|
@ -98,27 +157,80 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{status: "test"})
|
||||
with_media = create_with_media_activity(user)
|
||||
|
||||
_activity = insert(:note_activity, local: false)
|
||||
remote = insert(:note_activity, local: false)
|
||||
|
||||
conn = get(conn, "/api/v1/timelines/public?local=False")
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?local=False")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> length == 3
|
||||
|
||||
assert length(json_response_and_validate_schema(conn, :ok)) == 2
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=True")
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=1")
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=True&only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=1")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote.id in local_ids
|
||||
|
||||
remote_id = remote.id
|
||||
|
||||
assert [%{"id" => ^remote_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
with_media_id = with_media.id
|
||||
|
||||
assert [%{"id" => ^with_media_id}] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/public?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(:ok) == []
|
||||
|
||||
# does not contain repeats
|
||||
{:ok, _} = CommonAPI.repeat(activity.id, user)
|
||||
|
||||
conn = get(build_conn(), "/api/v1/timelines/public?local=true")
|
||||
|
||||
assert [_] = json_response_and_validate_schema(conn, :ok)
|
||||
assert [_, _] =
|
||||
conn
|
||||
|> get("/api/v1/timelines/public?local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
end
|
||||
|
||||
test "the public timeline includes only public statuses for an authenticated user" do
|
||||
|
|
@ -544,6 +656,77 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
}
|
||||
] = result
|
||||
end
|
||||
|
||||
test "filtering", %{user: user, conn: conn} do
|
||||
{:ok, list} = Pleroma.List.create("name", user)
|
||||
|
||||
local_user = insert(:user)
|
||||
{:ok, local_activity} = CommonAPI.post(local_user, %{status: "Marisa is stupid."})
|
||||
with_media = create_with_media_activity(local_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, local_user)
|
||||
|
||||
remote_user = insert(:user, local: false)
|
||||
remote_activity = create_remote_activity(remote_user)
|
||||
{:ok, list} = Pleroma.List.follow(list, remote_user)
|
||||
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
only_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?local=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert local_activity.id in only_local_ids
|
||||
assert with_media.id in only_local_ids
|
||||
refute remote_activity.id in only_local_ids
|
||||
|
||||
only_local_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?local=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_local_media_ids
|
||||
assert with_media.id in only_local_media_ids
|
||||
refute remote_activity.id in only_local_media_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?remote=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?remote=true&only_media=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
|
||||
only_media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?only_media=true")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute local_activity.id in only_media_ids
|
||||
assert with_media.id in only_media_ids
|
||||
refute remote_activity.id in only_media_ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/list/#{list.id}?only_media=true&local=true&remote=true")
|
||||
|> json_response_and_validate_schema(200) == []
|
||||
end
|
||||
end
|
||||
|
||||
describe "hashtag" do
|
||||
|
|
@ -554,19 +737,85 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
following = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
|
||||
with_media = create_with_media_activity(following)
|
||||
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2hu")
|
||||
remote = insert(:user, local: false)
|
||||
remote_activity = create_remote_activity(remote)
|
||||
|
||||
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
assert activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
# works for different capitalization too
|
||||
nconn = get(conn, "/api/v1/timelines/tag/2HU")
|
||||
all_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2HU")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
||||
assert activity.id in all_ids
|
||||
assert with_media.id in all_ids
|
||||
assert remote_activity.id in all_ids
|
||||
|
||||
assert id == to_string(activity.id)
|
||||
local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
assert activity.id in local_ids
|
||||
assert with_media.id in local_ids
|
||||
refute remote_activity.id in local_ids
|
||||
|
||||
remote_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in remote_ids
|
||||
refute with_media.id in remote_ids
|
||||
assert remote_activity.id in remote_ids
|
||||
|
||||
media_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in media_ids
|
||||
assert with_media.id in media_ids
|
||||
refute remote_activity.id in media_ids
|
||||
|
||||
media_local_ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in media_local_ids
|
||||
assert with_media.id in media_local_ids
|
||||
refute remote_activity.id in media_local_ids
|
||||
|
||||
ids =
|
||||
conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&local=true&remote=true")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|> Enum.map(& &1["id"])
|
||||
|
||||
refute activity.id in ids
|
||||
refute with_media.id in ids
|
||||
refute remote_activity.id in ids
|
||||
|
||||
assert conn
|
||||
|> get("/api/v1/timelines/tag/2hu?only_media=true&remote=true")
|
||||
|> json_response_and_validate_schema(:ok) == []
|
||||
end
|
||||
|
||||
test "multi-hashtag timeline", %{conn: conn} do
|
||||
|
|
@ -726,4 +975,37 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
ensure_authenticated_access(base_uri)
|
||||
end
|
||||
end
|
||||
|
||||
defp create_remote_activity(user) do
|
||||
obj =
|
||||
insert(:note, %{
|
||||
data: %{
|
||||
"to" => [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
User.ap_followers(user)
|
||||
]
|
||||
},
|
||||
user: user
|
||||
})
|
||||
|
||||
insert(:note_activity, %{
|
||||
note: obj,
|
||||
recipients: [
|
||||
"https://www.w3.org/ns/activitystreams#Public",
|
||||
User.ap_followers(user)
|
||||
],
|
||||
user: user,
|
||||
local: false
|
||||
})
|
||||
end
|
||||
|
||||
defp create_with_media_activity(user) do
|
||||
obj = insert(:attachment_note, user: user)
|
||||
|
||||
insert(:note_activity, %{
|
||||
note: obj,
|
||||
recipients: ["https://www.w3.org/ns/activitystreams#Public", User.ap_followers(user)],
|
||||
user: user
|
||||
})
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
||||
use Pleroma.Web.ConnCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -55,7 +54,7 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do
|
|||
conn: conn,
|
||||
path: path
|
||||
} do
|
||||
Config.put([:instance, :public], false)
|
||||
clear_config([:instance, :public], false)
|
||||
|
||||
conn = get(conn, path)
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,6 @@
|
|||
defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
||||
use Pleroma.DataCase
|
||||
|
||||
alias Pleroma.Config
|
||||
alias Pleroma.User
|
||||
alias Pleroma.UserRelationship
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
|
@ -556,7 +555,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
)
|
||||
|
||||
with media_preview_enabled <- [false, true] do
|
||||
Config.put([:media_preview_proxy, :enabled], media_preview_enabled)
|
||||
clear_config([:media_preview_proxy, :enabled], media_preview_enabled)
|
||||
|
||||
AccountView.render("show.json", %{user: user, skip_visibility_check: true})
|
||||
|> Enum.all?(fn
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue