From 412bb073466e75396a2f8b9e5094b8aa6390f0ca Mon Sep 17 00:00:00 2001 From: Andrey Canon Date: Thu, 12 Nov 2020 10:21:55 -0500 Subject: [PATCH] Comment log in migration file Making the oauth2 tokens with grant client_credentials live for one year refactor: deleted unnecesary comments refactor: replaced comments above of exception section refactor: deleted unnecesary import comment --- .../courseware/migrations/0008_move_idde_to_edx_when.py | 7 ++++--- .../djangoapps/oauth_dispatch/dot_overrides/validators.py | 8 +++++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py b/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py index 632409025cf..40de31760ac 100644 --- a/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py +++ b/lms/djangoapps/courseware/migrations/0008_move_idde_to_edx_when.py @@ -2,7 +2,6 @@ import json -import logging from django.db import migrations @@ -12,7 +11,6 @@ def move_overrides_to_edx_when(apps, schema_editor): from edx_when import api date_field = Date() StudentFieldOverride = apps.get_model('courseware', 'StudentFieldOverride') - log = logging.getLogger(__name__) for override in StudentFieldOverride.objects.filter(field='due'): try: abs_date = date_field.from_json(json.loads(override.value)) @@ -23,7 +21,10 @@ def move_overrides_to_edx_when(apps, schema_editor): abs_date, user=override.student) except Exception: # pylint: disable=broad-except - log.exception("migrating %d %r: %r", override.id, override.location, override.value) + # The following line is commented since these logs only add noise to output console + # Thi migration only works with IDDE + # log.exception("migrating %d %r: %r", override.id, override.location, override.value) + pass class Migration(migrations.Migration): diff --git a/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py b/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py index 0b2ad35b2f4..673fb5cdb67 100644 --- a/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py +++ b/openedx/core/djangoapps/oauth_dispatch/dot_overrides/validators.py @@ -5,6 +5,7 @@ from datetime import datetime, timedelta +from django.conf import settings from django.contrib.auth import authenticate, get_user_model from django.db.models.signals import pre_save from django.dispatch import receiver @@ -81,7 +82,12 @@ def save_bearer_token(self, token, request, *args, **kwargs): # associate access tokens issued with the client_credentials grant to users. request.user = request.client.user - super().save_bearer_token(token, request, *args, **kwargs) + # ednx: JU-10. Tokens for the machine-to-machine comunication should be longer lived + # for backwards compatibility with eox-core and other plugin APIs. + # Without this modification the BearerToken class will set this to 3600 + request.expires_in = getattr(settings, 'CLIENT_CREDENTIALS_ACCESS_TOKEN_EXPIRE_SECONDS', 31557600) + + super(EdxOAuth2Validator, self).save_bearer_token(token, request, *args, **kwargs) is_restricted_client = self._update_token_expiry_if_restricted_client(token, request.client) if not is_restricted_client: