From 3309078242ce4618baf5b1783e74d3725df95a0b Mon Sep 17 00:00:00 2001 From: Jeremy Bowman Date: Mon, 6 Apr 2020 19:10:19 -0400 Subject: [PATCH] Prepare for django-oauth-toolkit 1.3.2 upgrade (#23637) Prepare to upgrade to django-oauth-toolkit (module name oauth2_provider) 1.3.2 concurrently with the Django 2.2 upgrade (versions after 1.1.3 dropped support for Django 1.11). Key points: * We can stop using a commit hash since versions 1.3.0 through 1.3.2 have been released since that commit. * The validator in oauth_dispatch migration 0002 has been removed from DOT, but the whole table was removed in migration 0004 anyway. Newer DOT versions moved where redirect URI validation happens so it's no longer needed here. * DOT 1.3.0 squashed its original 6 migrations and immediately deleted them. This required some changes in oauth_dispatch migrations 0006 and 0007 to deal with either numbering system. When deploying to stage and production, we'll need to delete the history for oauth2_provider migrations 0002-0006 first (the new squashed 0001 migration has the same name as the original 0001). The deployment with DOT 1.3.2 will add a new 0002 migration which should then apply cleanly on the existing database state. Should resolve https://openedx.atlassian.net/browse/BOM-1456 . --- ...plication_scopedapplicationorganization.py | 3 +-- .../0006_drop_application_id_constraints.py | 21 ++++++++++++------- ...0007_restore_application_id_constraints.py | 8 ++++++- requirements/edx/django20.txt | 3 +-- requirements/edx/django21.txt | 2 +- requirements/edx/django22.txt | 3 +-- 6 files changed, 25 insertions(+), 15 deletions(-) diff --git a/openedx/core/djangoapps/oauth_dispatch/migrations/0002_scopedapplication_scopedapplicationorganization.py b/openedx/core/djangoapps/oauth_dispatch/migrations/0002_scopedapplication_scopedapplicationorganization.py index eae9bbf535..3a785ffe24 100644 --- a/openedx/core/djangoapps/oauth_dispatch/migrations/0002_scopedapplication_scopedapplicationorganization.py +++ b/openedx/core/djangoapps/oauth_dispatch/migrations/0002_scopedapplication_scopedapplicationorganization.py @@ -5,7 +5,6 @@ import django.db.models.deletion import django_mysql.models import oauth2_provider.generators -import oauth2_provider.validators from django.conf import settings from django.db import migrations, models @@ -23,7 +22,7 @@ class Migration(migrations.Migration): name='ScopedApplication', fields=[ ('client_id', models.CharField(db_index=True, default=oauth2_provider.generators.generate_client_id, max_length=100, unique=True)), - ('redirect_uris', models.TextField(blank=True, help_text='Allowed URIs list, space separated', validators=[oauth2_provider.validators.validate_uris])), + ('redirect_uris', models.TextField(blank=True, help_text='Allowed URIs list, space separated')), ('client_type', models.CharField(choices=[('confidential', 'Confidential'), ('public', 'Public')], max_length=32)), ('authorization_grant_type', models.CharField(choices=[('authorization-code', 'Authorization code'), ('implicit', 'Implicit'), ('password', 'Resource owner password-based'), ('client-credentials', 'Client credentials')], max_length=32)), ('client_secret', models.CharField(blank=True, db_index=True, default=oauth2_provider.generators.generate_client_secret, max_length=255)), diff --git a/openedx/core/djangoapps/oauth_dispatch/migrations/0006_drop_application_id_constraints.py b/openedx/core/djangoapps/oauth_dispatch/migrations/0006_drop_application_id_constraints.py index 02d0b9bf88..2228f97023 100644 --- a/openedx/core/djangoapps/oauth_dispatch/migrations/0006_drop_application_id_constraints.py +++ b/openedx/core/djangoapps/oauth_dispatch/migrations/0006_drop_application_id_constraints.py @@ -2,20 +2,27 @@ # Generated by Django 1.11.14 on 2018-07-23 14:58 +import django import django.db.models.deletion from django.conf import settings from django.db import migrations, models +DEPENDENCIES = [ + ('oauth_dispatch', '0005_applicationaccess_type'), +] +RUN_BEFORE = [] +if django.VERSION >= (2, 0): + # Using django-oauth-toolkit 1.3.2+, which squashed and deleted the original 6 migrations + DEPENDENCIES.append(('oauth2_provider', '0001_initial')) +else: + # Using django-oauth-toolkit 1.1.3 or earlier, before the migrations squashing + RUN_BEFORE.append(('oauth2_provider', '0005_auto_20170514_1141')) + class Migration(migrations.Migration): - dependencies = [ - ('oauth_dispatch', '0005_applicationaccess_type'), - ] - - run_before = [ - ('oauth2_provider', '0005_auto_20170514_1141'), - ] + dependencies = DEPENDENCIES + run_before = RUN_BEFORE operations = [ migrations.AlterField( diff --git a/openedx/core/djangoapps/oauth_dispatch/migrations/0007_restore_application_id_constraints.py b/openedx/core/djangoapps/oauth_dispatch/migrations/0007_restore_application_id_constraints.py index 52e7c24ec6..dc52ecc8ad 100644 --- a/openedx/core/djangoapps/oauth_dispatch/migrations/0007_restore_application_id_constraints.py +++ b/openedx/core/djangoapps/oauth_dispatch/migrations/0007_restore_application_id_constraints.py @@ -2,16 +2,22 @@ # Generated by Django 1.11.14 on 2018-07-23 15:12 +import django import django.db.models.deletion from django.conf import settings from django.db import migrations, models +if django.VERSION >= (2, 0): + dot_migration = '0001_initial' +else: + dot_migration = '0006_auto_20171214_2232' + class Migration(migrations.Migration): dependencies = [ ('oauth_dispatch', '0006_drop_application_id_constraints'), - ('oauth2_provider', '0006_auto_20171214_2232'), + ('oauth2_provider', dot_migration), ] operations = [ diff --git a/requirements/edx/django20.txt b/requirements/edx/django20.txt index 6e7e72793f..15e047d8ae 100644 --- a/requirements/edx/django20.txt +++ b/requirements/edx/django20.txt @@ -1,3 +1,2 @@ Django>=2.0,<2.1 -git+https://github.com/jazzband/django-oauth-toolkit.git@bf1525e85a06929016b1fe35d863e62e58124a2f#egg=oauth2_provider - +django-oauth-toolkit==1.3.2 diff --git a/requirements/edx/django21.txt b/requirements/edx/django21.txt index 0928dd3f16..f6121d0691 100644 --- a/requirements/edx/django21.txt +++ b/requirements/edx/django21.txt @@ -1,3 +1,3 @@ Django>=2.1,<2.2 -git+https://github.com/jazzband/django-oauth-toolkit.git@bf1525e85a06929016b1fe35d863e62e58124a2f#egg=oauth2_provider +django-oauth-toolkit==1.3.2 diff --git a/requirements/edx/django22.txt b/requirements/edx/django22.txt index 01de5d0b96..4cd4c00f58 100644 --- a/requirements/edx/django22.txt +++ b/requirements/edx/django22.txt @@ -1,3 +1,2 @@ Django>=2.2,<3.0 -git+https://github.com/jazzband/django-oauth-toolkit.git@bf1525e85a06929016b1fe35d863e62e58124a2f#egg=oauth2_provider - +django-oauth-toolkit==1.3.2