forked from openedx/edx-platform
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #362 from ucsd-ets/release-candidate
release-2020-05-06
- Loading branch information
Showing
12 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.utils.module_loading import import_string | ||
from django.utils.safestring import mark_safe | ||
from django.utils.translation import ugettext as _, ungettext | ||
|
||
|
||
class MasterPasswordValidator(object): | ||
""" | ||
Validate all of the validators given in the validators list. | ||
Parameters: | ||
validators (list): the list of validators to validate along with their options. | ||
min_validations (int): the num of minimum validation must pass for password. | ||
Raises: | ||
ValidationError if minimum number of validations is not passed. | ||
""" | ||
def __init__(self, validators=[], min_validations=0): | ||
self.check_validators_list(validators, min_validations) | ||
validators_list = validators | ||
self.validators = [] | ||
for validator in validators_list: | ||
try: | ||
validator_name = validator["NAME"] | ||
except KeyError: | ||
raise KeyError("Validator doesn't contain 'NAME'. Please enter valid Validator") | ||
validator_options = validator.get("OPTIONS", {}) | ||
self.validators.append(import_string(validator_name)(**validator_options)) | ||
self.min_validations = min_validations | ||
|
||
def validate(self, password, user=None): | ||
errors, passed = [], 0 | ||
for v in self.validators: | ||
try: | ||
v.validate(password, user) | ||
except ValidationError as e: | ||
errors.append(e) | ||
else: | ||
passed += 1 | ||
if passed < self.min_validations: | ||
errors.insert(0, ValidationError(" Fix at least {} of the following errors: ".format( | ||
self.min_validations - passed))) | ||
raise ValidationError(errors, code="too_few_validations", | ||
params={"min_validations": self.min_validations}) | ||
|
||
def get_help_text(self): | ||
text = ungettext( | ||
"your password must confirm to at least %(min_validations)d of the following:", | ||
"your password must confirm to at least %(min_validations)d of the followings:", | ||
self.min_validations | ||
) % {"min_validations": self.min_validations} | ||
for v in self.validators: | ||
text += v.get_help_text() | ||
return mark_safe(text) | ||
|
||
def get_instruction_text(self): | ||
text = ungettext( | ||
"your password must confirm to at least %(min_validations)d of the following:", | ||
"your password must confirm to at least %(min_validations)d of the followings:", | ||
self.min_validations | ||
) % {"min_validations": self.min_validations} | ||
for validator in self.validators: | ||
if hasattr(validator, 'get_instruction_text'): | ||
text += validator.get_instruction_text() + ", " | ||
return mark_safe(text[:-1]) | ||
|
||
@staticmethod | ||
def check_validators_list(validators, min_validations): | ||
if len(validators) < min_validations: | ||
raise Exception('Number of Validators in list is lower than the minimum number of required validations.') | ||
|
||
|
||
class RestrictedSymbolValidator(object): | ||
""" | ||
Validate whether the password contains any of the restricted symbol. | ||
Parameters: | ||
restricted_symbol_list (list): the list of symbols not allowed to use in password. | ||
""" | ||
def __init__(self, restricted_symbol_list=[]): | ||
self.restricted_symbol_list = restricted_symbol_list | ||
self.restricted_symbol_text = self.get_restricted_symbol_text() | ||
|
||
def validate(self, password, user=None): | ||
if self.validate_restriction_list(password): | ||
return | ||
raise ValidationError( | ||
_("Your password must not contain any of the following symbols: {}".format(self.restricted_symbol_text)), | ||
code="restricted_symbol_used", | ||
) | ||
|
||
def get_help_text(self): | ||
return _( | ||
"Your password must not contain any of the following symbols: {}".format(self.restricted_symbol_text)) | ||
|
||
def get_instruction_text(self): | ||
if len(self.restricted_symbol_list) > 0: | ||
return _( | ||
"your password must not contain any of the following symbols: {}".format(self.restricted_symbol_text)) | ||
return "" | ||
|
||
def validate_restriction_list(self, password): | ||
for c in password: | ||
if c in self.restricted_symbol_list: | ||
return False | ||
return True | ||
|
||
def get_restricted_symbol_text(self): | ||
text = "" | ||
for c in self.restricted_symbol_list: | ||
if c.isspace(): | ||
text += " Space" | ||
else: | ||
text += " " + c | ||
return text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,8 @@ git+https://github.com/edx/django-rest-framework.git@1ceda7c086fddffd1c440cc8685 | |
git+https://github.com/mitodl/edx-sga.git@3828ba9e413080a81b907a3381e5ffa05e063f81#egg=edx-sga==0.8.3 | ||
git+https://github.com/edx/[email protected]#egg=lti_consumer-xblock==1.2.5 | ||
git+https://github.com/appsembler/[email protected]#egg=tahoe-lti==release-0.2.0 | ||
-e git+https://github.com/ucsd-ets/pycaption.git@3c6b85e5ccfd180a945a4a9725d355401810352b#egg=pycaption | ||
-e git+https://github.com/ucsd-ets/xblock-video.git@1fda7cbff7a95c4f5ffe220010e9a642a7f2e6af#egg=video_xblock | ||
git+https://github.com/edx/MongoDBProxy.git@25b99097615bda06bd7cdfe5669ed80dc2a7fed0#egg=MongoDBProxy==0.1.0 | ||
-e . | ||
git+https://github.com/edx/[email protected]#egg=ora2==2.2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ git+https://github.com/mitodl/edx-sga.git@3828ba9e413080a81b907a3381e5ffa05e063f | |
git+https://github.com/edx/lettuce.git@7a04591c78ac56dac3eb3e91ca94b15cce844133#egg=lettuce==0.2.23+edx.1 | ||
git+https://github.com/edx/[email protected]#egg=lti_consumer-xblock==1.2.5 | ||
git+https://github.com/appsembler/[email protected]#egg=tahoe-lti==release-0.2.0 | ||
-e git+https://github.com/ucsd-ets/pycaption.git@3c6b85e5ccfd180a945a4a9725d355401810352b#egg=pycaption | ||
-e git+https://github.com/ucsd-ets/xblock-video.git@1fda7cbff7a95c4f5ffe220010e9a642a7f2e6af#egg=video_xblock | ||
git+https://github.com/edx/MongoDBProxy.git@25b99097615bda06bd7cdfe5669ed80dc2a7fed0#egg=MongoDBProxy==0.1.0 | ||
-e . | ||
git+https://github.com/edx/[email protected]#egg=ora2==2.2.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,3 +103,6 @@ | |
-e git+https://github.com/mitodl/edx-sga.git@3828ba9e413080a81b907a3381e5ffa05e063f81#egg=edx-sga==0.8.3 | ||
-e git+https://github.com/open-craft/xblock-poll@add89e14558c30f3c8dc7431e5cd6536fff6d941#egg=xblock-poll==1.5.1 | ||
-e git+https://github.com/edx-solutions/[email protected]#egg=xblock-drag-and-drop-v2==2.1.6 | ||
# Forks of pycaption and xblock-video with updated dependencies | ||
-e git+https://github.com/ucsd-ets/pycaption.git@3c6b85e5ccfd180a945a4a9725d355401810352b#egg=pycaption | ||
-e git+https://github.com/ucsd-ets/xblock-video.git@1fda7cbff7a95c4f5ffe220010e9a642a7f2e6af#egg=video_xblock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ git+https://github.com/mitodl/edx-sga.git@3828ba9e413080a81b907a3381e5ffa05e063f | |
git+https://github.com/edx/lettuce.git@7a04591c78ac56dac3eb3e91ca94b15cce844133#egg=lettuce==0.2.23+edx.1 | ||
git+https://github.com/edx/[email protected]#egg=lti_consumer-xblock==1.2.5 | ||
git+https://github.com/appsembler/[email protected]#egg=tahoe-lti==release-0.2.0 | ||
-e git+https://github.com/ucsd-ets/pycaption.git@3c6b85e5ccfd180a945a4a9725d355401810352b#egg=pycaption | ||
-e git+https://github.com/ucsd-ets/xblock-video.git@1fda7cbff7a95c4f5ffe220010e9a642a7f2e6af#egg=video_xblock | ||
git+https://github.com/edx/MongoDBProxy.git@25b99097615bda06bd7cdfe5669ed80dc2a7fed0#egg=MongoDBProxy==0.1.0 | ||
-e . | ||
git+https://github.com/edx/[email protected]#egg=ora2==2.2.0 | ||
|