Merge branch 'bugfix/sensitive_object' into 'develop'

Transmogrifier.set_sensitive/1: Keep sensitive set to true

Closes #954

See merge request pleroma/pleroma!2470
This commit is contained in:
lain 2020-05-06 09:04:13 +00:00
commit df846eda71
3 changed files with 20 additions and 7 deletions

View File

@ -49,6 +49,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
- Logger configuration through AdminFE - Logger configuration through AdminFE
- HTTP Basic Authentication permissions issue - HTTP Basic Authentication permissions issue
- ObjectAgePolicy didn't filter out old messages - ObjectAgePolicy didn't filter out old messages
- Transmogrifier: Keep object sensitive settings for outgoing representation (AP C2S)
### Added ### Added
- NodeInfo: ObjectAgePolicy settings to the `federation` list. - NodeInfo: ObjectAgePolicy settings to the `federation` list.

View File

@ -1195,6 +1195,10 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
Map.put(object, "conversation", object["context"]) Map.put(object, "conversation", object["context"])
end end
def set_sensitive(%{"sensitive" => true} = object) do
object
end
def set_sensitive(object) do def set_sensitive(object) do
tags = object["tag"] || [] tags = object["tag"] || []
Map.put(object, "sensitive", "nsfw" in tags) Map.put(object, "sensitive", "nsfw" in tags)

View File

@ -820,21 +820,29 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do
activity: activity activity: activity
} do } do
user = insert(:user) user = insert(:user)
conn = assign(conn, :user, user)
object = Map.put(activity["object"], "sensitive", true) object = Map.put(activity["object"], "sensitive", true)
activity = Map.put(activity, "object", object) activity = Map.put(activity, "object", object)
result = response =
conn conn
|> assign(:user, user)
|> put_req_header("content-type", "application/activity+json") |> put_req_header("content-type", "application/activity+json")
|> post("/users/#{user.nickname}/outbox", activity) |> post("/users/#{user.nickname}/outbox", activity)
|> json_response(201) |> json_response(201)
assert Activity.get_by_ap_id(result["id"]) assert Activity.get_by_ap_id(response["id"])
assert result["object"] assert response["object"]
assert %Object{data: object} = Object.normalize(result["object"]) assert %Object{data: response_object} = Object.normalize(response["object"])
assert object["sensitive"] == activity["object"]["sensitive"] assert response_object["sensitive"] == true
assert object["content"] == activity["object"]["content"] assert response_object["content"] == activity["object"]["content"]
representation =
conn
|> put_req_header("accept", "application/activity+json")
|> get(response["id"])
|> json_response(200)
assert representation["object"]["sensitive"] == true
end end
test "it rejects an incoming activity with bogus type", %{conn: conn, activity: activity} do test "it rejects an incoming activity with bogus type", %{conn: conn, activity: activity} do