diff --git a/common/djangoapps/student/management/commands/bulk_change_enrollment.py b/common/djangoapps/student/management/commands/bulk_change_enrollment.py index 0c95dd8bca..a1a5c4de5b 100644 --- a/common/djangoapps/student/management/commands/bulk_change_enrollment.py +++ b/common/djangoapps/student/management/commands/bulk_change_enrollment.py @@ -36,7 +36,7 @@ class Command(BaseCommand): """ def add_arguments(self, parser): - group = parser.add_mutually_exclusive_group() + group = parser.add_mutually_exclusive_group(required=True) group.add_argument( '-c', '--course', help='The course to change enrollments in') @@ -64,7 +64,6 @@ class Command(BaseCommand): to_mode = options['to_mode'] commit = options['commit'] course_keys = [] - if course_id: try: course_key = CourseKey.from_string(course_id) diff --git a/common/djangoapps/student/management/commands/manage_user.py b/common/djangoapps/student/management/commands/manage_user.py index 46ee7501ce..4c2a102322 100644 --- a/common/djangoapps/student/management/commands/manage_user.py +++ b/common/djangoapps/student/management/commands/manage_user.py @@ -5,7 +5,7 @@ Django users, set/unset permission bits, and associate groups by name. from django.contrib.auth import get_user_model -from django.contrib.auth.hashers import is_password_usable +from django.contrib.auth.hashers import is_password_usable, identify_hasher from django.contrib.auth.models import Group from django.core.management.base import BaseCommand, CommandError from django.db import transaction @@ -15,6 +15,20 @@ from openedx.core.djangoapps.user_authn.utils import generate_password from student.models import UserProfile +def is_valid_django_hash(encoded): + """ + Starting with django 2.1, the function is_password_usable no longer checks whether encode + is a valid password created by a django hasher (hasher in PASSWORD_HASHERS setting) + + Adding this function to create constant behavior as we upgrade django versions + """ + try: + identify_hasher(encoded) + except ValueError: + return False + return True + + class Command(BaseCommand): # pylint: disable=missing-docstring @@ -87,7 +101,7 @@ class Command(BaseCommand): if created: if initial_password_hash: - if not is_password_usable(initial_password_hash): + if not (is_password_usable(initial_password_hash) and is_valid_django_hash(initial_password_hash)): raise CommandError('The password hash provided for user {} is invalid.'.format(username)) user.password = initial_password_hash else: