From 00b32e638a99022465393531aad5f3ba3eb7088c Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Fri, 23 Dec 2022 21:00:05 +0300 Subject: [PATCH] =?UTF-8?q?fix=20Bug=C2=A060214?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Core/Core/Dao/TeamlabDao/FileDao.cs | 21 +++++++------------ .../Core/Core/Dao/TeamlabDao/FolderDao.cs | 4 +++- products/ASC.Files/Core/Utils/FileUploader.cs | 2 +- web/ASC.Web.Api/Api/SecurityController.cs | 8 +++---- web/ASC.Web.Core/SetupInfo.cs | 8 +++---- 5 files changed, 20 insertions(+), 23 deletions(-) diff --git a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs index 9240fc88d5..edf6d91343 100644 --- a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs +++ b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs @@ -393,21 +393,16 @@ internal class FileDao : AbstractDao, IFileDao return SaveFileAsync(file, fileStream, true); } - public Task> SaveFileAsync(File file, Stream fileStream, bool checkQuota = true) + public async Task> SaveFileAsync(File file, Stream fileStream, bool checkQuota = true) { ArgumentNullException.ThrowIfNull(file); - var maxChunkedUploadSize = _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic); + var maxChunkedUploadSize = await _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic); if (checkQuota && maxChunkedUploadSize < file.ContentLength) { throw FileSizeComment.GetFileSizeException(maxChunkedUploadSize); } - return InternalSaveFileAsync(file, fileStream, checkQuota); - } - - private async Task> InternalSaveFileAsync(File file, Stream fileStream, bool checkQuota = true) - { if (checkQuota && _coreBaseSettings.Personal && SetupInfo.IsVisibleSettings("PersonalMaxSpace")) { var personalMaxSpace = _coreConfiguration.PersonalMaxSpace(_settingsManager); @@ -585,18 +580,18 @@ internal class FileDao : AbstractDao, IFileDao throw new ArgumentException("No file id or folder id toFolderId determine provider"); } - var maxChunkedUploadSize = _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic); + return InternalReplaceFileVersionAsync(file, fileStream); + } + + private async Task> InternalReplaceFileVersionAsync(File file, Stream fileStream) + { + var maxChunkedUploadSize = await _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic); if (maxChunkedUploadSize < file.ContentLength) { throw FileSizeComment.GetFileSizeException(maxChunkedUploadSize); } - return InternalReplaceFileVersionAsync(file, fileStream); - } - - private async Task> InternalReplaceFileVersionAsync(File file, Stream fileStream) - { if (_coreBaseSettings.Personal && SetupInfo.IsVisibleSettings("PersonalMaxSpace")) { var personalMaxSpace = _coreConfiguration.PersonalMaxSpace(_settingsManager); diff --git a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs index cc3175aee4..8e5604df31 100644 --- a/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs +++ b/products/ASC.Files/Core/Core/Dao/TeamlabDao/FolderDao.cs @@ -944,7 +944,9 @@ internal class FolderDao : AbstractDao, IFolderDao tmp = _coreConfiguration.PersonalMaxSpace(_settingsManager) - await _globalSpace.GetUserUsedSpaceAsync(); } - return Math.Min(tmp, chunkedUpload ? _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic) : _setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic)); + return Math.Min(tmp, chunkedUpload ? + await _setupInfo.MaxChunkedUploadSize(_tenantManager, _maxTotalSizeStatistic) : + await _setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic)); } private async Task RecalculateFoldersCountAsync(int id) diff --git a/products/ASC.Files/Core/Utils/FileUploader.cs b/products/ASC.Files/Core/Utils/FileUploader.cs index 92909bd65b..46f3f569ca 100644 --- a/products/ASC.Files/Core/Utils/FileUploader.cs +++ b/products/ASC.Files/Core/Utils/FileUploader.cs @@ -316,7 +316,7 @@ public class FileUploader if (chunkLength > _setupInfo.ChunkUploadSize) { - throw FileSizeComment.GetFileSizeException(_setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic)); + throw FileSizeComment.GetFileSizeException(await _setupInfo.MaxUploadSize(_tenantManager, _maxTotalSizeStatistic)); } var maxUploadSize = await GetMaxFileSizeAsync(uploadSession.FolderId, uploadSession.BytesTotal > 0); diff --git a/web/ASC.Web.Api/Api/SecurityController.cs b/web/ASC.Web.Api/Api/SecurityController.cs index 112d016297..b3d161ff04 100644 --- a/web/ASC.Web.Api/Api/SecurityController.cs +++ b/web/ASC.Web.Api/Api/SecurityController.cs @@ -188,7 +188,7 @@ public class SecurityController : ControllerBase } [HttpPost("audit/login/report")] - public object CreateLoginHistoryReport() + public async Task CreateLoginHistoryReport() { _permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings); @@ -203,14 +203,14 @@ public class SecurityController : ControllerBase var events = _loginEventsRepository.GetByFilter(fromDate: from, to: to); using var stream = _auditReportCreator.CreateCsvReport(events); - var result = _auditReportSaver.UploadCsvReport(stream, reportName); + var result = await _auditReportSaver.UploadCsvReport(stream, reportName); _messageService.Send(MessageAction.LoginHistoryReportDownloaded); return result; } [HttpPost("audit/events/report")] - public object CreateAuditTrailReport() + public async Task CreateAuditTrailReport() { _permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings); @@ -228,7 +228,7 @@ public class SecurityController : ControllerBase var events = _auditEventsRepository.GetByFilter(from: from, to: to); using var stream = _auditReportCreator.CreateCsvReport(events); - var result = _auditReportSaver.UploadCsvReport(stream, reportName); + var result = await _auditReportSaver.UploadCsvReport(stream, reportName); _messageService.Send(MessageAction.AuditTrailReportDownloaded); return result; diff --git a/web/ASC.Web.Core/SetupInfo.cs b/web/ASC.Web.Core/SetupInfo.cs index dfe23b742d..8f33077399 100644 --- a/web/ASC.Web.Core/SetupInfo.cs +++ b/web/ASC.Web.Core/SetupInfo.cs @@ -49,9 +49,9 @@ public class SetupInfo /// /// Max possible file size for not chunked upload. Less or equal than 100 mb. /// - public long MaxUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic) + public async Task MaxUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic) { - return Math.Min(AvailableFileSize, MaxChunkedUploadSize(tenantManager, maxTotalSizeStatistic)); + return Math.Min(AvailableFileSize, await MaxChunkedUploadSize(tenantManager, maxTotalSizeStatistic)); } public long AvailableFileSize @@ -201,12 +201,12 @@ public class SetupInfo return _hideSettings == null || !_hideSettings.Contains(settings, StringComparer.CurrentCultureIgnoreCase); } - public long MaxChunkedUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic) + public async Task MaxChunkedUploadSize(TenantManager tenantManager, MaxTotalSizeStatistic maxTotalSizeStatistic) { var diskQuota = tenantManager.GetCurrentTenantQuota(); if (diskQuota != null) { - var usedSize = maxTotalSizeStatistic.GetValue().Result; + var usedSize = await maxTotalSizeStatistic.GetValue(); var freeSize = Math.Max(diskQuota.MaxTotalSize - usedSize, 0); return Math.Min(freeSize, diskQuota.MaxFileSize); }