object_validators: Use ecto_types where available
This commit is contained in:
parent
14a06e63f6
commit
7a273087ed
6 changed files with 24 additions and 28 deletions
|
@ -15,16 +15,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.AnswerValidator do
|
||||||
|
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
||||||
field(:to, {:array, :string}, default: [])
|
field(:to, ObjectValidators.Recipients, default: [])
|
||||||
field(:cc, {:array, :string}, default: [])
|
field(:cc, ObjectValidators.Recipients, default: [])
|
||||||
|
field(:bto, ObjectValidators.Recipients, default: [])
|
||||||
# is this actually needed?
|
field(:bcc, ObjectValidators.Recipients, default: [])
|
||||||
field(:bto, {:array, :string}, default: [])
|
|
||||||
field(:bcc, {:array, :string}, default: [])
|
|
||||||
|
|
||||||
field(:type, :string)
|
field(:type, :string)
|
||||||
field(:name, :string)
|
field(:name, :string)
|
||||||
field(:inReplyTo, :string)
|
field(:inReplyTo, ObjectValidators.ObjectID)
|
||||||
field(:attributedTo, ObjectValidators.ObjectID)
|
field(:attributedTo, ObjectValidators.ObjectID)
|
||||||
|
|
||||||
# TODO: Remove actor on objects
|
# TODO: Remove actor on objects
|
||||||
|
|
|
@ -16,11 +16,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.CreateNoteValidator do
|
||||||
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
||||||
field(:actor, ObjectValidators.ObjectID)
|
field(:actor, ObjectValidators.ObjectID)
|
||||||
field(:type, :string)
|
field(:type, :string)
|
||||||
field(:to, {:array, :string})
|
field(:to, ObjectValidators.Recipients, default: [])
|
||||||
field(:cc, {:array, :string})
|
field(:cc, ObjectValidators.Recipients, default: [])
|
||||||
field(:bto, {:array, :string}, default: [])
|
field(:bto, ObjectValidators.Recipients, default: [])
|
||||||
field(:bcc, {:array, :string}, default: [])
|
field(:bcc, ObjectValidators.Recipients, default: [])
|
||||||
|
|
||||||
embeds_one(:object, NoteValidator)
|
embeds_one(:object, NoteValidator)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -20,8 +20,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.EmojiReactValidator do
|
||||||
field(:actor, ObjectValidators.ObjectID)
|
field(:actor, ObjectValidators.ObjectID)
|
||||||
field(:context, :string)
|
field(:context, :string)
|
||||||
field(:content, :string)
|
field(:content, :string)
|
||||||
field(:to, {:array, :string}, default: [])
|
field(:to, ObjectValidators.Recipients, default: [])
|
||||||
field(:cc, {:array, :string}, default: [])
|
field(:cc, ObjectValidators.Recipients, default: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def cast_and_validate(data) do
|
def cast_and_validate(data) do
|
||||||
|
|
|
@ -13,10 +13,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator do
|
||||||
|
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
||||||
field(:to, {:array, :string}, default: [])
|
field(:to, ObjectValidators.Recipients, default: [])
|
||||||
field(:cc, {:array, :string}, default: [])
|
field(:cc, ObjectValidators.Recipients, default: [])
|
||||||
field(:bto, {:array, :string}, default: [])
|
field(:bto, ObjectValidators.Recipients, default: [])
|
||||||
field(:bcc, {:array, :string}, default: [])
|
field(:bcc, ObjectValidators.Recipients, default: [])
|
||||||
# TODO: Write type
|
# TODO: Write type
|
||||||
field(:tag, {:array, :map}, default: [])
|
field(:tag, {:array, :map}, default: [])
|
||||||
field(:type, :string)
|
field(:type, :string)
|
||||||
|
@ -34,7 +34,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.NoteValidator do
|
||||||
field(:replies_count, :integer, default: 0)
|
field(:replies_count, :integer, default: 0)
|
||||||
field(:like_count, :integer, default: 0)
|
field(:like_count, :integer, default: 0)
|
||||||
field(:announcement_count, :integer, default: 0)
|
field(:announcement_count, :integer, default: 0)
|
||||||
field(:inReplyTo, :string)
|
field(:inReplyTo, ObjectValidators.ObjectID)
|
||||||
field(:uri, ObjectValidators.Uri)
|
field(:uri, ObjectValidators.Uri)
|
||||||
|
|
||||||
field(:likes, {:array, :string}, default: [])
|
field(:likes, {:array, :string}, default: [])
|
||||||
|
|
|
@ -19,10 +19,10 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
|
||||||
# Extends from NoteValidator
|
# Extends from NoteValidator
|
||||||
embedded_schema do
|
embedded_schema do
|
||||||
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
field(:id, ObjectValidators.ObjectID, primary_key: true)
|
||||||
field(:to, {:array, :string}, default: [])
|
field(:to, ObjectValidators.Recipients, default: [])
|
||||||
field(:cc, {:array, :string}, default: [])
|
field(:cc, ObjectValidators.Recipients, default: [])
|
||||||
field(:bto, {:array, :string}, default: [])
|
field(:bto, ObjectValidators.Recipients, default: [])
|
||||||
field(:bcc, {:array, :string}, default: [])
|
field(:bcc, ObjectValidators.Recipients, default: [])
|
||||||
# TODO: Write type
|
# TODO: Write type
|
||||||
field(:tag, {:array, :map}, default: [])
|
field(:tag, {:array, :map}, default: [])
|
||||||
field(:type, :string)
|
field(:type, :string)
|
||||||
|
@ -42,7 +42,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.QuestionValidator do
|
||||||
field(:replies_count, :integer, default: 0)
|
field(:replies_count, :integer, default: 0)
|
||||||
field(:like_count, :integer, default: 0)
|
field(:like_count, :integer, default: 0)
|
||||||
field(:announcement_count, :integer, default: 0)
|
field(:announcement_count, :integer, default: 0)
|
||||||
field(:inReplyTo, :string)
|
field(:inReplyTo, ObjectValidators.ObjectID)
|
||||||
field(:uri, ObjectValidators.Uri)
|
field(:uri, ObjectValidators.Uri)
|
||||||
# short identifier for PleromaFE to group statuses by context
|
# short identifier for PleromaFE to group statuses by context
|
||||||
field(:context_id, :integer)
|
field(:context_id, :integer)
|
||||||
|
@ -117,7 +117,7 @@ def changeset(struct, data) do
|
||||||
def validate_data(data_cng) do
|
def validate_data(data_cng) do
|
||||||
data_cng
|
data_cng
|
||||||
|> validate_inclusion(:type, ["Question"])
|
|> validate_inclusion(:type, ["Question"])
|
||||||
|> validate_required([:id, :actor, :attributedTo, :type, :context])
|
|> validate_required([:id, :actor, :attributedTo, :type, :context, :context_id])
|
||||||
|> CommonValidations.validate_any_presence([:cc, :to])
|
|> CommonValidations.validate_any_presence([:cc, :to])
|
||||||
|> CommonValidations.validate_fields_match([:actor, :attributedTo])
|
|> CommonValidations.validate_fields_match([:actor, :attributedTo])
|
||||||
|> CommonValidations.validate_actor_presence()
|
|> CommonValidations.validate_actor_presence()
|
||||||
|
|
|
@ -18,8 +18,8 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator do
|
||||||
field(:type, :string)
|
field(:type, :string)
|
||||||
field(:object, ObjectValidators.ObjectID)
|
field(:object, ObjectValidators.ObjectID)
|
||||||
field(:actor, ObjectValidators.ObjectID)
|
field(:actor, ObjectValidators.ObjectID)
|
||||||
field(:to, {:array, :string}, default: [])
|
field(:to, ObjectValidators.Recipients, default: [])
|
||||||
field(:cc, {:array, :string}, default: [])
|
field(:cc, ObjectValidators.Recipients, default: [])
|
||||||
end
|
end
|
||||||
|
|
||||||
def cast_and_validate(data) do
|
def cast_and_validate(data) do
|
||||||
|
|
Loading…
Reference in a new issue