X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=lib%2Fpleroma%2Fweb%2Factivity_pub%2Fobject_validators%2Fdelete_validator.ex;h=7da67bf16bf6d845ca53fa007d8fc444e2f9fa47;hb=84f42b92f0f53c569d0f7628d0a4af3ee5c06eaa;hp=a2eff7b69895ae0a64bec99d4b1a320cb4f043e3;hpb=32b8386edeec3e9b24123c3ccc81a22f1edd5a1c;p=akkoma
diff --git a/lib/pleroma/web/activity_pub/object_validators/delete_validator.ex b/lib/pleroma/web/activity_pub/object_validators/delete_validator.ex
index a2eff7b69..7da67bf16 100644
--- a/lib/pleroma/web/activity_pub/object_validators/delete_validator.ex
+++ b/lib/pleroma/web/activity_pub/object_validators/delete_validator.ex
@@ -1,13 +1,12 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
use Ecto.Schema
alias Pleroma.Activity
- alias Pleroma.User
- alias Pleroma.Web.ActivityPub.ObjectValidators.Types
+ alias Pleroma.EctoType.ActivityPub.ObjectValidators
import Ecto.Changeset
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
@@ -15,13 +14,13 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
@primary_key false
embedded_schema do
- field(:id, Types.ObjectID, primary_key: true)
+ field(:id, ObjectValidators.ObjectID, primary_key: true)
field(:type, :string)
- field(:actor, Types.ObjectID)
- field(:to, Types.Recipients, default: [])
- field(:cc, Types.Recipients, default: [])
- field(:deleted_activity_id)
- field(:object, Types.ObjectID)
+ field(:actor, ObjectValidators.ObjectID)
+ field(:to, ObjectValidators.Recipients, default: [])
+ field(:cc, ObjectValidators.Recipients, default: [])
+ field(:deleted_activity_id, ObjectValidators.ObjectID)
+ field(:object, ObjectValidators.ObjectID)
end
def cast_data(data) do
@@ -42,13 +41,25 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
end
end
- def validate_data(cng) do
+ @deletable_types ~w{
+ Answer
+ Article
+ Audio
+ ChatMessage
+ Event
+ Note
+ Page
+ Question
+ Tombstone
+ Video
+ }
+ defp validate_data(cng) do
cng
|> validate_required([:id, :type, :actor, :to, :cc, :object])
|> validate_inclusion(:type, ["Delete"])
|> validate_actor_presence()
- |> validate_deletion_rights()
- |> validate_object_or_user_presence()
+ |> validate_modification_rights()
+ |> validate_object_or_user_presence(allowed_types: @deletable_types)
|> add_deleted_activity_id()
end
@@ -56,33 +67,6 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
!same_domain?(cng)
end
- defp same_domain?(cng) do
- actor_domain =
- cng
- |> get_field(:actor)
- |> URI.parse()
- |> (& &1.host).()
-
- object_domain =
- cng
- |> get_field(:object)
- |> URI.parse()
- |> (& &1.host).()
-
- object_domain == actor_domain
- end
-
- def validate_deletion_rights(cng) do
- actor = User.get_cached_by_ap_id(get_field(cng, :actor))
-
- if User.superuser?(actor) || same_domain?(cng) do
- cng
- else
- cng
- |> add_error(:actor, "is not allowed to delete object")
- end
- end
-
def cast_and_validate(data) do
data
|> cast_data