object_validators: Group common fields in CommonValidations
authorHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Thu, 1 Apr 2021 11:26:32 +0000 (13:26 +0200)
committerHaelwenn (lanodan) Monnier <contact@hacktivis.me>
Sun, 10 Oct 2021 00:50:06 +0000 (02:50 +0200)
Notes:
- QuestionValidator didn't have a :name field but that seems like a mistake
- `_fields` functions can't inherit others because of some Validators
- bto/bcc fields were absent in activities, also seems like a mistake
  (Well IIRC we don't or barely support bto/bcc anyway)

19 files changed:
lib/pleroma/web/activity_pub/object_validators/accept_reject_validator.ex
lib/pleroma/web/activity_pub/object_validators/add_remove_validator.ex
lib/pleroma/web/activity_pub/object_validators/announce_validator.ex
lib/pleroma/web/activity_pub/object_validators/answer_validator.ex
lib/pleroma/web/activity_pub/object_validators/article_note_page_validator.ex
lib/pleroma/web/activity_pub/object_validators/audio_video_validator.ex
lib/pleroma/web/activity_pub/object_validators/block_validator.ex
lib/pleroma/web/activity_pub/object_validators/common_fields.ex [new file with mode: 0644]
lib/pleroma/web/activity_pub/object_validators/create_chat_message_validator.ex
lib/pleroma/web/activity_pub/object_validators/create_generic_validator.ex
lib/pleroma/web/activity_pub/object_validators/delete_validator.ex
lib/pleroma/web/activity_pub/object_validators/emoji_react_validator.ex
lib/pleroma/web/activity_pub/object_validators/event_validator.ex
lib/pleroma/web/activity_pub/object_validators/follow_validator.ex
lib/pleroma/web/activity_pub/object_validators/like_validator.ex
lib/pleroma/web/activity_pub/object_validators/question_validator.ex
lib/pleroma/web/activity_pub/object_validators/undo_validator.ex
lib/pleroma/web/activity_pub/object_validators/update_validator.ex
test/pleroma/web/activity_pub/transmogrifier/add_remove_handling_test.exs

index b577a1044d852baab57fa189f47f78af65d3b6cd..7c3c8d0fad9bc21ea58ec76055ae129da30d7ada 100644 (file)
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptRejectValidator do
   use Ecto.Schema
 
   alias Pleroma.Activity
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
 
   import Ecto.Changeset
   import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
@@ -14,12 +13,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AcceptRejectValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:object, ObjectValidators.ObjectID)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
   end
 
   def cast_data(data) do
index f885aabe4955c6846efb7e762f783420e04385cf..fc482c9c021fc7fed1b2bafa2da5c9a8ce64ec84 100644 (file)
@@ -10,19 +10,20 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AddRemoveValidator do
 
   require Pleroma.Constants
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
   alias Pleroma.User
 
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
     field(:target)
-    field(:object, ObjectValidators.ObjectID)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:type)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
+
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
   end
 
   def cast_and_validate(data) do
index 4db76f387354184be7794590b40ba372d77adb00..a7f2f667305069a26be255e048451a228e8d606c 100644 (file)
@@ -20,13 +20,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnnounceValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:object, ObjectValidators.ObjectID)
-    field(:actor, ObjectValidators.ObjectID)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
+
     field(:context, :string)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
     field(:published, ObjectValidators.DateTime)
   end
 
index 3451e1ff8937254f61de9afadaa7150273d9b879..4325e44f714fe82dd0b04890382509a3782a3286 100644 (file)
@@ -15,12 +15,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnswerValidator do
   @derive Jason.Encoder
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:bto, ObjectValidators.Recipients, default: [])
-    field(:bcc, ObjectValidators.Recipients, default: [])
-    field(:type, :string)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+      end
+    end
+
     field(:name, :string)
     field(:inReplyTo, ObjectValidators.ObjectID)
     field(:attributedTo, ObjectValidators.ObjectID)
index 0d987116c8b00e9d88201a86ffdb5282800e78e7..0aa249c4c1ea089847202ae709e06530aaf9e330 100644 (file)
@@ -6,10 +6,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
   use Ecto.Schema
 
   alias Pleroma.EctoType.ActivityPub.ObjectValidators
