Clean imports and remove calls to the utils module

master
Pierre Jaury 8 years ago
parent ee9a416696
commit 713318f097

@ -1,10 +1,7 @@
from freeposte.admin import app, db, models, forms, access
import os
import pprint
import flask
import flask_login
import json
@app.route('/admin/list', methods=['GET'])

@ -1,8 +1,6 @@
from freeposte.admin import app, db, models, forms, access
import os
import flask
import flask_login
import wtforms_components

@ -1,7 +1,6 @@
from freeposte import dockercli
from freeposte.admin import app, db, models, forms, utils, access
from freeposte.admin import app, db, models, forms, access
import os
import flask
import flask_login
@ -35,7 +34,6 @@ def logout():
@app.route('/services', methods=['GET'])
@access.global_admin
def services():
utils.require_global_admin()
containers = {}
for brief in dockercli.containers(all=True):
if brief['Image'].startswith('freeposte/'):

@ -1,9 +1,7 @@
from freeposte.admin import app, db, models, forms, utils, access
from freeposte.admin import app, db, models, forms, access
from freeposte import app as flask_app
import os
import flask
import flask_login
import wtforms_components
@ -47,7 +45,7 @@ def domain_edit(domain_name):
@app.route('/domain/delete/<domain_name>', methods=['GET', 'POST'])
@access.global_admin
@utils.confirmation_required("delete {domain_name}")
@access.confirmation_required("delete {domain_name}")
def domain_delete(domain_name):
domain = models.Domain.query.get(domain_name) or flask.abort(404)
db.session.delete(domain)
@ -66,7 +64,7 @@ def domain_details(domain_name):
@app.route('/domain/genkeys/<domain_name>', methods=['GET', 'POST'])
@access.domain_admin(models.Domain, 'domain_name')
@utils.confirmation_required("regenerate keys for {domain_name}")
@access.confirmation_required("regenerate keys for {domain_name}")
def domain_genkeys(domain_name):
domain = models.Domain.query.get(domain_name) or flask.abort(404)
domain.generate_dkim_key()

@ -1,9 +1,7 @@
from freeposte.admin import app, db, models, forms, utils, access
from freeposte.admin import app, db, models, forms, access
import os
import flask
import flask_login
import wtforms_components
@app.route('/fetch/list', methods=['GET', 'POST'], defaults={'user_email': None})
@ -49,7 +47,7 @@ def fetch_edit(fetch_id):
@app.route('/fetch/delete/<fetch_id>', methods=['GET', 'POST'])
@utils.confirmation_required("delete a fetched account")
@access.confirmation_required("delete a fetched account")
@access.owner(models.Fetch, 'fetch_id')
def fetch_delete(fetch_id):
fetch = models.Fetch.query.get(fetch_id) or flask.abort(404)

@ -1,9 +1,7 @@
from freeposte.admin import app, db, models, forms, utils, access
from freeposte.admin import app, db, models, forms, access
import os
import flask
import flask_login
import wtforms_components
@app.route('/manager/list/<domain_name>', methods=['GET'])
@ -18,13 +16,16 @@ def manager_list(domain_name):
def manager_create(domain_name):
domain = models.Domain.query.get(domain_name) or flask.abort(404)
form = forms.ManagerForm()
available_users = flask_login.current_user.get_managed_emails(
include_aliases=False)
form.manager.choices = [
(user.email, user.email) for user in
flask_login.current_user.get_managed_emails(include_aliases=False)
(user.email, user.email) for user in available_users
]
if form.validate_on_submit():
user = utils.get_user(form.manager.data, admin=True)
if user in domain.managers:
user = models.User.query.get(form.manager.data)
if user not in available_users:
flask.abort(403)
elif user in domain.managers:
flask.flash('User %s is already manager' % user, 'error')
else:
domain.managers.append(user)
@ -36,18 +37,18 @@ def manager_create(domain_name):
domain=domain, form=form)
# TODO For now the deletion behaviour is broken and reserved to
# global admins.
@app.route('/manager/delete/<manager>', methods=['GET', 'POST'])
@utils.confirmation_required("remove manager {manager}")
@flask_login.login_required
@access.confirmation_required("remove manager {manager}")
@access.global_admin
def manager_delete(manager):
# TODO fix this behaviour
user = utils.get_user(manager, admin=True)
domain = utils.get_domain_admin(user.domain_name)
if user in domain.managers:
domain.managers.remove(user)
user = models.User.query.get(manager)
if user in user.domain.managers:
user.domain.managers.remove(user)
db.session.commit()
flask.flash('User %s can no longer manager %s' % (user, domain))
flask.flash('User %s can no longer manager %s' % (user, user.domain))
else:
flask.flash('User %s is not manager' % user, 'error')
return flask.redirect(
flask.url_for('.manager_list', domain_name=domain.name))
flask.url_for('.manager_list', domain_name=user.domain.name))

@ -1,6 +1,5 @@
from freeposte.admin import app, db, models, forms, utils, access
from freeposte.admin import app, db, models, forms, access
import os
import flask
import flask_login
import wtforms_components
@ -58,7 +57,7 @@ def user_edit(user_email):
@app.route('/user/delete/<user_email>', methods=['GET', 'POST'])
@access.domain_admin(models.User, 'user_email')
@utils.confirmation_required("delete {user_email}")
@access.confirmation_required("delete {user_email}")
def user_delete(user_email):
user = models.User.query.get(user_email) or flask.abort(404)
db.session.delete(user)

Loading…
Cancel
Save