aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-07-02 05:45:19 +0200
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>2020-07-15 12:32:43 +0200
commite4beff90f5670876184b2593c1b4a49f2339d048 (patch)
treedca182e4aa12bb0ecf5502ea6d150e3037675c39 /lib
parent922ca232988b90b7a4fb5918bb76c383c90fd770 (diff)
downloadpleroma-e4beff90f5670876184b2593c1b4a49f2339d048.tar.gz
Create Question: Add context field to create
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/builder.ex10
-rw-r--r--lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex17
-rw-r--r--lib/pleroma/web/activity_pub/transmogrifier.ex2
3 files changed, 28 insertions, 1 deletions
diff --git a/lib/pleroma/web/activity_pub/builder.ex b/lib/pleroma/web/activity_pub/builder.ex
index 49ce5a938..1b4c421b8 100644
--- a/lib/pleroma/web/activity_pub/builder.ex
+++ b/lib/pleroma/web/activity_pub/builder.ex
@@ -80,6 +80,13 @@ defmodule Pleroma.Web.ActivityPub.Builder do
end
def create(actor, object, recipients) do
+ context =
+ if is_map(object) do
+ object["context"]
+ else
+ nil
+ end
+
{:ok,
%{
"id" => Utils.generate_activity_id(),
@@ -88,7 +95,8 @@ defmodule Pleroma.Web.ActivityPub.Builder do
"object" => object,
"type" => "Create",
"published" => DateTime.utc_now() |> DateTime.to_iso8601()
- }, []}
+ }
+ |> Pleroma.Maps.put_if_present("context", context), []}
end
def chat_message(actor, recipient, content, opts \\ []) do
diff --git a/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex b/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex
index 54ea14f89..ff889330e 100644
--- a/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex
+++ b/lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex
@@ -24,6 +24,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
field(:cc, ObjectValidators.Recipients, default: [])
field(:object, ObjectValidators.ObjectID)
field(:expires_at, ObjectValidators.DateTime)
+
+ # Should be moved to object, done for CommonAPI.Utils.make_context
+ field(:context, :string)
end
def cast_data(data) do
@@ -55,6 +58,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
|> validate_actor_is_active()
|> validate_any_presence([:to, :cc])
|> validate_actors_match(meta)
+ |> validate_context_match(meta)
|> validate_object_nonexistence()
|> validate_object_containment()
end
@@ -98,4 +102,17 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
end
end)
end
+
+ def validate_context_match(cng, %{object_data: %{"context" => object_context}}) do
+ cng
+ |> validate_change(:context, fn :context, context ->
+ if context == object_context do
+ []
+ else
+ [{:context, "context field not matching between Create and object (#{object_context})"}]
+ end
+ end)
+ end
+
+ def validate_context_match(cng, _), do: cng
end
diff --git a/lib/pleroma/web/activity_pub/transmogrifier.ex b/lib/pleroma/web/activity_pub/transmogrifier.ex
index 6ab8a52c1..edabe1130 100644
--- a/lib/pleroma/web/activity_pub/transmogrifier.ex
+++ b/lib/pleroma/web/activity_pub/transmogrifier.ex
@@ -643,6 +643,8 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier do
|> Map.put("object", fix_object(object))
|> fix_addressing()
+ data = Map.put_new(data, "context", data["object"]["context"])
+
with {:ok, %User{}} <- ObjectValidator.fetch_actor(data),
{:ok, activity, _} <- Pipeline.common_pipeline(data, local: false) do
{:ok, activity}