From 4081e087c6124e311d2e124e46728b7583908644 Mon Sep 17 00:00:00 2001 From: ahmed-zubair12 <74174850+ahmed-zubair12@users.noreply.github.com> Date: Fri, 9 Apr 2021 13:02:53 +0500 Subject: [PATCH 1/4] MCKIN-24991 - Fix for reports with no responses (#2140) --- lms/djangoapps/instructor_task/tasks_helper/grades.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lms/djangoapps/instructor_task/tasks_helper/grades.py b/lms/djangoapps/instructor_task/tasks_helper/grades.py index 5f4da33c58f6..34a3155965c4 100644 --- a/lms/djangoapps/instructor_task/tasks_helper/grades.py +++ b/lms/djangoapps/instructor_task/tasks_helper/grades.py @@ -959,9 +959,6 @@ def _build_student_data( if max_count <= 0: break - if not student_data: - break - # Keep the keys in a useful order, starting with username, title and location, # then the columns returned by the xblock report generator in sorted order and # finally end with the more machine friendly block_key and state. @@ -972,6 +969,9 @@ def _build_student_data( ) yield student_data, student_data_keys_list, batch_no + + if not student_data: + break batch_no += 1 @classmethod From 5b7e467cde37bc35cd61ad14449a6ffe8b0f4522 Mon Sep 17 00:00:00 2001 From: Mudassir Hafeez Date: Mon, 12 Apr 2021 17:54:42 +0500 Subject: [PATCH 2/4] MEI-6830 handled other attributes that store except list (#2142) --- common/djangoapps/third_party_auth/saml.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/common/djangoapps/third_party_auth/saml.py b/common/djangoapps/third_party_auth/saml.py index 6a06a86d4619..1856e2fddb0d 100644 --- a/common/djangoapps/third_party_auth/saml.py +++ b/common/djangoapps/third_party_auth/saml.py @@ -209,10 +209,16 @@ def get_user_details(self, attributes): """ details = super(EdXSAMLIdentityProvider, self).get_user_details(attributes) extra_field_definitions = self.conf.get('extra_field_definitions', []) - details.update({ - field['name']: attributes[field['urn']][0] if field['urn'] in attributes else None - for field in extra_field_definitions - }) + extra_fields = {} + for field in extra_field_definitions: + value = attributes[field['urn']] if field['urn'] in attributes else None + if isinstance(value, list): + if len(value): + value = value[0] + else: + value = None + extra_fields[field['name']] = value + details.update(extra_fields) return details def get_attr(self, attributes, conf_key, default_attribute): From 7888cef45e5e8f5d1352e683944bb0c9edcef694 Mon Sep 17 00:00:00 2001 From: ahmed-zubair12 Date: Tue, 13 Apr 2021 11:48:54 +0500 Subject: [PATCH 3/4] pylint violations fix for commit in release v1.62.2 --- common/djangoapps/third_party_auth/saml.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/djangoapps/third_party_auth/saml.py b/common/djangoapps/third_party_auth/saml.py index 1856e2fddb0d..45bc1697bdef 100644 --- a/common/djangoapps/third_party_auth/saml.py +++ b/common/djangoapps/third_party_auth/saml.py @@ -213,7 +213,7 @@ def get_user_details(self, attributes): for field in extra_field_definitions: value = attributes[field['urn']] if field['urn'] in attributes else None if isinstance(value, list): - if len(value): + if value: value = value[0] else: value = None From 542785760fbdff1552b1babd751f5f9e4f3bd90e Mon Sep 17 00:00:00 2001 From: ahmed-zubair12 <74174850+ahmed-zubair12@users.noreply.github.com> Date: Thu, 1 Apr 2021 11:54:41 +0500 Subject: [PATCH 4/4] MCKIN-32075 - Migration to drop foreign key of oauth2 tables with auth_user (#2136) * MCKIN-32075 - Migration to alter foreign key on delete behaviour of oauth2 tables to CASCADE * MCKIN-32075 - Fixed comments * MCKIN-32075 - Including missing table, dropping foreign key instead of altering to CASCADE --- ...gn_keys_from_edx_django_oauth2_provider.py | 69 +++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 common/djangoapps/database_fixups/migrations/0003_remove_foreign_keys_from_edx_django_oauth2_provider.py diff --git a/common/djangoapps/database_fixups/migrations/0003_remove_foreign_keys_from_edx_django_oauth2_provider.py b/common/djangoapps/database_fixups/migrations/0003_remove_foreign_keys_from_edx_django_oauth2_provider.py new file mode 100644 index 000000000000..d6378a3b3bf4 --- /dev/null +++ b/common/djangoapps/database_fixups/migrations/0003_remove_foreign_keys_from_edx_django_oauth2_provider.py @@ -0,0 +1,69 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations + +""" +The `edx-django-oauth2-provider` has been deprecated in favor of `django-oauth-toolkit`. +Its tables however persist in database. They have foreign key dependancy with `auth_user.id`. Django does +not resolves this constratint and we are unable to remove users. + +This migration drops the foreign key relation between the 4 tables created by `edx-django-oauth2-provider` +and `auth_user`. +""" + + +class Migration(migrations.Migration): + + dependencies = [ + ('database_fixups', '0002_remove_foreign_keys_from_progress_extensions'), + ] + + operations = [ + migrations.RunSQL( + """ + -- Drop a procedure if it already exists - safety check. + DROP PROCEDURE IF EXISTS drop_foreign_key_from_oauth2_table; + + -- We are dropping constraints from 4 tables, so we create a temporary procedure to avoid code repetition. + CREATE PROCEDURE drop_foreign_key_from_oauth2_table(given_table VARCHAR(64)) + BEGIN + -- Getting the foreign key that refernces to auth_user table + SET @auth_foreign_key = ( + SELECT CONSTRAINT_NAME FROM INFORMATION_SCHEMA.KEY_COLUMN_USAGE + WHERE REFERENCED_TABLE_SCHEMA='edxapp' + AND REFERENCED_TABLE_NAME='auth_user' + AND TABLE_NAME=given_table + ); + + IF @auth_foreign_key IS NOT NULL THEN + -- DROP the existing foreign key. + SET @statement = CONCAT('ALTER TABLE ', given_table, ' DROP FOREIGN KEY ', @auth_foreign_key); + PREPARE stmt FROM @statement; + EXECUTE stmt; + DEALLOCATE PREPARE stmt; + ELSE + -- Raise custom error for having clearer logs in case of a failure. + SET @error_message = CONCAT('Cannot find foreign key in ', given_table, ' table.'); + SIGNAL SQLSTATE '45000' SET MESSAGE_TEXT = @error_message; + END IF; + + END; + + -- Call temporary procedure on relevant tables. + CALL drop_foreign_key_from_oauth2_table('oauth2_client'); + CALL drop_foreign_key_from_oauth2_table('oauth2_grant'); + CALL drop_foreign_key_from_oauth2_table('oauth2_accesstoken'); + CALL drop_foreign_key_from_oauth2_table('oauth2_refreshtoken'); + + -- Clean up. + DROP PROCEDURE IF EXISTS drop_foreign_key_from_oauth2_table; + """, + reverse_sql=""" + ALTER TABLE `oauth2_client` ADD FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); + ALTER TABLE `oauth2_grant` ADD FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); + ALTER TABLE `oauth2_accesstoken` ADD FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); + ALTER TABLE `oauth2_refreshtoken` ADD FOREIGN KEY (`user_id`) REFERENCES `auth_user` (`id`); + """, + ) + ]