-  alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
-  alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
   alias Pleroma.Web.ActivityPub.Transmogrifier
 
   import Ecto.Changeset
@@ -18,38 +16,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.ArticleNotePageValidator do
   @derive Jason.Encoder
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:bto, ObjectValidators.Recipients, default: [])
-    field(:bcc, ObjectValidators.Recipients, default: [])
-    embeds_many(:tag, TagValidator)
-    field(:type, :string)
-
-    field(:name, :string)
-    field(:summary, :string)
-    field(:content, :string)
-
-    field(:context, :string)
-    # short identifier for PleromaFE to group statuses by context
-    field(:context_id, :integer)
-
-    # TODO: Remove actor on objects
-    field(:actor, ObjectValidators.ObjectID)
-
-    field(:attributedTo, ObjectValidators.ObjectID)
-    field(:published, ObjectValidators.DateTime)
-    field(:emoji, ObjectValidators.Emoji, default: %{})
-    field(:sensitive, :boolean, default: false)
-    embeds_many(:attachment, AttachmentValidator)
-    field(:replies_count, :integer, default: 0)
-    field(:like_count, :integer, default: 0)
-    field(:announcement_count, :integer, default: 0)
-    field(:inReplyTo, ObjectValidators.ObjectID)
-    field(:url, ObjectValidators.Uri)
-
-    field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
-    field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        object_fields()
+        status_object_fields()
+      end
+    end
 
     field(:replies, {:array, ObjectValidators.ObjectID}, default: [])
   end
index 572687deb845d5b34d8ce5f4759d5155502033b4..331ec90505f05b5ae7329bcbd3b1dddd077c9d2a 100644 (file)
@@ -5,11 +5,8 @@
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioVideoValidator do
   use Ecto.Schema
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
-  alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
-  alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
   alias Pleroma.Web.ActivityPub.Transmogrifier
 
   import Ecto.Changeset
@@ -18,38 +15,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AudioVideoValidator do
   @derive Jason.Encoder
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:bto, ObjectValidators.Recipients, default: [])
-    field(:bcc, ObjectValidators.Recipients, default: [])
-    embeds_many(:tag, TagValidator)
-    field(:type, :string)
-
-    field(:name, :string)
-    field(:summary, :string)
-    field(:content, :string)
-
-    field(:context, :string)
-    # short identifier for PleromaFE to group statuses by context
-    field(:context_id, :integer)
-
-    # TODO: Remove actor on objects
-    field(:actor, ObjectValidators.ObjectID)
-
-    field(:attributedTo, ObjectValidators.ObjectID)
-    field(:published, ObjectValidators.DateTime)
-    field(:emoji, ObjectValidators.Emoji, default: %{})
-    field(:sensitive, :boolean, default: false)
-    embeds_many(:attachment, AttachmentValidator)
-    field(:replies_count, :integer, default: 0)
-    field(:like_count, :integer, default: 0)
-    field(:announcement_count, :integer, default: 0)
-    field(:inReplyTo, ObjectValidators.ObjectID)
-    field(:url, ObjectValidators.Uri)
-
-    field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
-    field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        object_fields()
+        status_object_fields()
+      end
+    end
   end
 
   def cast_and_apply(data) do
index 88948135fc2f19fee402c5c6a5b9ad9a732927e0..400e5e278c5fd6e628dc2b546f52afc5e4e791a5 100644 (file)
@@ -5,20 +5,21 @@
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator do
   use Ecto.Schema
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
+  alias Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
 
   import Ecto.Changeset
-  import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
 
   @primary_key false
+  @derive Jason.Encoder
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:object, ObjectValidators.ObjectID)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
   end
 
   def cast_data(data) do
@@ -30,8 +31,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.BlockValidator do
     cng
     |> validate_required([:id, :type, :actor, :to, :cc, :object])
     |> validate_inclusion(:type, ["Block"])
-    |> validate_actor_presence()
-    |> validate_actor_presence(field_name: :object)
+    |> CommonValidations.validate_actor_presence()
+    |> CommonValidations.validate_actor_presence(field_name: :object)
   end
 
   def cast_and_validate(data) do
diff --git a/lib/pleroma/web/activity_pub/object_validators/common_fields.ex b/lib/pleroma/web/activity_pub/object_validators/common_fields.ex
new file mode 100644 (file)
index 0000000..872f80e
--- /dev/null
@@ -0,0 +1,68 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.ActivityPub.ObjectValidators.CommonFields do
+  alias Pleroma.EctoType.ActivityPub.ObjectValidators
+  alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
+  alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
+
+  # Activities and Objects, except (Create)ChatMessage
+  defmacro message_fields do
+    quote bind_quoted: binding() do
+      field(:type, :string)
+      field(:id, ObjectValidators.ObjectID, primary_key: true)
+
+      field(:to, ObjectValidators.Recipients, default: [])
+      field(:cc, ObjectValidators.Recipients, default: [])
+      field(:bto, ObjectValidators.Recipients, default: [])
+      field(:bcc, ObjectValidators.Recipients, default: [])
+    end
+  end
+
+  defmacro activity_fields do
+    quote bind_quoted: binding() do
+      field(:object, ObjectValidators.ObjectID)
+      field(:actor, ObjectValidators.ObjectID)
+    end
+  end
+
+  # All objects except Answer and CHatMessage
+  defmacro object_fields do
+    quote bind_quoted: binding() do
+      field(:content, :string)
+
+      field(:published, ObjectValidators.DateTime)
+      field(:emoji, ObjectValidators.Emoji, default: %{})
+      embeds_many(:attachment, AttachmentValidator)
+    end
+  end
+
+  # Basically objects that aren't ChatMessage and Answer
+  defmacro status_object_fields do
+    quote bind_quoted: binding() do
+      # TODO: Remove actor on objects
+      field(:actor, ObjectValidators.ObjectID)
+      field(:attributedTo, ObjectValidators.ObjectID)
+
+      embeds_many(:tag, TagValidator)
+
+      field(:name, :string)
+      field(:summary, :string)
+
+      field(:context, :string)
+      # short identifier for PleromaFE to group statuses by context
+      field(:context_id, :integer)
+
+      field(:sensitive, :boolean, default: false)
+      field(:replies_count, :integer, default: 0)
+      field(:like_count, :integer, default: 0)
+      field(:announcement_count, :integer, default: 0)
+      field(:inReplyTo, ObjectValidators.ObjectID)
+      field(:url, ObjectValidators.Uri)
+
+      field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
+      field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
+    end
+  end
+end
index 7a31a99bfeb8be15b0947886c24cff31a2f2d65a..6551f64cac69d66d5a5a46f9558d3004f3c05532 100644 (file)
@@ -17,11 +17,16 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateChatMessageValidator do
   @primary_key false
 
   embedded_schema do
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        activity_fields()
+      end
+    end
+
     field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:actor, ObjectValidators.ObjectID)
     field(:type, :string)
     field(:to, ObjectValidators.Recipients, default: [])
-    field(:object, ObjectValidators.ObjectID)
   end
 
   def cast_and_apply(data) do
index d2de53049d760edf2820b17e6c309c92a83e7b8f..803b5d5a11d009b2752e871a29062701e919ac3f 100644 (file)
@@ -20,14 +20,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateGenericValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:type, :string)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:bto, ObjectValidators.Recipients, default: [])
-    field(:bcc, ObjectValidators.Recipients, default: [])
-    field(:object, ObjectValidators.ObjectID)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
+
     field(:expires_at, ObjectValidators.DateTime)
 
     # Should be moved to object, done for CommonAPI.Utils.make_context
index 05f93da825cb21662adc1fe4286114b05f186b24..f0c99356e75aa3f54f773ce66b3cff37bafbe860 100644 (file)
@@ -15,13 +15,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
+
     field(:deleted_activity_id, ObjectValidators.ObjectID)
-    field(:object, ObjectValidators.ObjectID)
   end
 
   def cast_data(data) do
index a18bd7540b28056e4b3bd0ff9eb29ea8118e5c23..9eaaf831929fe75b49ecdb4bf23c6ae2e3085698 100644 (file)
@@ -5,7 +5,6 @@
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
   use Ecto.Schema
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
   alias Pleroma.Object
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
 
@@ -15,14 +14,16 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:object, ObjectValidators.ObjectID)
-    field(:actor, ObjectValidators.ObjectID)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
+
     field(:context, :string)
     field(:content, :string)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
   end
 
   def cast_and_validate(data) do
index fee2e997afd967cc9bd63858c7503f65ee659f3d..34a3031c3f0d168f1274f2a31b0b2e2d1346dfa5 100644 (file)
@@ -5,11 +5,8 @@
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.EventValidator do
   use Ecto.Schema
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
-  alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
-  alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
   alias Pleroma.Web.ActivityPub.Transmogrifier
 
   import Ecto.Changeset
@@ -19,38 +16,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EventValidator do
 
   # Extends from NoteValidator
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:bto, ObjectValidators.Recipients, default: [])
-    field(:bcc, ObjectValidators.Recipients, default: [])
-    embeds_many(:tag, TagValidator)
-    field(:type, :string)
-
-    field(:name, :string)
-    field(:summary, :string)
-    field(:content, :string)
-
-    field(:context, :string)
-    # short identifier for PleromaFE to group statuses by context
-    field(:context_id, :integer)
-
-    # TODO: Remove actor on objects
-    field(:actor, ObjectValidators.ObjectID)
-
-    field(:attributedTo, ObjectValidators.ObjectID)
-    field(:published, ObjectValidators.DateTime)
-    field(:emoji, ObjectValidators.Emoji, default: %{})
-    field(:sensitive, :boolean, default: false)
-    embeds_many(:attachment, AttachmentValidator)
-    field(:replies_count, :integer, default: 0)
-    field(:like_count, :integer, default: 0)
-    field(:announcement_count, :integer, default: 0)
-    field(:inReplyTo, ObjectValidators.ObjectID)
-    field(:url, ObjectValidators.Uri)
-
-    field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
-    field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        object_fields()
+        status_object_fields()
+      end
+    end
   end
 
   def cast_and_apply(data) do
index 239cee5e7a3f5ad97da792026127ad45a8d79157..c061ebba924495cd722d8657724ea4333e2f0dfa 100644 (file)
@@ -5,20 +5,20 @@
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.FollowValidator do
   use Ecto.Schema
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
-
   import Ecto.Changeset
   import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
 
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:object, ObjectValidators.ObjectID)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
+
     field(:state, :string, default: "pending")
   end
 
index 8b99c89b90741cfdbbe6eeed4c32439e444d9e94..35e000d72888b59186a0c85b5cc0c8b15607b459 100644 (file)
@@ -5,7 +5,6 @@
 defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator do
   use Ecto.Schema
 
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
   alias Pleroma.Object
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
   alias Pleroma.Web.ActivityPub.Utils
@@ -16,13 +15,15 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.LikeValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:object, ObjectValidators.ObjectID)
-    field(:actor, ObjectValidators.ObjectID)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
+
     field(:context, :string)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
   end
 
   def cast_and_validate(data) do
index 083d08ec4e3ce93da3aecac14d3e42271b21fda4..bdddfdaeb55070636a3e9e627db75f3b8dcb6386 100644 (file)
@@ -6,11 +6,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
   use Ecto.Schema
 
   alias Pleroma.EctoType.ActivityPub.ObjectValidators
-  alias Pleroma.Web.ActivityPub.ObjectValidators.AttachmentValidator
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonFixes
   alias Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
   alias Pleroma.Web.ActivityPub.ObjectValidators.QuestionOptionsValidator
-  alias Pleroma.Web.ActivityPub.ObjectValidators.TagValidator
   alias Pleroma.Web.ActivityPub.Transmogrifier
 
   import Ecto.Changeset
