return (relatively) correct nodeinfo

This commit is contained in:
Her Email 2023-12-03 15:30:21 -05:00 committed by Henri Dickson
parent 240e782bfc
commit ec2e27dfe3
5 changed files with 28 additions and 22 deletions

View file

@ -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"]},

@ -1 +1 @@
Subproject commit 53d05334a23df974799ba8c19a388a28376d55b1
Subproject commit 893c00f06c710dcfeb53d64704b694a7dfb3f810

View file

@ -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

View file

@ -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"):
"""

View file

@ -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