Quota updates are not polluting the audit log anymore

This commit is contained in:
jendib 2015-12-12 01:56:54 +01:00
parent 332de409b8
commit 5f82752416
3 changed files with 23 additions and 3 deletions

View File

@ -110,6 +110,26 @@ public class UserDao {
return user; return user;
} }
/**
* Updates a user's quota.
*
* @param user User to update
* @return Updated user
*/
public User updateQuota(User user) {
EntityManager em = ThreadLocalContext.get().getEntityManager();
// Get the user
Query q = em.createQuery("select u from User u where u.id = :id and u.deleteDate is null");
q.setParameter("id", user.getId());
User userFromDb = (User) q.getSingleResult();
// Update the user
userFromDb.setStorageQuota(user.getStorageQuota());
return user;
}
/** /**
* Update the user password. * Update the user password.
* *

View File

@ -304,7 +304,7 @@ public class AppResource extends BaseResource {
// Save all users // Save all users
for (User user : userMap.values()) { for (User user : userMap.values()) {
if (user.getDeleteDate() == null) { if (user.getDeleteDate() == null) {
userDao.update(user); userDao.updateQuota(user);
} }
} }

View File

@ -157,7 +157,7 @@ public class FileResource extends BaseResource {
// Update the user quota // Update the user quota
user.setStorageCurrent(user.getStorageCurrent() + fileData.length); user.setStorageCurrent(user.getStorageCurrent() + fileData.length);
userDao.update(user); userDao.updateQuota(user);
// Raise a new file created event if we have a document // Raise a new file created event if we have a document
if (documentId != null) { if (documentId != null) {
@ -369,7 +369,7 @@ public class FileResource extends BaseResource {
java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id); java.nio.file.Path storedFile = DirectoryUtil.getStorageDirectory().resolve(id);
try { try {
user.setStorageCurrent(user.getStorageCurrent() - Files.size(storedFile)); user.setStorageCurrent(user.getStorageCurrent() - Files.size(storedFile));
userDao.update(user); userDao.updateQuota(user);
} catch (IOException e) { } catch (IOException e) {
// The file doesn't exists on disk, which is weird, but not fatal // The file doesn't exists on disk, which is weird, but not fatal
} }