diff --git a/common/views.py b/common/views.py index ebbc5add..1825307a 100644 --- a/common/views.py +++ b/common/views.py @@ -41,18 +41,11 @@ def nodeinfo2(request): # TODO filter local with SQL function in https://wiki.postgresql.org/wiki/Count_estimate with connection.cursor() as cursor: cursor.execute( - "SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = 'journal_shelfmember';" + "SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = 'journal_shelflogentry';" ) row = cursor.fetchone() if row: usage["localPosts"] = row[0] - with connection.cursor() as cursor: - cursor.execute( - "SELECT n_live_tup FROM pg_stat_all_tables WHERE relname = 'journal_comment';" - ) - row = cursor.fetchone() - if row: - usage["localComments"] = row[0] return JsonResponse( { "version": "2.0", @@ -63,7 +56,7 @@ def nodeinfo2(request): "homepage": "https://neodb.net/", }, "protocols": ["activitypub", "neodb"], - "openRegistrations": False, # settings.SITE_INFO["open_registrations"], + "openRegistrations": not settings.INVITE_ONLY, "services": {"outbound": [], "inbound": []}, "usage": usage, "metadata": {"nodeName": settings.SITE_INFO["site_name"]}, diff --git a/neodb-takahe b/neodb-takahe index 53d05334..893c00f0 160000 --- a/neodb-takahe +++ b/neodb-takahe @@ -1 +1 @@ -Subproject commit 53d05334a23df974799ba8c19a388a28376d55b1 +Subproject commit 893c00f06c710dcfeb53d64704b694a7dfb3f810 diff --git a/takahe/models.py b/takahe/models.py index 212caef0..6cd6f02d 100644 --- a/takahe/models.py +++ b/takahe/models.py @@ -1065,16 +1065,17 @@ class Post(models.Model): ) post.object_uri = post.urls.object_uri post.url = post.absolute_object_uri() - post.mentions.set(mentions) - post.emojis.set(emojis) - if published and published < timezone.now(): - post.published = published - if ( - timezone.now() - published - > datetime.timedelta(days=settings.FANOUT_LIMIT_DAYS) - and _migration_mode - ): - post.state = "fanned_out" # add post quietly if it's old + if _migration_mode: + post.state = "fanned_out" + else: + post.mentions.set(mentions) + post.emojis.set(emojis) + if published and published < timezone.now(): + post.published = published + if timezone.now() - published > datetime.timedelta( + days=settings.FANOUT_LIMIT_DAYS + ): + post.state = "fanned_out" # add post quietly if it's old # if attachments:# FIXME # post.attachments.set(attachments) # if question: # FIXME @@ -1087,6 +1088,7 @@ class Post(models.Model): if reply_to: reply_to.calculate_stats() if post.state == "fanned_out" and not _migration_mode: + # add post to auther's timeline directly if it's old post.add_to_timeline(author) return post diff --git a/takahe/utils.py b/takahe/utils.py index 96d6e7d2..bd32b264 100644 --- a/takahe/utils.py +++ b/takahe/utils.py @@ -61,6 +61,16 @@ class Takahe: if domain and domain.nodeinfo: return domain.nodeinfo.get("metadata", {}).get("nodeName") + @staticmethod + def sync_password(u: "NeoUser"): + user = User.objects.filter(pk=u.pk).first() + if not user: + raise ValueError(f"Cannot find takahe user {u}") + elif user.password != u.password: + logger.info(f"Updating takahe user {u} password") + user.password = u.password + user.save() + @staticmethod def init_identity_for_local_user(u: "NeoUser"): """ diff --git a/takahe/views.py b/takahe/views.py index bc1044bf..3d07909f 100644 --- a/takahe/views.py +++ b/takahe/views.py @@ -9,14 +9,15 @@ from django.utils.http import http_date from loguru import logger from .models import TakaheSession +from .utils import Takahe _TAKAHE_SESSION_COOKIE_NAME = "sessionid" @login_required -def auth_login(request: HttpRequest): +def auth_login(request): """Redirect to the login page if not yet, otherwise sync login info to takahe session""" - + Takahe.sync_password(request.user) # if SESSION_ENGINE = "django.contrib.sessions.backends.signed_cookies" in Takahe session = SessionStore(session_key=request.COOKIES.get(_TAKAHE_SESSION_COOKIE_NAME)) session._session_cache = request.session._session # type: ignore