@@ -20,35 +18,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
 
   # Extends from NoteValidator
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
-    field(:bto, ObjectValidators.Recipients, default: [])
-    field(:bcc, ObjectValidators.Recipients, default: [])
-    embeds_many(:tag, TagValidator)
-    field(:type, :string)
-    field(:content, :string)
-    field(:context, :string)
-
-    # TODO: Remove actor on objects
-    field(:actor, ObjectValidators.ObjectID)
-
-    field(:attributedTo, ObjectValidators.ObjectID)
-    field(:summary, :string)
-    field(:published, ObjectValidators.DateTime)
-    field(:emoji, ObjectValidators.Emoji, default: %{})
-    field(:sensitive, :boolean, default: false)
-    embeds_many(:attachment, AttachmentValidator)
-    field(:replies_count, :integer, default: 0)
-    field(:like_count, :integer, default: 0)
-    field(:announcement_count, :integer, default: 0)
-    field(:inReplyTo, ObjectValidators.ObjectID)
-    field(:url, ObjectValidators.Uri)
-    # short identifier for PleromaFE to group statuses by context
-    field(:context_id, :integer)
-
-    field(:likes, {:array, ObjectValidators.ObjectID}, default: [])
-    field(:announcements, {:array, ObjectValidators.ObjectID}, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        object_fields()
+        status_object_fields()
+      end
+    end
 
     field(:closed, ObjectValidators.DateTime)
     field(:voters, {:array, ObjectValidators.ObjectID}, default: [])
index 6ff648c849b31af5a59f0b096e93746328d44394..703643e3f1d841ff53b8e87957a6a3eb049c5166 100644 (file)
@@ -6,7 +6,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator do
   use Ecto.Schema
 
   alias Pleroma.Activity
-  alias Pleroma.EctoType.ActivityPub.ObjectValidators
   alias Pleroma.User
 
   import Ecto.Changeset
@@ -15,12 +14,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
-    field(:object, ObjectValidators.ObjectID)
-    field(:actor, ObjectValidators.ObjectID)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+        activity_fields()
+      end
+    end
   end
 
   def cast_and_validate(data) do
index 6bb1dc7fa1f2c80d978296515d11446277b88634..a1fae47f58aeb84ad7baba87826a3a1a7a058eb5 100644 (file)
@@ -13,11 +13,14 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UpdateValidator do
   @primary_key false
 
   embedded_schema do
-    field(:id, ObjectValidators.ObjectID, primary_key: true)
-    field(:type, :string)
+    quote do
+      unquote do
+        import Elixir.Pleroma.Web.ActivityPub.ObjectValidators.CommonFields
+        message_fields()
+      end
+    end
+
     field(:actor, ObjectValidators.ObjectID)
-    field(:to, ObjectValidators.Recipients, default: [])
-    field(:cc, ObjectValidators.Recipients, default: [])
     # In this case, we save the full object in this activity instead of just a
     # reference, so we can always see what was actually changed by this.
     field(:object, :map)
index fc7757125e2f139da30b7b780029fd09a39136f8..b17c0e7bf169a839adb710ca369f2c8fa43d426b 100644 (file)
@@ -67,7 +67,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
       "target" => "https://example.com/users/lain/collections/featured",
       "type" => "Add",
       "to" => [Pleroma.Constants.as_public()],
-      "cc" => ["https://example.com/users/lain/followers"]
+      "cc" => ["https://example.com/users/lain/followers"],
+      "bcc" => [],
+      "bto" => []
     }
 
     assert {:ok, activity} = Transmogrifier.handle_incoming(message)
@@ -82,7 +84,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
       "target" => "https://example.com/users/lain/collections/featured",
       "type" => "Remove",
       "to" => [Pleroma.Constants.as_public()],
-      "cc" => ["https://example.com/users/lain/followers"]
+      "cc" => ["https://example.com/users/lain/followers"],
+      "bcc" => [],
+      "bto" => []
     }
 
     assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
@@ -161,7 +165,9 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
       "target" => "https://#{host}/users/#{user.nickname}/collections/featured",
       "type" => "Add",
       "to" => [Pleroma.Constants.as_public()],
-      "cc" => ["https://#{host}/users/#{user.nickname}/followers"]
+      "cc" => ["https://#{host}/users/#{user.nickname}/followers"],
+      "bcc" => [],
+      "bto" => []
     }
 
     assert {:ok, activity} = Transmogrifier.handle_incoming(message)