Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RDISCROWD-7659 password logic in ProjectCommonForm #973

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 14 additions & 16 deletions pybossa/forms/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ def v(form, field):


class ProjectCommonForm(Form):
def __init__(self, *args, **kwargs):
super(ProjectCommonForm, self).__init__(*args, **kwargs)
if current_app.config.get('PROJECT_PASSWORD_REQUIRED'):
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=True), validators.Required()]
n00rsy marked this conversation as resolved.
Show resolved Hide resolved
else:
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=False), validators.Optional()]
n00rsy marked this conversation as resolved.
Show resolved Hide resolved

name = TextField(lazy_gettext('Name'),
[validators.Required(),
pb_validator.Unique(project_repo.get_by, 'name',
Expand All @@ -104,26 +117,11 @@ class ProjectCommonForm(Form):
validators=[validators.Required()], choices=[], default='')
output_data_class = SelectFieldWithProps(lazy_gettext('Output Data Classification'),
validators=[validators.Required()], choices=[], default='')
def __init__(self, *args, **kwargs):
Form.__init__(self, *args, **kwargs)

class ProjectForm(ProjectCommonForm):

class ProjectForm(ProjectCommonForm):
def __init__(self, *args, **kwargs):
super(ProjectForm, self).__init__(*args, **kwargs)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep def __init__ on line 107-108 and 112-113?

The original PR included __init__ and super(ProjectForm...), but here it is being removed. It may need to be added back here so that the original is intact.

The only difference was adding self.password.validators with CheckPasswordStrength which can reside in ProjectCommonForm.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Constructor on lines 107-108:
    We removed the constructor in lines 107-108 and declared a new one starting on line 87 for ProjectCommonForm.

  2. Constructor on lines 112-113
    Removing the __init__ function from ProjectForm will make it default to it's parent class's constructor, ProjectCommonForm - exactly what we want.

See https://stackoverflow.com/questions/39488875/parent-constructor-called-by-default

if current_app.config.get('PROJECT_PASSWORD_REQUIRED'):
self.password_required = True
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=True), validators.Required()]
else:
self.password_required = False
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=False), validators.Optional()]

long_description = TextAreaField(lazy_gettext('Long Description'),
[validators.Required()])
description = TextAreaField(lazy_gettext('Description'),
Expand Down
Loading