mirror of
https://github.com/Mailu/Mailu.git
synced 2024-12-14 10:53:30 +02:00
Do not always add objects to the session before committing
This commit is contained in:
parent
2396324e21
commit
82ec86afd8
@ -22,7 +22,6 @@ def admin_create():
|
|||||||
user = models.User.query.get(form.admin.data)
|
user = models.User.query.get(form.admin.data)
|
||||||
if user:
|
if user:
|
||||||
user.global_admin = True
|
user.global_admin = True
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('User %s is now admin' % user)
|
flask.flash('User %s is now admin' % user)
|
||||||
return flask.redirect(flask.url_for('.admin_list'))
|
return flask.redirect(flask.url_for('.admin_list'))
|
||||||
@ -37,7 +36,6 @@ def admin_delete(admin):
|
|||||||
user = models.User.query.get(admin)
|
user = models.User.query.get(admin)
|
||||||
if user:
|
if user:
|
||||||
user.global_admin = False
|
user.global_admin = False
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('User %s is no longer admin' % user)
|
flask.flash('User %s is no longer admin' % user)
|
||||||
return flask.redirect(flask.url_for('.admin_list'))
|
return flask.redirect(flask.url_for('.admin_list'))
|
||||||
|
@ -45,7 +45,6 @@ def alias_edit(alias):
|
|||||||
wtforms_components.read_only(form.localpart)
|
wtforms_components.read_only(form.localpart)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(alias)
|
form.populate_obj(alias)
|
||||||
db.session.add(alias)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Alias %s updated' % alias)
|
flask.flash('Alias %s updated' % alias)
|
||||||
return flask.redirect(
|
return flask.redirect(
|
||||||
|
@ -39,7 +39,6 @@ def domain_edit(domain_name):
|
|||||||
wtforms_components.read_only(form.name)
|
wtforms_components.read_only(form.name)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(domain)
|
form.populate_obj(domain)
|
||||||
db.session.add(domain)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Domain %s saved' % domain)
|
flask.flash('Domain %s saved' % domain)
|
||||||
return flask.redirect(flask.url_for('.domain_list'))
|
return flask.redirect(flask.url_for('.domain_list'))
|
||||||
|
@ -38,7 +38,6 @@ def fetch_edit(fetch_id):
|
|||||||
form = forms.FetchForm(obj=fetch)
|
form = forms.FetchForm(obj=fetch)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(fetch)
|
form.populate_obj(fetch)
|
||||||
db.session.add(fetch)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Fetch configuration updated')
|
flask.flash('Fetch configuration updated')
|
||||||
return flask.redirect(
|
return flask.redirect(
|
||||||
|
@ -24,7 +24,6 @@ def manager_create(domain_name):
|
|||||||
flask.flash('User %s is already manager' % user, 'error')
|
flask.flash('User %s is already manager' % user, 'error')
|
||||||
else:
|
else:
|
||||||
domain.managers.append(user)
|
domain.managers.append(user)
|
||||||
db.session.add(domain)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('User %s can now manage %s' % (user, domain.name))
|
flask.flash('User %s can now manage %s' % (user, domain.name))
|
||||||
return flask.redirect(
|
return flask.redirect(
|
||||||
@ -40,7 +39,6 @@ def manager_delete(manager):
|
|||||||
domain = utils.get_domain_admin(user.domain_name)
|
domain = utils.get_domain_admin(user.domain_name)
|
||||||
if user in domain.managers:
|
if user in domain.managers:
|
||||||
domain.managers.remove(user)
|
domain.managers.remove(user)
|
||||||
db.session.add(domain)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('User %s can no longer manager %s' % (user, domain))
|
flask.flash('User %s can no longer manager %s' % (user, domain))
|
||||||
else:
|
else:
|
||||||
|
@ -49,7 +49,6 @@ def user_edit(user_email):
|
|||||||
form.populate_obj(user)
|
form.populate_obj(user)
|
||||||
if form.pw.data:
|
if form.pw.data:
|
||||||
user.set_password(form.pw.data)
|
user.set_password(form.pw.data)
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('User %s updated' % user)
|
flask.flash('User %s updated' % user)
|
||||||
return flask.redirect(
|
return flask.redirect(
|
||||||
@ -76,7 +75,6 @@ def user_settings(user_email):
|
|||||||
form = forms.UserSettingsForm(obj=user)
|
form = forms.UserSettingsForm(obj=user)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(user)
|
form.populate_obj(user)
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Settings updated for %s' % user)
|
flask.flash('Settings updated for %s' % user)
|
||||||
if user_email:
|
if user_email:
|
||||||
@ -96,7 +94,6 @@ def user_password(user_email):
|
|||||||
flask.flash('Passwords do not match', 'error')
|
flask.flash('Passwords do not match', 'error')
|
||||||
else:
|
else:
|
||||||
user.set_password(form.pw.data)
|
user.set_password(form.pw.data)
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Password updated for %s' % user)
|
flask.flash('Password updated for %s' % user)
|
||||||
if user_email:
|
if user_email:
|
||||||
@ -116,7 +113,6 @@ def user_forward(user_email):
|
|||||||
user.forward = form.forward.data
|
user.forward = form.forward.data
|
||||||
else:
|
else:
|
||||||
user.forward = None
|
user.forward = None
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Forward destination updated for %s' % user)
|
flask.flash('Forward destination updated for %s' % user)
|
||||||
if user_email:
|
if user_email:
|
||||||
@ -133,7 +129,6 @@ def user_reply(user_email):
|
|||||||
form = forms.UserReplyForm(obj=user)
|
form = forms.UserReplyForm(obj=user)
|
||||||
if form.validate_on_submit():
|
if form.validate_on_submit():
|
||||||
form.populate_obj(user)
|
form.populate_obj(user)
|
||||||
db.session.add(user)
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
flask.flash('Auto-reply message updated for %s' % user)
|
flask.flash('Auto-reply message updated for %s' % user)
|
||||||
if user_email:
|
if user_email:
|
||||||
|
Loading…
Reference in New Issue
Block a user