diff options
author | rinpatch <rinpatch@sdf.org> | 2020-04-29 14:26:31 +0300 |
---|---|---|
committer | rinpatch <rinpatch@sdf.org> | 2020-05-02 19:05:13 +0300 |
commit | e55876409b523d81bc19db876bc90f29ba80a47c (patch) | |
tree | b85e0ab309c870f2b5bbb6d3bd94b0dff3de3856 /priv | |
parent | e186d9941d4cf4708186681fcea60b23919c46ed (diff) | |
download | pleroma-e55876409b523d81bc19db876bc90f29ba80a47c.tar.gz pleroma-e55876409b523d81bc19db876bc90f29ba80a47c.zip |
Deactivate local users on deletion instead of deleting the record
Prevents the possibility of re-registration, which allowed to read
DMs of the deleted account.
Also includes a migration that tries to find any already deleted
accounts and insert skeletons for them.
Closes pleroma/pleroma#1687
Diffstat (limited to 'priv')
-rw-r--r-- | priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs b/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs new file mode 100644 index 000000000..11d9a70ba --- /dev/null +++ b/priv/repo/migrations/20200428221338_insert_skeletons_for_deleted_users.exs @@ -0,0 +1,45 @@ +defmodule Pleroma.Repo.Migrations.InsertSkeletonsForDeletedUsers do + use Ecto.Migration + + alias Pleroma.User + alias Pleroma.Repo + + import Ecto.Query + + def change do + Application.ensure_all_started(:flake_id) + + local_ap_id = + User.Query.build(%{local: true}) + |> select([u], u.ap_id) + |> limit(1) + |> Repo.one() + + unless local_ap_id == nil do + # Hack to get instance base url because getting it from Phoenix + # would require starting the whole application + instance_uri = + local_ap_id + |> URI.parse() + |> Map.put(:query, nil) + |> Map.put(:path, nil) + |> URI.to_string() + + {:ok, %{rows: ap_ids}} = + Ecto.Adapters.SQL.query( + Repo, + "select distinct unnest(nonexistent_locals.recipients) from activities, lateral (select array_agg(recipient) as recipients from unnest(activities.recipients) as recipient where recipient similar to '#{ + instance_uri + }/users/[A-Za-z0-9]*' and not(recipient in (select ap_id from users where local = true))) nonexistent_locals;", + [], + timeout: :infinity + ) + + ap_ids + |> Enum.each(fn [ap_id] -> + Ecto.Changeset.change(%User{}, deactivated: true, ap_id: ap_id) + |> Repo.insert() + end) + end + end +end |