diff options
author | lain <lain@soykaf.club> | 2020-04-28 16:45:28 +0200 |
---|---|---|
committer | lain <lain@soykaf.club> | 2020-04-28 16:45:28 +0200 |
commit | abd09282292f7e902c77b158ae3d86e9bfd5b986 (patch) | |
tree | bdbb89a1dbcb814e5d14b495711e798635eea56f /lib | |
parent | 6aa116eca7d6ef6567dcef03b8c776bd2134bf3f (diff) | |
download | pleroma-abd09282292f7e902c77b158ae3d86e9bfd5b986.tar.gz |
CreateChatMessageValidator: Validate object existence
Diffstat (limited to 'lib')
-rw-r--r-- | lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex | 14 |
1 files changed, 13 insertions, 1 deletions
diff --git a/lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex b/lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex index 21c7a5ba4..dfc91bf71 100644 --- a/lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex +++ b/lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex @@ -5,10 +5,10 @@ # NOTES # - Can probably be a generic create validator # - doesn't embed, will only get the object id -# - object has to be validated first, maybe with some meta info from the surrounding create defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateChatMessageValidator do use Ecto.Schema + alias Pleroma.Object alias Pleroma.Web.ActivityPub.ObjectValidators.Types import Ecto.Changeset @@ -43,6 +43,18 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateChatMessageValidator do |> validate_required([:id, :actor, :to, :type, :object]) |> validate_inclusion(:type, ["Create"]) |> validate_recipients_match(meta) + |> validate_object_nonexistence() + end + + def validate_object_nonexistence(cng) do + cng + |> validate_change(:object, fn :object, object_id -> + if Object.get_cached_by_ap_id(object_id) do + [{:object, "The object to create already exists"}] + else + [] + end + end) end def validate_recipients_match(cng, meta) do |