1
0
mirror of https://github.com/Mailu/Mailu.git synced 2024-12-14 10:53:30 +02:00
Mailu/core/admin/mailu/ui/views/admins.py

51 lines
1.6 KiB
Python
Raw Normal View History

from mailu import models
from mailu.ui import ui, forms, access
2016-04-24 19:17:40 +02:00
import flask
2016-08-13 20:51:54 +02:00
import flask_login
2016-04-24 19:17:40 +02:00
@ui.route('/admin/list', methods=['GET'])
@access.global_admin
2016-04-24 19:17:40 +02:00
def admin_list():
admins = models.User.query.filter_by(global_admin=True)
return flask.render_template('admin/list.html', admins=admins)
@ui.route('/admin/create', methods=['GET', 'POST'])
@access.global_admin
2016-04-24 19:17:40 +02:00
def admin_create():
form = forms.AdminForm()
2016-06-19 15:34:14 +02:00
form.admin.choices = [
(user.email, user.email)
for user in
flask_login.current_user.get_managed_emails(include_aliases=False)
]
2016-04-24 19:17:40 +02:00
if form.validate_on_submit():
user = models.User.query.get(form.admin.data)
2016-04-24 19:17:40 +02:00
if user:
user.global_admin = True
models.db.session.commit()
2016-04-24 19:17:40 +02:00
flask.flash('User %s is now admin' % user)
return flask.redirect(flask.url_for('.admin_list'))
else:
flask.flash('No such user', 'error')
return flask.render_template('admin/create.html', form=form)
2019-01-04 22:18:51 +02:00
@ui.route('/admin/delete/<path:admin>', methods=['GET', 'POST'])
@access.global_admin
@access.confirmation_required("delete admin {admin}")
2016-04-24 19:17:40 +02:00
def admin_delete(admin):
user = models.User.query.get(admin)
2016-04-24 19:17:40 +02:00
if user:
user.global_admin = False
models.db.session.commit()
2016-04-24 19:17:40 +02:00
flask.flash('User %s is no longer admin' % user)
return flask.redirect(flask.url_for('.admin_list'))
else:
flask.flash('No such user', 'error')
flask.flash('Alias %s deleted' % alias)
return flask.redirect(
flask.url_for('.alias_list', domain_name=alias.domain.name))