2018-10-18 17:55:07 +02:00
|
|
|
from mailu import models
|
2017-09-24 12:00:39 +02:00
|
|
|
from mailu.ui import ui, forms, access
|
2017-09-03 18:30:00 +02:00
|
|
|
|
|
|
|
import flask
|
|
|
|
import wtforms_components
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/alternative/list/<domain_name>', methods=['GET'])
|
2017-09-03 18:30:00 +02:00
|
|
|
@access.global_admin
|
|
|
|
def alternative_list(domain_name):
|
|
|
|
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
|
|
|
return flask.render_template('alternative/list.html', domain=domain)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/alternative/create/<domain_name>', methods=['GET', 'POST'])
|
2017-09-03 18:30:00 +02:00
|
|
|
@access.global_admin
|
|
|
|
def alternative_create(domain_name):
|
|
|
|
domain = models.Domain.query.get(domain_name) or flask.abort(404)
|
|
|
|
form = forms.AlternativeForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
conflicting_domain = models.Domain.query.get(form.name.data)
|
|
|
|
conflicting_alternative = models.Alternative.query.get(form.name.data)
|
2017-09-10 20:49:49 +02:00
|
|
|
conflicting_relay = models.Relay.query.get(form.name.data)
|
|
|
|
if conflicting_domain or conflicting_alternative or conflicting_relay:
|
2017-09-03 18:30:00 +02:00
|
|
|
flask.flash('Domain %s is already used' % form.name.data, 'error')
|
|
|
|
else:
|
|
|
|
alternative = models.Alternative(domain=domain)
|
|
|
|
form.populate_obj(alternative)
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.add(alternative)
|
|
|
|
models.db.session.commit()
|
2017-09-03 18:30:00 +02:00
|
|
|
flask.flash('Alternative domain %s created' % alternative)
|
|
|
|
return flask.redirect(
|
|
|
|
flask.url_for('.alternative_list', domain_name=domain.name))
|
|
|
|
return flask.render_template('alternative/create.html',
|
|
|
|
domain=domain, form=form)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/alternative/delete/<alternative>', methods=['GET', 'POST'])
|
2017-09-03 18:30:00 +02:00
|
|
|
@access.global_admin
|
|
|
|
@access.confirmation_required("delete {alternative}")
|
|
|
|
def alternative_delete(alternative):
|
|
|
|
alternative = models.Alternative.query.get(alternative) or flask.abort(404)
|
|
|
|
domain = alternative.domain
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.delete(alternative)
|
|
|
|
models.db.session.commit()
|
2017-09-03 18:30:00 +02:00
|
|
|
flask.flash('Alternative %s deleted' % alternative)
|
|
|
|
return flask.redirect(
|
|
|
|
flask.url_for('.alternative_list', domain_name=domain.name))
|