From aeff2b3dae29fc53b48a1b4cac900557a8732924 Mon Sep 17 00:00:00 2001 From: Pierre-Yves Chibon Date: Apr 30 2017 15:27:34 +0000 Subject: Add a custom validator to set the namespace when the project to create is private Signed-off-by: Pierre-Yves Chibon --- diff --git a/pagure/forms.py b/pagure/forms.py index 5281c05..2f35243 100644 --- a/pagure/forms.py +++ b/pagure/forms.py @@ -74,6 +74,13 @@ class MultipleEmail(wtforms.validators.Email): raise wtforms.validators.ValidationError(message) +def user_namespace_if_private(form, field): + ''' Check if the data in the field is the same as in the password field. + ''' + if form.private.data: + field.data = flask.g.fas_user.username + + def file_virus_validator(form, field): ''' Checks for virus in the file from flask request object, raises wtf.ValidationError if virus is found else None. ''' @@ -154,7 +161,7 @@ class ProjectForm(ProjectFormSimplified): ) namespace = wtforms.SelectField( 'Project Namespace', - [wtforms.validators.optional()], + [user_namespace_if_private, wtforms.validators.optional()], choices=[], coerce=convert_value ) diff --git a/pagure/ui/app.py b/pagure/ui/app.py index 55d6f05..ed8e78c 100644 --- a/pagure/ui/app.py +++ b/pagure/ui/app.py @@ -444,16 +444,12 @@ def new_project(): url = form.url.data avatar_email = form.avatar_email.data create_readme = form.create_readme.data - namespace = form.namespace.data - if namespace: - namespace = namespace.strip() private = False if pagure.APP.config.get('PRIVATE_PROJECTS', False): private = form.private.data - # Although it's not needed for the new_project function, it fixes - # the redirect afterward - if private: - namespace = flask.g.fas_user.username + namespace = form.namespace.data + if namespace: + namespace = namespace.strip() try: pagure.lib.new_project(