Fix the manager deletion behaviour

master
Pierre Jaury 8 years ago
parent f541a951de
commit f8dcef22ef

@ -22,7 +22,7 @@ Manager list
{% for manager in domain.managers %} {% for manager in domain.managers %}
<tr> <tr>
<td> <td>
<a href="{{ url_for('.manager_delete', manager=manager.email) }}" title="Delete"><i class="fa fa-trash"></i></a> <a href="{{ url_for('.manager_delete', domain_name=domain.name, user_email=manager.email) }}" title="Delete"><i class="fa fa-trash"></i></a>
</td> </td>
<td>{{ manager }}</td> <td>{{ manager }}</td>
</tr> </tr>

@ -37,18 +37,17 @@ def manager_create(domain_name):
domain=domain, form=form) domain=domain, form=form)
# TODO For now the deletion behaviour is broken and reserved to @app.route('/manager/delete/<domain_name>/<user_email>', methods=['GET', 'POST'])
# global admins. @access.confirmation_required("remove manager {user_email}")
@app.route('/manager/delete/<manager>', methods=['GET', 'POST']) @access.domain_admin(models.Domain, 'domain_name')
@access.confirmation_required("remove manager {manager}") def manager_delete(domain_name, user_email):
@access.global_admin domain = models.Domain.query.get(domain_name) or flask.abort(404)
def manager_delete(manager): user = models.User.query.get(user_email) or flask.abort(404)
user = models.User.query.get(manager) if user in domain.managers:
if user in user.domain.managers: domain.managers.remove(user)
user.domain.managers.remove(user)
db.session.commit() db.session.commit()
flask.flash('User %s can no longer manager %s' % (user, user.domain)) flask.flash('User %s can no longer manager %s' % (user, domain))
else: else:
flask.flash('User %s is not manager' % user, 'error') flask.flash('User %s is not manager' % user, 'error')
return flask.redirect( return flask.redirect(
flask.url_for('.manager_list', domain_name=user.domain.name)) flask.url_for('.manager_list', domain_name=domain_name))

Loading…
Cancel
Save