aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorrinpatch <rinpatch@sdf.org>2020-07-01 13:51:23 +0000
committerrinpatch <rinpatch@sdf.org>2020-07-01 13:51:23 +0000
commitfa7a0be2252fc52202cf84b6549e2ff2e731c4ff (patch)
treeeb0d51b366c2785e89bd2ae016fda2c7bd45c478 /lib
parentd889c9ca709a085031ab2b7ebfe4755c7471991d (diff)
parentfedfe8f7d6f78d77e9cbaf70fa8a9e8df38463f7 (diff)
downloadpleroma-fa7a0be2252fc52202cf84b6549e2ff2e731c4ff.tar.gz
Merge branch '1716-handle-nickname-clashes' into 'develop'
ActivityPub: Handle clashing nicknames for the same ap id Closes #1716 See merge request pleroma/pleroma!2712
Diffstat (limited to 'lib')
-rw-r--r--lib/pleroma/web/activity_pub/activity_pub.ex12
1 files changed, 12 insertions, 0 deletions
diff --git a/lib/pleroma/web/activity_pub/activity_pub.ex b/lib/pleroma/web/activity_pub/activity_pub.ex
index 05bd824f5..94117202c 100644
--- a/lib/pleroma/web/activity_pub/activity_pub.ex
+++ b/lib/pleroma/web/activity_pub/activity_pub.ex
@@ -1371,6 +1371,16 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
end
end
+ def maybe_handle_clashing_nickname(nickname) do
+ with %User{} = old_user <- User.get_by_nickname(nickname) do
+ Logger.info("Found an old user for #{nickname}, ap id is #{old_user.ap_id}, renaming.")
+
+ old_user
+ |> User.remote_user_changeset(%{nickname: "#{old_user.id}.#{old_user.nickname}"})
+ |> User.update_and_set_cache()
+ end
+ end
+
def make_user_from_ap_id(ap_id) do
user = User.get_cached_by_ap_id(ap_id)
@@ -1383,6 +1393,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPub do
|> User.remote_user_changeset(data)
|> User.update_and_set_cache()
else
+ maybe_handle_clashing_nickname(data[:nickname])
+
data
|> User.remote_user_changeset()
|> Repo.insert()