Skip to content
This repository has been archived by the owner on Feb 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2144 from edx-solutions/release-candidate
Browse files Browse the repository at this point in the history
[v1.62.2] Review sync up of master branch with release-candidate
  • Loading branch information
ahmed-zubair12 authored Apr 21, 2021
2 parents 087d669 + eed4cc2 commit d091104
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -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`);
""",
)
]
14 changes: 10 additions & 4 deletions common/djangoapps/third_party_auth/saml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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):
Expand Down
6 changes: 3 additions & 3 deletions lms/djangoapps/instructor_task/tasks_helper/grades.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit d091104

Please sign in to comment.