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'), 'level': os.getenv('DJANGO_LOG_LEVEL', 'INFO'),
'propagate': False, '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 import View
from django.views.decorators.csrf import csrf_exempt from django.views.decorators.csrf import csrf_exempt
import requests import requests
import logging
from bookwyrm import activitypub, models from bookwyrm import activitypub, models
from bookwyrm.tasks import app from bookwyrm.tasks import app
from bookwyrm.signatures import Signature from bookwyrm.signatures import Signature
from bookwyrm.utils import regex from bookwyrm.utils import regex
logger = logging.getLogger(__name__)
@method_decorator(csrf_exempt, name="dispatch") @method_decorator(csrf_exempt, name="dispatch")
# pylint: disable=no-self-use # pylint: disable=no-self-use
@ -71,6 +73,7 @@ def raise_is_blocked_user_agent(request):
return return
url = url.group() url = url.group()
if models.FederatedServer.is_blocked(url): if models.FederatedServer.is_blocked(url):
logger.debug(f"{url} is blocked, denying request based on user agent")
raise PermissionDenied() 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""" """get the sender out of activity json and check if it's blocked"""
actor = activity_json.get("actor") 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: if not actor:
# well I guess it's not even a valid activity so who knows # well I guess it's not even a valid activity so who knows
return 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): if models.FederatedServer.is_blocked(actor):
logger.debug(f"{actor} is blocked, denying request based on actor")
raise PermissionDenied() raise PermissionDenied()