Skip to content

Commit

Permalink
refactor: improve logging and fix quality issues
Browse files Browse the repository at this point in the history
  • Loading branch information
tecoholic committed Aug 4, 2022
1 parent 9c2e441 commit 1684785
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lti_consumer/lti_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -1211,7 +1211,7 @@ def lti_1p3_access_token(self, request, suffix=''): # pylint: disable=unused-ar
# Runtime import because this can only be run in the LMS/Studio Django
# environments. Importing the views on the top level will cause RuntimeErorr
from lti_consumer.plugin.views import access_token_endpoint # pylint: disable=import-outside-toplevel
return access_token_endpoint(request, usage_id=str(self.location))
return access_token_endpoint(request, usage_id=str(self.location)) # pylint: disable=no-member

@XBlock.handler
def outcome_service_handler(self, request, suffix=''): # pylint: disable=unused-argument
Expand Down
17 changes: 14 additions & 3 deletions lti_consumer/plugin/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def public_keyset_endpoint(request, usage_id=None, lti_config_id=None):
"Error while retrieving keyset for usage_id (%r) or lit_config_id (%s): %s",
usage_id,
lti_config_id,
exc
exc,
exc_info=True
)
raise Http404 from exc

Expand All @@ -148,11 +149,18 @@ def launch_gate_endpoint(request, suffix=None): # pylint: disable=unused-argume
"""
usage_id = request.GET.get('login_hint')
if not usage_id:
log.info('The `login_hint` query param in the request is missing or empty.')
return render(request, 'html/lti_1p3_launch_error.html', status=HTTP_400_BAD_REQUEST)

try:
usage_key = UsageKey.from_string(usage_id)
except InvalidKeyError:
except InvalidKeyError as exc:
log.error(
"The login_hint: %s is not a valid block location. Error: %s",
usage_id,
exc,
exc_info=True
)
return render(request, 'html/lti_1p3_launch_error.html', status=HTTP_404_NOT_FOUND)

try:
Expand All @@ -164,7 +172,8 @@ def launch_gate_endpoint(request, suffix=None): # pylint: disable=unused-argume
raise Http404 from exc

if lti_config.version != LtiConfiguration.LTI_1P3:
return JsonResponse({"error": "invalid_lti_version"}, status=HTTP_404_NOT_FOUND)
log.error("The LTI Version of configuraiont %s is not LTI 1.3", lti_config)
return render(request, 'html/lti_1p3_launch_error.html', status=HTTP_404_NOT_FOUND)

context = {}

Expand Down Expand Up @@ -258,6 +267,7 @@ def launch_gate_endpoint(request, suffix=None): # pylint: disable=unused-argume
"Error preparing LTI 1.3 launch for block %r: %s",
usage_id,
exc,
exc_info=True
)
return render(request, 'html/lti_1p3_launch_error.html', context, status=HTTP_400_BAD_REQUEST)
except AssertionError as exc:
Expand All @@ -266,6 +276,7 @@ def launch_gate_endpoint(request, suffix=None): # pylint: disable=unused-argume
usage_id,
external_user_id,
exc,
exc_info=True
)
return render(request, 'html/lti_1p3_permission_error.html', context, status=HTTP_403_FORBIDDEN)

Expand Down
4 changes: 2 additions & 2 deletions lti_consumer/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
"""
import logging

from django.db.models.signals import post_save, pre_save
from django.db.models.signals import post_save
from django.dispatch import receiver

from lti_consumer.models import LtiAgsScore, LtiConfiguration
from lti_consumer.models import LtiAgsScore
from lti_consumer.plugin import compat


Expand Down

0 comments on commit 1684785

Please sign in to comment.