2018-10-18 15:57:43 +02:00
|
|
|
from mailu import models
|
2017-09-24 12:00:39 +02:00
|
|
|
from mailu.ui import ui, forms, access
|
2017-09-10 20:48:39 +02:00
|
|
|
|
|
|
|
import flask
|
|
|
|
import wtforms_components
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/relay', methods=['GET'])
|
2017-09-10 20:48:39 +02:00
|
|
|
@access.global_admin
|
|
|
|
def relay_list():
|
|
|
|
relays = models.Relay.query.all()
|
|
|
|
return flask.render_template('relay/list.html', relays=relays)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/relay/create', methods=['GET', 'POST'])
|
2017-09-10 20:48:39 +02:00
|
|
|
@access.global_admin
|
|
|
|
def relay_create():
|
|
|
|
form = forms.RelayForm()
|
|
|
|
if form.validate_on_submit():
|
|
|
|
conflicting_domain = models.Domain.query.get(form.name.data)
|
|
|
|
conflicting_alternative = models.Alternative.query.get(form.name.data)
|
|
|
|
conflicting_relay = models.Relay.query.get(form.name.data)
|
|
|
|
if conflicting_domain or conflicting_alternative or conflicting_relay:
|
|
|
|
flask.flash('Domain %s is already used' % form.name.data, 'error')
|
|
|
|
else:
|
|
|
|
relay = models.Relay()
|
|
|
|
form.populate_obj(relay)
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.add(relay)
|
|
|
|
models.db.session.commit()
|
2017-09-10 20:48:39 +02:00
|
|
|
flask.flash('Relayed domain %s created' % relay)
|
|
|
|
return flask.redirect(flask.url_for('.relay_list'))
|
|
|
|
return flask.render_template('relay/create.html', form=form)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/relay/edit/<relay_name>', methods=['GET', 'POST'])
|
2017-09-10 20:48:39 +02:00
|
|
|
@access.global_admin
|
|
|
|
def relay_edit(relay_name):
|
|
|
|
relay = models.Relay.query.get(relay_name) or flask.abort(404)
|
|
|
|
form = forms.RelayForm(obj=relay)
|
|
|
|
wtforms_components.read_only(form.name)
|
|
|
|
form.name.validators = []
|
|
|
|
if form.validate_on_submit():
|
|
|
|
form.populate_obj(relay)
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.commit()
|
2017-09-10 20:48:39 +02:00
|
|
|
flask.flash('Relayed domain %s saved' % relay)
|
|
|
|
return flask.redirect(flask.url_for('.relay_list'))
|
|
|
|
return flask.render_template('relay/edit.html', form=form,
|
|
|
|
relay=relay)
|
|
|
|
|
|
|
|
|
2017-09-24 12:00:39 +02:00
|
|
|
@ui.route('/relay/delete/<relay_name>', methods=['GET', 'POST'])
|
2017-09-10 20:48:39 +02:00
|
|
|
@access.global_admin
|
|
|
|
@access.confirmation_required("delete {relay_name}")
|
|
|
|
def relay_delete(relay_name):
|
|
|
|
relay = models.Relay.query.get(relay_name) or flask.abort(404)
|
2018-10-18 15:57:43 +02:00
|
|
|
models.db.session.delete(relay)
|
|
|
|
models.db.session.commit()
|
2017-09-10 20:48:39 +02:00
|
|
|
flask.flash('Relayed domain %s deleted' % relay)
|
|
|
|
return flask.redirect(flask.url_for('.relay_list'))
|
|
|
|
|