Skip to content

Commit

Permalink
RDISCROWD-7659 password logic in ProjectCommonForm (#973)
Browse files Browse the repository at this point in the history
* password logic in ProjectCommonForm

* cleanup
  • Loading branch information
n00rsy authored Sep 24, 2024
1 parent 35f7f09 commit 08408e4
Showing 1 changed file with 14 additions and 16 deletions.
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()]
else:
self.password.validators = [pb_validator.CheckPasswordStrength(
min_len=PROJECT_PWD_MIN_LEN,
special=False,
password_required=False), validators.Optional()]

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)
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

0 comments on commit 08408e4

Please sign in to comment.