Add bookwyrm-specific logging

This commit is contained in:
Joel Bradshaw 2022-01-10 06:45:14 +00:00 committed by Joel Bradshaw
parent af3c84cd87
commit 83851c2933
2 changed files with 14 additions and 5 deletions

View file

@ -124,6 +124,10 @@ LOGGING = {
'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': False,
},
'bookwyrm': {
'handlers': ['console'],
'level': os.getenv('LOG_LEVEL', 'DEBUG' if DEBUG else 'INFO').upper(),
}
},
}

View file

@ -10,12 +10,14 @@ from django.utils.decorators import method_decorator
from django.views import View
from django.views.decorators.csrf import csrf_exempt
import requests
import logging
from bookwyrm import activitypub, models
from bookwyrm.tasks import app
from bookwyrm.signatures import Signature
from bookwyrm.utils import regex
logger = logging.getLogger(__name__)
@method_decorator(csrf_exempt, name="dispatch")
# pylint: disable=no-self-use
@ -71,6 +73,7 @@ def raise_is_blocked_user_agent(request):
return
url = url.group()
if models.FederatedServer.is_blocked(url):
logger.debug(f"{url} is blocked, denying request based on user agent")
raise PermissionDenied()
@ -78,16 +81,18 @@ def raise_is_blocked_activity(activity_json):
"""get the sender out of activity json and check if it's blocked"""
actor = activity_json.get("actor")
# check if the user is banned/deleted
existing = models.User.find_existing_by_remote_id(actor)
if existing and existing.deleted:
raise PermissionDenied()
if not actor:
# well I guess it's not even a valid activity so who knows
return
# check if the user is banned/deleted
existing = models.User.find_existing_by_remote_id(actor)
if existing and existing.deleted:
logger.debug(f"{actor} is banned/deleted, denying request based on actor")
raise PermissionDenied()
if models.FederatedServer.is_blocked(actor):
logger.debug(f"{actor} is blocked, denying request based on actor")
raise PermissionDenied()