DeleteValidator: Add internal helper field after validation.
This commit is contained in:
parent
143353432a
commit
4500fdc04c
@ -5,6 +5,7 @@
|
|||||||
defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
|
defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
|
||||||
use Ecto.Schema
|
use Ecto.Schema
|
||||||
|
|
||||||
|
alias Pleroma.Activity
|
||||||
alias Pleroma.Web.ActivityPub.ObjectValidators.Types
|
alias Pleroma.Web.ActivityPub.ObjectValidators.Types
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
@ -18,6 +19,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
|
|||||||
field(:actor, Types.ObjectID)
|
field(:actor, Types.ObjectID)
|
||||||
field(:to, Types.Recipients, default: [])
|
field(:to, Types.Recipients, default: [])
|
||||||
field(:cc, Types.Recipients, default: [])
|
field(:cc, Types.Recipients, default: [])
|
||||||
|
field(:deleted_activity_id)
|
||||||
field(:object, Types.ObjectID)
|
field(:object, Types.ObjectID)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -26,12 +28,26 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
|
|||||||
|> cast(data, __schema__(:fields))
|
|> cast(data, __schema__(:fields))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def add_deleted_activity_id(cng) do
|
||||||
|
object =
|
||||||
|
cng
|
||||||
|
|> get_field(:object)
|
||||||
|
|
||||||
|
with %Activity{id: id} <- Activity.get_create_by_object_ap_id(object) do
|
||||||
|
cng
|
||||||
|
|> put_change(:deleted_activity_id, id)
|
||||||
|
else
|
||||||
|
_ -> cng
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def validate_data(cng) do
|
def validate_data(cng) do
|
||||||
cng
|
cng
|
||||||
|> validate_required([:id, :type, :actor, :to, :cc, :object])
|
|> validate_required([:id, :type, :actor, :to, :cc, :object])
|
||||||
|> validate_inclusion(:type, ["Delete"])
|
|> validate_inclusion(:type, ["Delete"])
|
||||||
|> validate_same_domain()
|
|> validate_same_domain()
|
||||||
|> validate_object_or_user_presence()
|
|> validate_object_or_user_presence()
|
||||||
|
|> add_deleted_activity_id()
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_same_domain(cng) do
|
def validate_same_domain(cng) do
|
||||||
|
@ -21,7 +21,9 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
test "it is valid for a post deletion", %{valid_post_delete: valid_post_delete} do
|
test "it is valid for a post deletion", %{valid_post_delete: valid_post_delete} do
|
||||||
assert match?({:ok, _, _}, ObjectValidator.validate(valid_post_delete, []))
|
{:ok, valid_post_delete_u, _} = ObjectValidator.validate(valid_post_delete, [])
|
||||||
|
|
||||||
|
assert valid_post_delete_u["deleted_activity_id"]
|
||||||
end
|
end
|
||||||
|
|
||||||
test "it is valid for a user deletion", %{valid_user_delete: valid_user_delete} do
|
test "it is valid for a user deletion", %{valid_user_delete: valid_user_delete} do
|
||||||
|
Loading…
Reference in New Issue
Block a user