project edit form: allow empty private code (= no change)

Currently, the private code is mandatory in the edit form, and it's not
clear whether it's meant to **check** for the right private code or to
**change** the private code.

Make the field optional and rename the help message to make it clearer
it's only meant to **change** the private code.

Also change the field type to "password" instead of simple string.
This commit is contained in:
Baptiste Jonglez 2021-07-04 13:17:04 +02:00 committed by zorun
parent 856412a70d
commit ec1e6cf26e

View file

@ -103,7 +103,8 @@ class CalculatorStringField(StringField):
class EditProjectForm(FlaskForm): class EditProjectForm(FlaskForm):
name = StringField(_("Project name"), validators=[DataRequired()]) name = StringField(_("Project name"), validators=[DataRequired()])
password = StringField(_("Private code"), validators=[DataRequired()]) # If empty -> don't change the password
password = PasswordField(_("New private code"))
contact_email = StringField(_("Email"), validators=[DataRequired(), Email()]) contact_email = StringField(_("Email"), validators=[DataRequired(), Email()])
project_history = BooleanField(_("Enable project history")) project_history = BooleanField(_("Enable project history"))
ip_recording = BooleanField(_("Use IP tracking for project history")) ip_recording = BooleanField(_("Use IP tracking for project history"))
@ -154,8 +155,13 @@ class EditProjectForm(FlaskForm):
"""Update the project with the information from the form""" """Update the project with the information from the form"""
project.name = self.name.data project.name = self.name.data
# Only update password if changed to prevent spurious log entries if (
if not check_password_hash(project.password, self.password.data): # Only update password if a new one is provided
self.password.data
# Only update password if different from the previous one,
# to prevent spurious log entries
and not check_password_hash(project.password, self.password.data)
):
project.password = generate_password_hash(self.password.data) project.password = generate_password_hash(self.password.data)
project.contact_email = self.contact_email.data project.contact_email = self.contact_email.data