refactor Move for more redundancy
As outlined in #3354, a use `Move` fails if the user is moving from a BookWyrm server to another BookWrym server. This is because: 1. the original code did not announce changes to alsoKnownAs; 2. the original code always checked the locally saved profile rather than refetching the remote data; This commit fixes both these problems by forcing `MoveUser` to always perform a "refresh" of the local data from the remote, and by saving the user with broadcast=True when updating alsoKnownAs ids.
This commit is contained in:
parent
193aeff4d2
commit
6684d60526
6 changed files with 222 additions and 4 deletions
|
@ -60,7 +60,7 @@ def is_bookwyrm_request(request):
|
|||
return True
|
||||
|
||||
|
||||
def handle_remote_webfinger(query, unknown_only=False):
|
||||
def handle_remote_webfinger(query, unknown_only=False, refresh=False):
|
||||
"""webfingerin' other servers"""
|
||||
user = None
|
||||
|
||||
|
@ -75,6 +75,11 @@ def handle_remote_webfinger(query, unknown_only=False):
|
|||
return None
|
||||
|
||||
try:
|
||||
|
||||
if refresh:
|
||||
# Always fetch the remote info - don't even bother checking the DB
|
||||
raise models.User.DoesNotExist("remote_only is set to True")
|
||||
|
||||
user = models.User.objects.get(username__iexact=query)
|
||||
|
||||
if unknown_only:
|
||||
|
@ -92,7 +97,7 @@ def handle_remote_webfinger(query, unknown_only=False):
|
|||
if link.get("rel") == "self":
|
||||
try:
|
||||
user = activitypub.resolve_remote_id(
|
||||
link["href"], model=models.User
|
||||
link["href"], model=models.User, refresh=refresh
|
||||
)
|
||||
except (KeyError, activitypub.ActivitySerializerError):
|
||||
return None
|
||||
|
|
|
@ -32,7 +32,7 @@ class MoveUser(View):
|
|||
|
||||
if form.is_valid() and user.check_password(form.cleaned_data["password"]):
|
||||
username = form.cleaned_data["target"]
|
||||
target = handle_remote_webfinger(username)
|
||||
target = handle_remote_webfinger(username, refresh=True)
|
||||
|
||||
try:
|
||||
models.MoveUser.objects.create(
|
||||
|
@ -81,6 +81,7 @@ class AliasUser(View):
|
|||
return TemplateResponse(request, "preferences/alias_user.html", data)
|
||||
|
||||
user.also_known_as.add(remote_user.id)
|
||||
user.save(broadcast=True) # broadcast the alias
|
||||
|
||||
return redirect("prefs-alias")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue