Skip to content
Snippets Groups Projects
Commit 1393a13f authored by Jiří Setnička's avatar Jiří Setnička
Browse files

Editace emailů uživatelů

Emaily soutěžících může editovat každý organizátor, který se dostane na
stránku Soutěžící (teď zatím všichni). Email organizátora může editovat
správce.

Issue #117
parent 5d014c42
No related branches found
No related tags found
1 merge request!56Editace emailu + zvací emaily
...@@ -322,14 +322,10 @@ def org_user(id: int): ...@@ -322,14 +322,10 @@ def org_user(id: int):
class UserEditForm(FlaskForm): class UserEditForm(FlaskForm):
first_name = wtforms.StringField("Jméno", validators=[Required()], render_kw={'autofocus': True}) first_name = wtforms.StringField("Jméno", validators=[Required()], render_kw={'autofocus': True})
last_name = wtforms.StringField("Příjmení", validators=[Required()]) last_name = wtforms.StringField("Příjmení", validators=[Required()])
email = wtforms.StringField("E-mail", validators=[Required()])
note = wtforms.TextAreaField("Poznámka") note = wtforms.TextAreaField("Poznámka")
submit = wtforms.SubmitField("Uložit") submit = wtforms.SubmitField("Uložit")
class NewUserForm(UserEditForm):
email = wtforms.StringField("E-mail", validators=[Required()])
submit = wtforms.SubmitField("Vytvořit")
def validate_email(form, field): def validate_email(form, field):
try: try:
field.data = mo.users.normalize_email(field.data) field.data = mo.users.normalize_email(field.data)
...@@ -357,9 +353,18 @@ def org_user_edit(id: int): ...@@ -357,9 +353,18 @@ def org_user_edit(id: int):
raise werkzeug.exceptions.Forbidden() raise werkzeug.exceptions.Forbidden()
form = UserEditForm(obj=user) form = UserEditForm(obj=user)
if (user.is_org or user.is_admin) and not g.user.is_admin:
# emaily u organizátorů může editovat jen správce
del form.email
if form.validate_on_submit(): if form.validate_on_submit():
form.populate_obj(user) check = True
if mo.users.user_by_email(form.email.data) is not None:
flash('Zadaný e-mail nelze použít, existuje jiný účet s tímto e-mailem', 'danger')
check = False
if check:
form.populate_obj(user)
if sess.is_modified(user): if sess.is_modified(user):
changes = db.get_object_changes(user) changes = db.get_object_changes(user)
...@@ -392,7 +397,8 @@ def org_user_new(): ...@@ -392,7 +397,8 @@ def org_user_new():
elif not rr.have_right(Right.add_users): elif not rr.have_right(Right.add_users):
raise werkzeug.exceptions.Forbidden() raise werkzeug.exceptions.Forbidden()
form = NewUserForm() form = UserEditForm()
form.submit.label.text = 'Vytvořit'
if form.validate_on_submit(): if form.validate_on_submit():
check = True check = True
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<h3>Editace údajů</h3> <h3>Editace údajů</h3>
<p>E-mail nelze editovat. Pro jeho změnu kontaktujte někoho ze správců.</p> {% if not form.email %}<p>E-mail u organizátora nelze editovat. Pro jeho změnu kontaktujte někoho ze správců.</p>{% endif %}
{{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }} {{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }}
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
{% block title %}Nový {% if is_org %}organizátor{% else %}soutěžící{% endif %}{% endblock %} {% block title %}Nový {% if is_org %}organizátor{% else %}soutěžící{% endif %}{% endblock %}
{% block body %} {% block body %}
<p>Na zadanou e-mailovou adresu dorazí e-mail pro nastavení hesla. E-mailovou adresu po vytvoření účtu již nelze měnit.</p> <p>Na zadanou e-mailovou adresu dorazí e-mail pro nastavení hesla.</p>
{{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }} {{ wtf.quick_form(form, form_type='horizontal', button_map={'submit': 'primary'}) }}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment