fix profile uri (#443)

This commit is contained in:
Henri Dickson 2023-12-23 00:57:00 -05:00 committed by GitHub
parent 789e3848cb
commit aaffc8f3cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 1 deletions

View file

@ -106,7 +106,7 @@ class Takahe:
logger.info(f"Creating takahe identity {u}@{domain}")
identity = Identity.objects.create(
actor_uri=f"https://{domain.uri_domain}/@{u.username}@{domain.domain}/",
profile_uri=u.url,
profile_uri=u.absolute_url,
username=u.username,
domain=domain,
name=u.username,

View file

@ -0,0 +1,30 @@
from django.conf import settings
from django.core.management.base import BaseCommand
from loguru import logger
from tqdm import tqdm
from takahe.utils import Takahe
from users.models import Preference, User
class Command(BaseCommand):
help = "Manage import tasks"
def add_arguments(self, parser):
parser.add_argument(
"--reset",
action="store_true",
)
def handle(self, *args, **options):
count = 0
for user in tqdm(User.objects.all()):
if (
user.identity
and not user.identity.takahe_identity.profile_uri.startswith("http")
):
user.identity.takahe_identity.profile_uri = user.absolute_url
user.identity.takahe_identity.save(update_fields=["profile_uri"])
Takahe.update_state(user.identity.takahe_identity, "edited")
count += 1
self.stdout.write(self.style.SUCCESS(f"{count} user(s) fixed"))

View file

@ -202,6 +202,10 @@ class User(AbstractUser):
def url(self):
return reverse("journal:user_profile", args=[self.handler])
@property
def absolute_url(self):
return settings.SITE_INFO["site_url"] + self.url
def __str__(self):
return f'{self.pk}:{self.username or ""}:{self.mastodon_acct}'