diff --git a/boofilsic/settings.py b/boofilsic/settings.py index e02fe830..97d081fc 100644 --- a/boofilsic/settings.py +++ b/boofilsic/settings.py @@ -516,6 +516,9 @@ "POST", # "PUT", ) + +DEACTIVATE_AFTER_UNREACHABLE_DAYS = 120 + DEFAULT_RELAY_SERVER = "https://relay.neodb.net/actor" SENTRY_DSN = env("NEODB_SENTRY_DSN") diff --git a/common/utils.py b/common/utils.py index 51564195..ef51b34f 100644 --- a/common/utils.py +++ b/common/utils.py @@ -37,6 +37,9 @@ def wrapper(request, user_name, *args, **kwargs): target = APIdentity.get_by_handler(user_name) except APIdentity.DoesNotExist: return render_user_not_found(request) + target_user = target.user + if target_user and not target_user.is_active: + return render_user_not_found(request) if not target.is_visible_to_user(request.user): return render_user_blocked(request) request.target_identity = target diff --git a/users/models/user.py b/users/models/user.py index 21e9f858..899f5cf0 100644 --- a/users/models/user.py +++ b/users/models/user.py @@ -1,5 +1,6 @@ import hashlib import re +from datetime import timedelta from functools import cached_property from typing import TYPE_CHECKING, ClassVar @@ -275,7 +276,14 @@ def refresh_mastodon_data(self): self.mastodon_last_refresh = timezone.now() if not webfinger(self.mastodon_site, self.mastodon_username): logger.error(f"Unable to fetch web finger for {self}") - self.save(update_fields=["mastodon_last_refresh"]) + if ( + timezone.now() - self.mastodon_last_reachable + > timedelta(days=settings.DEACTIVATE_AFTER_UNREACHABLE_DAYS) + and not self.email + ): + logger.warning(f"Deactivate {self} bc unable to reach for too long") + self.is_active = False + self.save(update_fields=["mastodon_last_refresh", "is_active"]) return False self.mastodon_last_reachable = timezone.now() code, mastodon_account = verify_account(self.mastodon_site, self.mastodon_token)