mirror of
https://github.com/Mailu/Mailu.git
synced 2025-03-03 14:52:36 +02:00
Merge #2458
2458: Fix: Don't update updated_at on quota_bytes_used change r=mergify[bot] a=DjVinnii ## What type of PR? bug-fix ## What does this PR do? This PR makes sure that the `updated_at` field is not updated when `quota_bytes_used` is updated. All other updates to the `User` model still updates the `updated_at` field. This is done by explicitly using an method in the `Base` class triggering [`flag_modified`][url-flag-modified]. ### Related issue(s) - closes #1363 ## Prerequisites Before we can consider review and merge, please make sure the following list is done and checked. If an entry in not applicable, you can check it or remove it from the list. - [ ] In case of feature or enhancement: documentation updated accordingly - [x] Unless it's docs or a minor change: add [changelog](https://mailu.io/master/contributors/workflow.html#changelog) entry file. <!-- LINKS--> [url-flag-modified]: https://docs.sqlalchemy.org/en/14/orm/session_api.html#sqlalchemy.orm.attributes.flag_modified Co-authored-by: Vincent Kling <v.kling@vinniict.nl>
This commit is contained in:
commit
9975a793fe
@ -33,6 +33,7 @@ def dovecot_quota(ns, user_email):
|
||||
user = models.User.query.get(user_email) or flask.abort(404)
|
||||
if ns == "storage":
|
||||
user.quota_bytes_used = flask.request.get_json()
|
||||
user.dont_change_updated_at()
|
||||
models.db.session.commit()
|
||||
return flask.jsonify(None)
|
||||
|
||||
|
@ -27,6 +27,7 @@ def fetch_done(fetch_id):
|
||||
fetch = models.Fetch.query.get(fetch_id) or flask.abort(404)
|
||||
fetch.last_check = datetime.datetime.now()
|
||||
fetch.error_message = str(flask.request.get_json())
|
||||
fetch.dont_change_updated_at()
|
||||
models.db.session.add(fetch)
|
||||
models.db.session.commit()
|
||||
return ""
|
||||
|
@ -25,6 +25,7 @@ from flask import current_app as app
|
||||
from sqlalchemy.ext import declarative
|
||||
from sqlalchemy.ext.hybrid import hybrid_property
|
||||
from sqlalchemy.inspection import inspect
|
||||
from sqlalchemy.orm.attributes import flag_modified
|
||||
from werkzeug.utils import cached_property
|
||||
|
||||
from mailu import dkim, utils
|
||||
@ -154,6 +155,10 @@ class Base(db.Model):
|
||||
self.__hashed = id(self) if primary is None else hash(primary)
|
||||
return self.__hashed
|
||||
|
||||
def dont_change_updated_at(self):
|
||||
""" Mark updated_at as modified, but keep the old date when updating the model"""
|
||||
flag_modified(self, 'updated_at')
|
||||
|
||||
|
||||
# Many-to-many association table for domain managers
|
||||
managers = db.Table('manager', Base.metadata,
|
||||
|
1
towncrier/newsfragments/1363.bugfix
Normal file
1
towncrier/newsfragments/1363.bugfix
Normal file
@ -0,0 +1 @@
|
||||
Do not update the updated_at field of the User model when quota_bytes_used is updated
|
Loading…
x
Reference in New Issue
Block a user