Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-03-12 23:11:19 +01:00
parent 151dd7ccb1
commit a97334520b
13 changed files with 71 additions and 73 deletions

View file

@ -1,3 +1,7 @@
A fork of Pleroma/Rebased. More information soon.
---
<img src="https://git.pleroma.social/pleroma/pleroma/uploads/8cec84f5a084d887339f57deeb8a293e/pleroma-banner-vector-nopad-notext.svg" width="300px" />
## About

View file

@ -94,9 +94,18 @@ def assign_account(
end
end
def notes_create(%{assigns: %{user: user}, body_params: %{content: content}} = conn, %{
id: report_id
}) do
def notes_create(
%{
assigns: %{user: user},
private: %{
open_api_spex: %{
body_params: %{content: content},
params: %{id: report_id}
}
}
} = conn,
_
) do
with {:ok, _} <- ReportNote.create(user.id, report_id, content),
report <- Activity.get_by_id_with_user_actor(report_id) do
ModerationLog.insert_log(%{

View file

@ -69,7 +69,7 @@ def delete(
defp do_deletes(%{assigns: %{user: admin}} = conn, nicknames) when is_list(nicknames) do
users = Enum.map(nicknames, &User.get_cached_by_nickname/1)
if Enum.all?(users, &is_higher_role(admin, &1)) do
if Enum.all?(users, &higher_role?(admin, &1)) do
Enum.each(users, fn user ->
{:ok, delete_data, _} = Builder.delete(admin, user.ap_id)
Pipeline.common_pipeline(delete_data, local: true)
@ -90,7 +90,7 @@ defp do_deletes(%{assigns: %{user: admin}} = conn, nicknames) when is_list(nickn
end
# true if actor is greater OR EQUAL in role to target
defp is_higher_role(%User{} = actor, %User{} = target) do
defp higher_role?(%User{} = actor, %User{} = target) do
role_weight(actor) >= role_weight(target)
end

View file

@ -105,7 +105,7 @@ def update_operation do
def assign_account_operation do
%Operation{
tags: ["Report managment"],
tags: ["Report management"],
summary: "Assign account to specified reports",
operationId: "AdminAPI.ReportController.assign_account",
security: [%{"oAuth" => ["admin:write:reports"]}],

View file

@ -641,7 +641,10 @@ def endorsements(%{assigns: %{user: user}} = conn, params) do
end
@doc "GET /api/v1/accounts/familiar_followers"
def familiar_followers(%{assigns: %{user: user}} = conn, %{id: id}) do
def familiar_followers(
%{assigns: %{user: user}, private: %{open_api_spex: %{params: %{id: id}}}} = conn,
_
) do
users =
User.get_all_by_ids(List.wrap(id))
|> Enum.map(&%{id: &1.id, accounts: get_familiar_followers(&1, user)})

View file

@ -562,7 +562,13 @@ def context(
end
@doc "POST /api/v1/statuses/:id/translate"
def translate(%{body_params: params, assigns: %{user: user}} = conn, %{id: status_id}) do
def translate(
%{
assigns: %{user: user},
private: %{open_api_spex: %{body_params: params, params: %{id: status_id}}}
} = conn,
_
) do
with {:authentication, true} <-
{:authentication,
!is_nil(user) ||

View file

@ -125,7 +125,7 @@ def scrub_mime(%Plug.Conn{halted: false, resp_headers: headers}, _args \\ []) do
end
end
defp plaintext_header() do
defp plaintext_header do
[{"content-type", "text/plain"}]
end
end

View file

@ -54,13 +54,12 @@ def fetch_data_for_activity(%Activity{data: %{"type" => "Create"}} = activity) d
@cachex.fetch!(:scrubber_cache, key, fn _ ->
result = fetch_data_for_object(object)
cond do
match?(%{page_url: _, rich_media: _}, result) ->
Activity.HTML.add_cache_key_for(activity.id, key)
{:commit, result}
true ->
{:ignore, %{}}
with %Embed{} <- result do
Activity.HTML.add_cache_key_for(activity.id, key)
{:commit, result}
else
_ ->
{:ignore, nil}
end
end)
end

View file

@ -150,7 +150,8 @@ def get_template_from_xml(body) do
xpath = "//Link[@rel='lrdd']/@template"
with {_, {:ok, doc}} <- {:xml_parse, XML.parse_document(body)},
{_, template} when template != nil <- {:find_template, XML.string_from_xpath(xpath, doc)} do
{_, template} when template != nil <-
{:find_template, XML.string_from_xpath(xpath, doc)} do
{:ok, template}
else
error -> {:error, error}

View file

@ -138,23 +138,6 @@ test "get oauth_consumer_strategies", %{conn: conn} do
assert result["pleroma"]["oauth_consumer_strategies"] == ["keycloak"]
end
test "get instance contact information", %{conn: conn} do
user = insert(:user, %{local: true})
clear_config([:instance, :contact_username], user.nickname)
conn = get(conn, "/api/v1/instance")
assert result = json_response_and_validate_schema(conn, 200)
assert result["contact_account"]["id"] == user.id
end
test "get instance information v2", %{conn: conn} do
assert get(conn, "/api/v2/instance")
|> json_response_and_validate_schema(200)
end
describe "instance domain blocks" do
setup do
clear_config([:mrf_simple, :reject], [{"fediverse.pl", "uses Soapbox"}])

View file

@ -3,27 +3,37 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.ChatMessageReferenceViewTest do
alias Pleroma.NullCache
use Pleroma.DataCase, async: true
use Pleroma.DataCase, async: false
alias Pleroma.Chat
alias Pleroma.Chat.MessageReference
alias Pleroma.Object
alias Pleroma.StaticStubbedConfigMock
alias Pleroma.UnstubbedConfigMock, as: ConfigMock
alias Pleroma.StaticStubbedConfigMock, as: ConfigMock
alias Pleroma.Web.ActivityPub.ActivityPub
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.PleromaAPI.Chat.MessageReferenceView
import Mox
import Pleroma.Factory
import Tesla.Mock
test "it displays a chat message" do
user = insert(:user)
recipient = insert(:user)
test "crawls valid, complete URLs" do
mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
ConfigMock
|> stub_with(Pleroma.Test.StaticConfig)
|> stub(:get, fn
[:rich_media, :enabled] -> true
path -> Pleroma.Test.StaticConfig.get(path)
end)
Pleroma.UnstubbedConfigMock
|> stub(:get, fn
[:rich_media, :enabled] -> true
path -> Pleroma.Test.StaticConfig.get(path)
end)
user = insert(:user)
recipient = insert(:user)
file = %Plug.Upload{
content_type: "image/jpeg",
@ -42,14 +52,14 @@ test "it displays a chat message" do
cm_ref = MessageReference.for_chat_and_object(chat, object)
id = cm_ref.id
{:ok, activity} =
CommonAPI.post(user, %{
status: "[test](https://example.com/ogp)",
content_type: "text/markdown"
})
Pleroma.CachexMock
|> stub(:get, fn
:chat_message_id_idempotency_key_cache, ^id -> {:ok, "123"}
cache, key -> NullCache.get(cache, key)
end)
|> stub(:fetch, fn :rich_media_cache, _, _ -> {:ok, {:ok, %{}}} end)
assert %{url: "https://example.com/ogp", meta: %{} = _} =
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
chat_message = MessageReferenceView.render("show.json", chat_message_reference: cm_ref)
@ -60,18 +70,6 @@ test "it displays a chat message" do
assert chat_message[:created_at]
assert chat_message[:unread] == false
assert match?([%{shortcode: "firefox"}], chat_message[:emojis])
assert chat_message[:idempotency_key] == "123"
StaticStubbedConfigMock
|> stub(:get, fn
[:rich_media, :enabled] -> true
path -> Pleroma.Test.StaticConfig.get(path)
end)
Tesla.Mock.mock_global(fn
%{url: "https://example.com/ogp"} ->
%Tesla.Env{status: 200, body: File.read!("test/fixtures/rich_media/ogp.html")}
end)
{:ok, activity} =
CommonAPI.post_chat_message(recipient, user, "gkgkgk https://example.com/ogp",

View file

@ -97,7 +97,7 @@ test "recrawls URLs on updates" do
{:ok, activity} = CommonAPI.post(user, %{status: "I like this site #{original_url}"})
assert match?(
%{page_url: ^original_url, rich_media: _},
%{url: ^original_url, meta: _},
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
)
@ -106,7 +106,7 @@ test "recrawls URLs on updates" do
activity = Pleroma.Activity.get_by_id(activity.id)
assert match?(
%{page_url: ^updated_url, rich_media: _},
%{url: ^updated_url, meta: _},
Pleroma.Web.RichMedia.Helpers.fetch_data_for_activity(activity)
)
end
@ -128,10 +128,10 @@ test "refuses to crawl URLs of private network from posts" do
path -> Pleroma.Test.StaticConfig.get(path)
end)
assert %{} == Helpers.fetch_data_for_activity(activity)
assert %{} == Helpers.fetch_data_for_activity(activity2)
assert %{} == Helpers.fetch_data_for_activity(activity3)
assert %{} == Helpers.fetch_data_for_activity(activity4)
assert %{} == Helpers.fetch_data_for_activity(activity5)
assert Helpers.fetch_data_for_activity(activity) == nil
assert Helpers.fetch_data_for_activity(activity2) == nil
assert Helpers.fetch_data_for_activity(activity3) == nil
assert Helpers.fetch_data_for_activity(activity4) == nil
assert Helpers.fetch_data_for_activity(activity5) == nil
end
end

View file

@ -56,11 +56,6 @@ test "Webfinger JRD" do
end
test "reach user on tld, while pleroma is running on subdomain" do
Pleroma.Web.Endpoint.config_change(
[{Pleroma.Web.Endpoint, url: [host: "sub.example.com"]}],
[]
)
clear_config([Pleroma.Web.Endpoint, :url, :host], "sub.example.com")
clear_config([Pleroma.Web.WebFinger, :domain], "example.com")