forked from AkkomaGang/akkoma
Deletions: allow deactivated users to be deleted
This commit is contained in:
parent
a7929c4d89
commit
43800d83f4
4 changed files with 32 additions and 9 deletions
|
@ -52,15 +52,18 @@ defp get_recipients(data) do
|
||||||
{recipients, to, cc}
|
{recipients, to, cc}
|
||||||
end
|
end
|
||||||
|
|
||||||
defp check_actor_is_active(nil), do: true
|
defp check_actor_can_insert(%{"type" => "Delete"}), do: true
|
||||||
|
defp check_actor_can_insert(%{"type" => "Undo"}), do: true
|
||||||
|
|
||||||
defp check_actor_is_active(actor) when is_binary(actor) do
|
defp check_actor_can_insert(%{"actor" => actor}) when is_binary(actor) do
|
||||||
case User.get_cached_by_ap_id(actor) do
|
case User.get_cached_by_ap_id(actor) do
|
||||||
%User{is_active: true} -> true
|
%User{is_active: true} -> true
|
||||||
_ -> false
|
_ -> false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp check_actor_can_insert(_), do: true
|
||||||
|
|
||||||
defp check_remote_limit(%{"object" => %{"content" => content}}) when not is_nil(content) do
|
defp check_remote_limit(%{"object" => %{"content" => content}}) when not is_nil(content) do
|
||||||
limit = Config.get([:instance, :remote_limit])
|
limit = Config.get([:instance, :remote_limit])
|
||||||
String.length(content) <= limit
|
String.length(content) <= limit
|
||||||
|
@ -116,7 +119,7 @@ def persist(object, meta) do
|
||||||
def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when is_map(map) do
|
def insert(map, local \\ true, fake \\ false, bypass_actor_check \\ false) when is_map(map) do
|
||||||
with nil <- Activity.normalize(map),
|
with nil <- Activity.normalize(map),
|
||||||
map <- lazy_put_activity_defaults(map, fake),
|
map <- lazy_put_activity_defaults(map, fake),
|
||||||
{_, true} <- {:actor_check, bypass_actor_check || check_actor_is_active(map["actor"])},
|
{_, true} <- {:actor_check, bypass_actor_check || check_actor_can_insert(map)},
|
||||||
{_, true} <- {:remote_limit_pass, check_remote_limit(map)},
|
{_, true} <- {:remote_limit_pass, check_remote_limit(map)},
|
||||||
{:ok, map} <- MRF.filter(map),
|
{:ok, map} <- MRF.filter(map),
|
||||||
{recipients, _, _} = get_recipients(map),
|
{recipients, _, _} = get_recipients(map),
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.DeleteValidator do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
||||||
|
@ -57,7 +58,7 @@ 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_actor_presence()
|
|> validate_delete_actor(:actor)
|
||||||
|> validate_modification_rights()
|
|> validate_modification_rights()
|
||||||
|> validate_object_or_user_presence(allowed_types: @deletable_types)
|
|> validate_object_or_user_presence(allowed_types: @deletable_types)
|
||||||
|> add_deleted_activity_id()
|
|> add_deleted_activity_id()
|
||||||
|
@ -72,4 +73,13 @@ def cast_and_validate(data) do
|
||||||
|> cast_data
|
|> cast_data
|
||||||
|> validate_data
|
|> validate_data
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp validate_delete_actor(cng, field_name) do
|
||||||
|
validate_change(cng, field_name, fn field_name, actor ->
|
||||||
|
case User.get_cached_by_ap_id(actor) do
|
||||||
|
%User{} -> []
|
||||||
|
_ -> [{field_name, "can't find user"}]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,6 +7,7 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidators.UndoValidator do
|
||||||
|
|
||||||
alias Pleroma.Activity
|
alias Pleroma.Activity
|
||||||
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
alias Pleroma.EctoType.ActivityPub.ObjectValidators
|
||||||
|
alias Pleroma.User
|
||||||
|
|
||||||
import Ecto.Changeset
|
import Ecto.Changeset
|
||||||
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
import Pleroma.Web.ActivityPub.ObjectValidators.CommonValidations
|
||||||
|
@ -42,7 +43,7 @@ def validate_data(data_cng) do
|
||||||
data_cng
|
data_cng
|
||||||
|> validate_inclusion(:type, ["Undo"])
|
|> validate_inclusion(:type, ["Undo"])
|
||||||
|> validate_required([:id, :type, :object, :actor, :to, :cc])
|
|> validate_required([:id, :type, :object, :actor, :to, :cc])
|
||||||
|> validate_actor_presence()
|
|> validate_undo_actor(:actor)
|
||||||
|> validate_object_presence()
|
|> validate_object_presence()
|
||||||
|> validate_undo_rights()
|
|> validate_undo_rights()
|
||||||
end
|
end
|
||||||
|
@ -59,4 +60,13 @@ def validate_undo_rights(cng) do
|
||||||
_ -> cng
|
_ -> cng
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp validate_undo_actor(cng, field_name) do
|
||||||
|
validate_change(cng, field_name, fn field_name, actor ->
|
||||||
|
case User.get_cached_by_ap_id(actor) do
|
||||||
|
%User{} -> []
|
||||||
|
_ -> [{field_name, "can't find user"}]
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1621,9 +1621,9 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
|
||||||
follower_count: 9,
|
follower_count: 9,
|
||||||
following_count: 9001,
|
following_count: 9001,
|
||||||
is_locked: true,
|
is_locked: true,
|
||||||
is_confirmed: false,
|
is_confirmed: true,
|
||||||
password_reset_pending: true,
|
password_reset_pending: true,
|
||||||
is_approved: false,
|
is_approved: true,
|
||||||
registration_reason: "ahhhhh",
|
registration_reason: "ahhhhh",
|
||||||
confirmation_token: "qqqq",
|
confirmation_token: "qqqq",
|
||||||
domain_blocks: ["lain.com"],
|
domain_blocks: ["lain.com"],
|
||||||
|
@ -1663,9 +1663,9 @@ test "delete/1 purges a user when they wouldn't be fully deleted" do
|
||||||
follower_count: 0,
|
follower_count: 0,
|
||||||
following_count: 0,
|
following_count: 0,
|
||||||
is_locked: false,
|
is_locked: false,
|
||||||
is_confirmed: false,
|
is_confirmed: true,
|
||||||
password_reset_pending: false,
|
password_reset_pending: false,
|
||||||
is_approved: false,
|
is_approved: true,
|
||||||
registration_reason: nil,
|
registration_reason: nil,
|
||||||
confirmation_token: nil,
|
confirmation_token: nil,
|
||||||
domain_blocks: [],
|
domain_blocks: [],
|
||||||
|
|
Loading…
Reference in a new issue