Skip to content

Commit

Permalink
do not show user profile if deactivated
Browse files Browse the repository at this point in the history
  • Loading branch information
Her Email authored and alphatownsman committed Nov 24, 2023
1 parent 2059f45 commit 6e48bb9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
3 changes: 3 additions & 0 deletions boofilsic/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
3 changes: 3 additions & 0 deletions common/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 9 additions & 1 deletion users/models/user.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import hashlib
import re
from datetime import timedelta
from functools import cached_property
from typing import TYPE_CHECKING, ClassVar

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 6e48bb9

Please sign in to comment.