diff --git a/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs b/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs index c36e94b1be9..eb26fadd3cd 100644 --- a/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/Interfaces/IFolderDao.cs @@ -418,6 +418,7 @@ Task GetFoldersCountAsync(T parentId, FilterType filterType, bool subjectGr Task SetWatermarkSettings(WatermarkSettings waterMarks, Folder folder); Task GetWatermarkSettings(Folder room); Task> DeleteWatermarkSettings(Folder room); + Task> DeleteLifetimeSettings(Folder room); #endregion } diff --git a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs index a3830a76aea..9b0d6387829 100644 --- a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs @@ -568,29 +568,58 @@ private async Task InternalSaveFolderToDbAsync(FilesDbContext filesDbContex public async Task SetWatermarkSettings(WatermarkSettings watermarkSettings, Folder room) { + ArgumentNullException.ThrowIfNull(room); + var tenantId = await _tenantManager.GetCurrentTenantIdAsync(); await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync(); + var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id); - var toUpdate = await filesDbContext.RoomSettingsAsync(tenantId, room.Id); - - toUpdate.Watermark = mapper.Map(watermarkSettings); - filesDbContext.Update(toUpdate); - - await filesDbContext.SaveChangesAsync(); + if (roomSettings != null) + { + roomSettings.Watermark = mapper.Map(watermarkSettings); + filesDbContext.Update(roomSettings); + await filesDbContext.SaveChangesAsync(); + } return room.Id; } public async Task> DeleteWatermarkSettings(Folder room) { + ArgumentNullException.ThrowIfNull(room); + var tenantId = await _tenantManager.GetCurrentTenantIdAsync(); await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync(); var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id); - roomSettings.Watermark = null; - filesDbContext.Update(roomSettings); - await filesDbContext.SaveChangesAsync(); + + if (roomSettings != null) + { + roomSettings.Watermark = null; + filesDbContext.Update(roomSettings); + await filesDbContext.SaveChangesAsync(); + } + + return room; + } + + public async Task> DeleteLifetimeSettings(Folder room) + { + ArgumentNullException.ThrowIfNull(room); + + var tenantId = await _tenantManager.GetCurrentTenantIdAsync(); + + await using var filesDbContext = await _dbContextFactory.CreateDbContextAsync(); + var roomSettings = await filesDbContext.RoomSettingsAsync(tenantId, room.Id); + + if (roomSettings != null) + { + roomSettings.Lifetime = null; + filesDbContext.Update(roomSettings); + await filesDbContext.SaveChangesAsync(); + } + return room; } diff --git a/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs index 1a96a02d6ef..476b2505fb4 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/ProviderDao/ProviderFolderDao.cs @@ -700,4 +700,12 @@ public Task> DeleteWatermarkSettings(Folder room) return folderDao.DeleteWatermarkSettings(room); } + public Task> DeleteLifetimeSettings(Folder room) + { + ArgumentNullException.ThrowIfNull(room); + var selector = _selectorFactory.GetSelector(room.Id); + var folderDao = selector.GetFolderDao(room.Id); + + return folderDao.DeleteLifetimeSettings(room); + } } \ No newline at end of file diff --git a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs index b084f0711e7..92d8362c26f 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/SharePoint/SharePointFolderDao.cs @@ -477,6 +477,11 @@ public Task> DeleteWatermarkSettings(Folder room) { throw new NotImplementedException(); } + + public Task> DeleteLifetimeSettings(Folder room) + { + throw new NotImplementedException(); + } } static file class Queries diff --git a/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs b/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs index efd1ce52854..b3d246c230a 100644 --- a/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs +++ b/products/ASC.Files/Core/Core/Thirdparty/ThirdPartyFolderDao.cs @@ -697,6 +697,11 @@ public Task> DeleteWatermarkSettings(Folder room) { throw new NotImplementedException(); } + + public Task> DeleteLifetimeSettings(Folder room) + { + throw new NotImplementedException(); + } } internal abstract class BaseFolderDao diff --git a/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDeleteOperation.cs b/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDeleteOperation.cs index 2ed294f7589..4f29f2853f5 100644 --- a/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDeleteOperation.cs +++ b/products/ASC.Files/Core/Services/WCFService/FileOperations/FileDeleteOperation.cs @@ -378,7 +378,7 @@ private async Task DeleteFilesAsync(IEnumerable fileIds, IServiceScope scope, await folderDao.ChangeTreeFolderSizeAsync(_trashId, (-1) * file.ContentLength); } - if (_headers != null) + if (_headers != null && _headers.Count > 0) { if (isNeedSendActions) { diff --git a/products/ASC.Files/Core/Services/WCFService/FileOperations/FileMoveCopyOperation.cs b/products/ASC.Files/Core/Services/WCFService/FileOperations/FileMoveCopyOperation.cs index 0ba54b50f3f..d50ae8b53af 100644 --- a/products/ASC.Files/Core/Services/WCFService/FileOperations/FileMoveCopyOperation.cs +++ b/products/ASC.Files/Core/Services/WCFService/FileOperations/FileMoveCopyOperation.cs @@ -770,6 +770,8 @@ await socketManager.DeleteFolder(folder, action: async () => await TagDao.RemoveTagsAsync(pins); } + await FolderDao.DeleteLifetimeSettings(folder); + await filesMessageService.SendAsync(MessageAction.RoomArchived, folder, _headers, folder.Title); } else diff --git a/products/ASC.Files/Service/Services/CleanupLifetimeExpiredService.cs b/products/ASC.Files/Service/Services/CleanupLifetimeExpiredService.cs index ff75d99e8a3..0f477591655 100644 --- a/products/ASC.Files/Service/Services/CleanupLifetimeExpiredService.cs +++ b/products/ASC.Files/Service/Services/CleanupLifetimeExpiredService.cs @@ -161,7 +161,7 @@ public static readonly Func ctx.Tree .Join(ctx.Files, a => a.FolderId, b => b.ParentId, (tree, file) => new { tree, file }) - .Where(x => x.tree.ParentId == roomId && x.file.TenantId == tenantId && x.file.ModifiedOn < expiration) + .Where(x => x.tree.ParentId == roomId && x.file.TenantId == tenantId && x.file.Version == 1 && x.file.ModifiedOn < expiration) .Select(r => r.file.Id)); }