From b1bd5a100ffd6f13cb72205f4b7e73ca08ae965c Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Wed, 12 Oct 2022 14:23:57 +0300 Subject: [PATCH 01/14] Quota: recalculate user quota --- .../FilesSpaceUsageStatManager.cs | 48 +++-- .../Core/Configuration/ProductEntryPoint.cs | 8 +- .../Core/Core/UsersQuotaSyncOperation.cs | 174 ++++++++++++++++++ products/ASC.Files/Core/Helpers/Global.cs | 8 +- .../ASC.Files/Server/ProductEntryPoint.cs | 4 +- .../ASC.People/Server/Api/UserController.cs | 22 ++- products/ASC.People/Server/GlobalUsings.cs | 1 + web/ASC.Web.Core/SpaceUsageStatManager.cs | 2 + 8 files changed, 227 insertions(+), 40 deletions(-) create mode 100644 products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs diff --git a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs index a095d40b12..00f5b4b94e 100644 --- a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs +++ b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs @@ -27,7 +27,7 @@ namespace ASC.Web.Files; [Scope] -public class FilesSpaceUsageStatManager : SpaceUsageStatManager +public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage { private readonly IDbContextFactory _dbContextFactory; private readonly TenantManager _tenantManager; @@ -37,6 +37,9 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager private readonly CommonLinkUtility _commonLinkUtility; private readonly GlobalFolderHelper _globalFolderHelper; private readonly PathProvider _pathProvider; + private readonly IDaoFactory _daoFactory; + private readonly GlobalFolder _globalFolder; + private readonly FileMarker _fileMarker; public FilesSpaceUsageStatManager( IDbContextFactory dbContextFactory, @@ -46,7 +49,10 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager DisplayUserSettingsHelper displayUserSettingsHelper, CommonLinkUtility commonLinkUtility, GlobalFolderHelper globalFolderHelper, - PathProvider pathProvider) + PathProvider pathProvider, + IDaoFactory daoFactory, + GlobalFolder globalFolder, + FileMarker fileMarker) { _dbContextFactory = dbContextFactory; _tenantManager = tenantManager; @@ -56,6 +62,9 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager _commonLinkUtility = commonLinkUtility; _globalFolderHelper = globalFolderHelper; _pathProvider = pathProvider; + _daoFactory = daoFactory; + _globalFolder = globalFolder; + _fileMarker = fileMarker; } public override ValueTask> GetStatDataAsync() @@ -107,31 +116,8 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager .ToListAsync(); } -} -[Scope] -public class FilesUserSpaceUsage : IUserSpaceUsage -{ - private readonly IDbContextFactory _dbContextFactory; - private readonly TenantManager _tenantManager; - private readonly GlobalFolder _globalFolder; - private readonly FileMarker _fileMarker; - private readonly IDaoFactory _daoFactory; - public FilesUserSpaceUsage( - IDbContextFactory dbContextFactory, - TenantManager tenantManager, - GlobalFolder globalFolder, - FileMarker fileMarker, - IDaoFactory daoFactory) - { - _dbContextFactory = dbContextFactory; - _tenantManager = tenantManager; - _globalFolder = globalFolder; - _fileMarker = fileMarker; - _daoFactory = daoFactory; - } - public async Task GetUserSpaceUsageAsync(Guid userId) { var tenantId = _tenantManager.GetCurrentTenant().Id; @@ -143,4 +129,16 @@ public class FilesUserSpaceUsage : IUserSpaceUsage .Where(r => r.TenantId == tenantId && r.CreateBy == userId && (r.ParentId == my || r.ParentId == trash)) .SumAsync(r => r.ContentLength); } + + public async Task RecalculateUserQuota(int TenantId, Guid userId) + { + _tenantManager.SetCurrentTenant(TenantId); + + var size = await GetUserSpaceUsageAsync(userId); + + _tenantManager.SetTenantQuotaRow( + new TenantQuotaRow { Tenant = TenantId, Path = $"/{FileConstant.ModuleId}/", Counter = size, Tag = WebItemManager.DocumentsProductID.ToString(), UserId = userId, LastModified = DateTime.UtcNow }, + true); + } + } diff --git a/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs b/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs index d067a07bab..62ad4958f6 100644 --- a/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs +++ b/products/ASC.Files/Core/Configuration/ProductEntryPoint.cs @@ -31,7 +31,7 @@ public class ProductEntryPoint : Product { internal const string ProductPath = "/products/files/"; - //public FilesSpaceUsageStatManager FilesSpaceUsageStatManager { get; } + private readonly FilesSpaceUsageStatManager _filesSpaceUsageStatManager; private readonly CoreBaseSettings _coreBaseSettings; private readonly AuthContext _authContext; private readonly UserManager _userManager; @@ -42,7 +42,7 @@ public class ProductEntryPoint : Product public ProductEntryPoint() { } public ProductEntryPoint( - // FilesSpaceUsageStatManager filesSpaceUsageStatManager, + FilesSpaceUsageStatManager filesSpaceUsageStatManager, CoreBaseSettings coreBaseSettings, AuthContext authContext, UserManager userManager, @@ -50,7 +50,7 @@ public class ProductEntryPoint : Product // SubscriptionManager subscriptionManager ) { - // FilesSpaceUsageStatManager = filesSpaceUsageStatManager; + _filesSpaceUsageStatManager = filesSpaceUsageStatManager; _coreBaseSettings = coreBaseSettings; _authContext = authContext; _userManager = userManager; @@ -83,7 +83,7 @@ public class ProductEntryPoint : Product LargeIconFileName = "images/files.svg", DefaultSortOrder = 10, //SubscriptionManager = SubscriptionManager, - //SpaceUsageStatManager = FilesSpaceUsageStatManager, + SpaceUsageStatManager = _filesSpaceUsageStatManager, AdminOpportunities = adminOpportunities, UserOpportunities = userOpportunities, CanNotBeDisabled = true, diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs new file mode 100644 index 0000000000..a1b08dc8fa --- /dev/null +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -0,0 +1,174 @@ +// (c) Copyright Ascensio System SIA 2010-2022 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +using ASC.Files.Core.Data; +using ASC.Web.Core; + +namespace ASC.Web.Files; + +[Singletone(Additional = typeof(UsersQuotaOperationExtension))] +public class UsersQuotaSyncOperation +{ + public const string CUSTOM_DISTRIBUTED_TASK_QUEUE_NAME = "userQuotaOperation"; + + private readonly DistributedTaskQueue _progressQueue; + + private readonly IServiceProvider _serviceProvider; + + + public void RecalculateQuota(Tenant tenant) + { + var item = _progressQueue.GetAllTasks().FirstOrDefault(t => t.TenantId == tenant.Id); + if (item != null && item.IsCompleted) + { + _progressQueue.DequeueTask(item.Id); + item = null; + } + + if (item == null) + { + item = _serviceProvider.GetRequiredService(); + item.InitJob(tenant); + _progressQueue.EnqueueTask(item); + } + + item.PublishChanges(); + } + + + public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory) + { + ; + _serviceProvider = serviceProvider; + + _progressQueue = queueFactory.CreateQueue(CUSTOM_DISTRIBUTED_TASK_QUEUE_NAME); + } + + + + public static class UsersQuotaOperationExtension + { + public static void Register(DIHelper services) + { + services.TryAdd(); + } + } +} + +public class UsersQuotaSyncJob : DistributedTaskProgress +{ + private readonly IServiceScopeFactory _serviceScopeFactory; + private readonly IDaoFactory _daoFactory; + private readonly FilesSpaceUsageStatManager _filesSpaceUsageStatManager; + private readonly WebItemManager _webItemManager; + private readonly WebItemManagerSecurity _webItemManagerSecurity; + + protected readonly IDbContextFactory _dbContextFactory; + + + private int? _tenantId; + public int TenantId + { + get + { + return _tenantId ?? this[nameof(_tenantId)]; + } + private set + { + _tenantId = value; + this[nameof(_tenantId)] = value; + } + } + + public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory, + IDaoFactory daoFactory, + FilesSpaceUsageStatManager filesSpaceUsageStatManager, + WebItemManager webItemManager, + WebItemManagerSecurity webItemManagerSecurity + ) + { + _serviceScopeFactory = serviceScopeFactory; + _daoFactory = daoFactory; + _filesSpaceUsageStatManager = filesSpaceUsageStatManager; + _webItemManager = webItemManager; + _webItemManagerSecurity = webItemManagerSecurity; + } + public void InitJob(Tenant tenant) + { + TenantId = tenant.Id; + } + protected override async void DoJob() + { + try + { + using var scope = _serviceScopeFactory.CreateScope(); + + var _tenantManager = scope.ServiceProvider.GetRequiredService(); + var _userManager = scope.ServiceProvider.GetRequiredService(); + + _tenantManager.SetCurrentTenant(TenantId); + + var fileDao = _daoFactory.GetFileDao(); + + var users = _userManager.GetUsers(); + var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); + + foreach (var user in users) + { + _tenantManager.SetCurrentTenant(TenantId); + var spaceUsage = _filesSpaceUsageStatManager.GetUserSpaceUsageAsync(user.Id); + + + foreach (var item in webItems) + { + IUserSpaceUsage manager; + + if (item.ID == WebItemManager.DocumentsProductID) + { + manager = item.Context.SpaceUsageStatManager as IUserSpaceUsage; + if (manager == null) + { + continue; + } + + await manager.RecalculateUserQuota(TenantId, user.Id); + } + } + + } + } + catch (Exception ex) + { + Status = DistributedTaskStatus.Failted; + Exception = ex; + } + finally + { + IsCompleted = true; + } + PublishChanges(); + } +} diff --git a/products/ASC.Files/Core/Helpers/Global.cs b/products/ASC.Files/Core/Helpers/Global.cs index 31796f41eb..5e31729d0b 100644 --- a/products/ASC.Files/Core/Helpers/Global.cs +++ b/products/ASC.Files/Core/Helpers/Global.cs @@ -250,12 +250,12 @@ public class GlobalStore [Scope] public class GlobalSpace { - private readonly FilesUserSpaceUsage _filesUserSpaceUsage; + private readonly FilesSpaceUsageStatManager _filesSpaceUsageStatManager; private readonly AuthContext _authContext; - public GlobalSpace(FilesUserSpaceUsage filesUserSpaceUsage, AuthContext authContext) + public GlobalSpace(FilesSpaceUsageStatManager filesSpaceUsageStatManager, AuthContext authContext) { - _filesUserSpaceUsage = filesUserSpaceUsage; + _filesSpaceUsageStatManager = filesSpaceUsageStatManager; _authContext = authContext; } @@ -266,7 +266,7 @@ public class GlobalSpace public Task GetUserUsedSpaceAsync(Guid userId) { - return _filesUserSpaceUsage.GetUserSpaceUsageAsync(userId); + return _filesSpaceUsageStatManager.GetUserSpaceUsageAsync(userId); } } diff --git a/products/ASC.Files/Server/ProductEntryPoint.cs b/products/ASC.Files/Server/ProductEntryPoint.cs index 2d293d52d2..6e8c5d6ed2 100644 --- a/products/ASC.Files/Server/ProductEntryPoint.cs +++ b/products/ASC.Files/Server/ProductEntryPoint.cs @@ -35,13 +35,13 @@ public class ApiProductEntryPoint : ProductEntryPoint } public ApiProductEntryPoint( - //FilesSpaceUsageStatManager filesSpaceUsageStatManager, + FilesSpaceUsageStatManager filesSpaceUsageStatManager, CoreBaseSettings coreBaseSettings, AuthContext authContext, UserManager userManager, NotifyConfiguration notifyConfiguration //SubscriptionManager subscriptionManager - ) : base(coreBaseSettings, authContext, userManager, notifyConfiguration) + ) : base(filesSpaceUsageStatManager, coreBaseSettings, authContext, userManager, notifyConfiguration) { } diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index 88d9c8505c..fc7d40d376 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -64,8 +64,10 @@ public class UserController : PeopleControllerBase private readonly SetupInfo _setupInfo; private readonly SettingsManager _settingsManager; private readonly RoomLinkService _roomLinkService; - private readonly FileSecurity _fileSecurity; + private readonly FileSecurity _fileSecurity; private readonly IQuotaService _quotaService; + private readonly FilesSpaceUsageStatManager _filesSpaceUsageStatManager; + private readonly UsersQuotaSyncOperation _usersQuotaSyncOperation; public UserController( ICache cache, @@ -105,8 +107,10 @@ public class UserController : PeopleControllerBase IHttpContextAccessor httpContextAccessor, SettingsManager settingsManager, RoomLinkService roomLinkService, - FileSecurity fileSecurity, - IQuotaService quotaService) + FileSecurity fileSecurity, + IQuotaService quotaService, + FilesSpaceUsageStatManager filesSpaceUsageStatManager, + UsersQuotaSyncOperation usersQuotaSyncOperation) : base(userManager, permissionContext, apiContext, userPhotoManager, httpClientFactory, httpContextAccessor) { _cache = cache; @@ -140,8 +144,10 @@ public class UserController : PeopleControllerBase _setupInfo = setupInfo; _settingsManager = settingsManager; _roomLinkService = roomLinkService; - _fileSecurity = fileSecurity; + _fileSecurity = fileSecurity; _quotaService = quotaService; + _filesSpaceUsageStatManager = filesSpaceUsageStatManager; + _usersQuotaSyncOperation = usersQuotaSyncOperation; } [HttpPost("active")] @@ -1069,6 +1075,12 @@ public class UserController : PeopleControllerBase yield return await _employeeFullDtoHelper.GetFull(user); } } + [HttpGet("recalculatequota")] + public void RecalculateQuota() + { + _permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings); + _usersQuotaSyncOperation.RecalculateQuota(_tenantManager.GetCurrentTenant()); + } [HttpPut("quota")] public async IAsyncEnumerable UpdateUserQuota(UpdateMembersQuotaRequestDto inDto) @@ -1083,7 +1095,7 @@ public class UserController : PeopleControllerBase if (inDto.Quota != -1) { var usedSpace = Math.Max(0, - _quotaService.FindUserQuotaRows( + _quotaService.FindUserQuotaRows( _tenantManager.GetCurrentTenant().Id, user.Id ) diff --git a/products/ASC.People/Server/GlobalUsings.cs b/products/ASC.People/Server/GlobalUsings.cs index 68b0729216..57b66272a1 100644 --- a/products/ASC.People/Server/GlobalUsings.cs +++ b/products/ASC.People/Server/GlobalUsings.cs @@ -66,6 +66,7 @@ global using ASC.Web.Core.Mobile; global using ASC.Web.Core.PublicResources; global using ASC.Web.Core.Users; global using ASC.Web.Core.Utility; +global using ASC.Web.Files; global using ASC.Web.Files.Classes; global using ASC.Web.Studio.Core; global using ASC.Web.Studio.Core.Notify; diff --git a/web/ASC.Web.Core/SpaceUsageStatManager.cs b/web/ASC.Web.Core/SpaceUsageStatManager.cs index 689c5eaca3..fd2b58b4ca 100644 --- a/web/ASC.Web.Core/SpaceUsageStatManager.cs +++ b/web/ASC.Web.Core/SpaceUsageStatManager.cs @@ -43,4 +43,6 @@ public abstract class SpaceUsageStatManager public interface IUserSpaceUsage { Task GetUserSpaceUsageAsync(Guid userId); + + Task RecalculateUserQuota(int tenantId, Guid userId); } From 21075fd4c33613904e37bc88b1c7115b098d4551 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Thu, 13 Oct 2022 17:45:09 +0300 Subject: [PATCH 02/14] Quota: fix --- .../Context/Impl/AuthManager.cs | 6 +++++ .../FilesSpaceUsageStatManager.cs | 5 ++-- .../Core/Core/UsersQuotaSyncOperation.cs | 23 ++++++++----------- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/common/ASC.Core.Common/Context/Impl/AuthManager.cs b/common/ASC.Core.Common/Context/Impl/AuthManager.cs index 80d0c1118b..f45b0980ad 100644 --- a/common/ASC.Core.Common/Context/Impl/AuthManager.cs +++ b/common/ASC.Core.Common/Context/Impl/AuthManager.cs @@ -60,6 +60,12 @@ public class AuthManager public IAccount GetAccountByID(int tenantId, Guid id) { + var tenant = _tenantManager.GetCurrentTenant(false); + if (tenant == null) + { + _tenantManager.SetCurrentTenant(tenantId); + } + var s = Configuration.Constants.SystemAccounts.FirstOrDefault(a => a.ID == id); if (s != null) { diff --git a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs index 00f5b4b94e..e399d38621 100644 --- a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs +++ b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs @@ -132,13 +132,12 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage public async Task RecalculateUserQuota(int TenantId, Guid userId) { - _tenantManager.SetCurrentTenant(TenantId); - + var size = await GetUserSpaceUsageAsync(userId); _tenantManager.SetTenantQuotaRow( new TenantQuotaRow { Tenant = TenantId, Path = $"/{FileConstant.ModuleId}/", Counter = size, Tag = WebItemManager.DocumentsProductID.ToString(), UserId = userId, LastModified = DateTime.UtcNow }, - true); + false); } } diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index a1b08dc8fa..6d22ab92a2 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -82,10 +82,10 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { private readonly IServiceScopeFactory _serviceScopeFactory; private readonly IDaoFactory _daoFactory; - private readonly FilesSpaceUsageStatManager _filesSpaceUsageStatManager; - private readonly WebItemManager _webItemManager; private readonly WebItemManagerSecurity _webItemManagerSecurity; - + private readonly SecurityContext _securityContext; + private readonly AuthManager _authentication; + protected readonly IDbContextFactory _dbContextFactory; @@ -105,16 +105,16 @@ public class UsersQuotaSyncJob : DistributedTaskProgress public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory, IDaoFactory daoFactory, - FilesSpaceUsageStatManager filesSpaceUsageStatManager, - WebItemManager webItemManager, - WebItemManagerSecurity webItemManagerSecurity + WebItemManagerSecurity webItemManagerSecurity, + SecurityContext securityContext, + AuthManager authentication ) { _serviceScopeFactory = serviceScopeFactory; _daoFactory = daoFactory; - _filesSpaceUsageStatManager = filesSpaceUsageStatManager; - _webItemManager = webItemManager; _webItemManagerSecurity = webItemManagerSecurity; + _securityContext = securityContext; + _authentication = authentication; } public void InitJob(Tenant tenant) { @@ -131,16 +131,13 @@ public class UsersQuotaSyncJob : DistributedTaskProgress _tenantManager.SetCurrentTenant(TenantId); - var fileDao = _daoFactory.GetFileDao(); - var users = _userManager.GetUsers(); var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); foreach (var user in users) { - _tenantManager.SetCurrentTenant(TenantId); - var spaceUsage = _filesSpaceUsageStatManager.GetUserSpaceUsageAsync(user.Id); - + var account = _authentication.GetAccountByID(TenantId, user.Id); + _securityContext.AuthenticateMe(account); foreach (var item in webItems) { From d6441948f3891f2bd73914ca9168e3f9da52260e Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Thu, 13 Oct 2022 18:12:04 +0300 Subject: [PATCH 03/14] Quota: fix --- common/ASC.Core.Common/Data/DbQuotaService.cs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/common/ASC.Core.Common/Data/DbQuotaService.cs b/common/ASC.Core.Common/Data/DbQuotaService.cs index 13f410fed1..2371fc5daa 100644 --- a/common/ASC.Core.Common/Data/DbQuotaService.cs +++ b/common/ASC.Core.Common/Data/DbQuotaService.cs @@ -101,12 +101,8 @@ class DbQuotaService : IQuotaService using var coreDbContext = _dbContextFactory.CreateDbContext(); using var tx = coreDbContext.Database.BeginTransaction(); - AddQuota(coreDbContext, Guid.Empty); - if (row.UserId != Guid.Empty) - { - AddQuota(coreDbContext, row.UserId); - } + AddQuota(coreDbContext, row.UserId != Guid.Empty ? row.UserId : Guid.Empty); tx.Commit(); }); From ac0e87e5813a75195afc531706771a87e541b29b Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Wed, 19 Oct 2022 14:48:48 +0300 Subject: [PATCH 04/14] Quota: fix --- products/ASC.People/Server/Api/UserController.cs | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index e77c469881..bc89ad0591 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -58,8 +58,7 @@ public class UserController : PeopleControllerBase private readonly SettingsManager _settingsManager; private readonly RoomLinkService _roomLinkService; private readonly FileSecurity _fileSecurity; - private readonly IQuotaService _quotaService; - private readonly FilesSpaceUsageStatManager _filesSpaceUsageStatManager; + private readonly IQuotaService _quotaService; private readonly UsersQuotaSyncOperation _usersQuotaSyncOperation; private readonly CountManagerChecker _countManagerChecker; private readonly CountUserChecker _countUserChecker; @@ -101,9 +100,7 @@ public class UserController : PeopleControllerBase SettingsManager settingsManager, RoomLinkService roomLinkService, FileSecurity fileSecurity, - - FilesSpaceUsageStatManager filesSpaceUsageStatManager, - UsersQuotaSyncOperation usersQuotaSyncOperation) + UsersQuotaSyncOperation usersQuotaSyncOperation, CountManagerChecker countManagerChecker, CountUserChecker activeUsersChecker, UsersInRoomChecker usersInRoomChecker, @@ -144,7 +141,6 @@ public class UserController : PeopleControllerBase _usersInRoomChecker = usersInRoomChecker; _usersInRoomStatistic = usersInRoomStatistic; _quotaService = quotaService; - _filesSpaceUsageStatManager = filesSpaceUsageStatManager; _usersQuotaSyncOperation = usersQuotaSyncOperation; } From ea86b81c7eeee4d352a9da47d94a3ab3ea1971b6 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Wed, 19 Oct 2022 18:04:31 +0300 Subject: [PATCH 05/14] Quota: fix --- .../Context/Impl/AuthManager.cs | 6 ----- .../FilesSpaceUsageStatManager.cs | 5 ++-- .../Core/Core/UsersQuotaSyncOperation.cs | 25 ++++++------------- web/ASC.Web.Core/SpaceUsageStatManager.cs | 2 +- 4 files changed, 10 insertions(+), 28 deletions(-) diff --git a/common/ASC.Core.Common/Context/Impl/AuthManager.cs b/common/ASC.Core.Common/Context/Impl/AuthManager.cs index f45b0980ad..80d0c1118b 100644 --- a/common/ASC.Core.Common/Context/Impl/AuthManager.cs +++ b/common/ASC.Core.Common/Context/Impl/AuthManager.cs @@ -60,12 +60,6 @@ public class AuthManager public IAccount GetAccountByID(int tenantId, Guid id) { - var tenant = _tenantManager.GetCurrentTenant(false); - if (tenant == null) - { - _tenantManager.SetCurrentTenant(tenantId); - } - var s = Configuration.Constants.SystemAccounts.FirstOrDefault(a => a.ID == id); if (s != null) { diff --git a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs index e399d38621..09d6fac8aa 100644 --- a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs +++ b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs @@ -130,10 +130,9 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage .SumAsync(r => r.ContentLength); } - public async Task RecalculateUserQuota(int TenantId, Guid userId) + public void RecalculateUserQuota(int TenantId, Guid userId) { - - var size = await GetUserSpaceUsageAsync(userId); + var size = GetUserSpaceUsageAsync(userId).Result; _tenantManager.SetTenantQuotaRow( new TenantQuotaRow { Tenant = TenantId, Path = $"/{FileConstant.ModuleId}/", Counter = size, Tag = WebItemManager.DocumentsProductID.ToString(), UserId = userId, LastModified = DateTime.UtcNow }, diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 6d22ab92a2..9ac4cdef4a 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -82,9 +82,6 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { private readonly IServiceScopeFactory _serviceScopeFactory; private readonly IDaoFactory _daoFactory; - private readonly WebItemManagerSecurity _webItemManagerSecurity; - private readonly SecurityContext _securityContext; - private readonly AuthManager _authentication; protected readonly IDbContextFactory _dbContextFactory; @@ -103,24 +100,16 @@ public class UsersQuotaSyncJob : DistributedTaskProgress } } - public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory, - IDaoFactory daoFactory, - WebItemManagerSecurity webItemManagerSecurity, - SecurityContext securityContext, - AuthManager authentication - ) + public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory, IDaoFactory daoFactory) { _serviceScopeFactory = serviceScopeFactory; _daoFactory = daoFactory; - _webItemManagerSecurity = webItemManagerSecurity; - _securityContext = securityContext; - _authentication = authentication; } public void InitJob(Tenant tenant) { TenantId = tenant.Id; } - protected override async void DoJob() + protected override void DoJob() { try { @@ -128,9 +117,10 @@ public class UsersQuotaSyncJob : DistributedTaskProgress var _tenantManager = scope.ServiceProvider.GetRequiredService(); var _userManager = scope.ServiceProvider.GetRequiredService(); - - _tenantManager.SetCurrentTenant(TenantId); - + var _authentication = scope.ServiceProvider.GetRequiredService(); + var _securityContext = scope.ServiceProvider.GetRequiredService(); + var _webItemManagerSecurity = scope.ServiceProvider.GetRequiredService(); + var users = _userManager.GetUsers(); var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); @@ -150,8 +140,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { continue; } - - await manager.RecalculateUserQuota(TenantId, user.Id); + manager.RecalculateUserQuota(TenantId, user.Id); } } diff --git a/web/ASC.Web.Core/SpaceUsageStatManager.cs b/web/ASC.Web.Core/SpaceUsageStatManager.cs index fd2b58b4ca..936ff575ec 100644 --- a/web/ASC.Web.Core/SpaceUsageStatManager.cs +++ b/web/ASC.Web.Core/SpaceUsageStatManager.cs @@ -44,5 +44,5 @@ public interface IUserSpaceUsage { Task GetUserSpaceUsageAsync(Guid userId); - Task RecalculateUserQuota(int tenantId, Guid userId); + void RecalculateUserQuota(int tenantId, Guid userId); } From ea47a3c31ea21ea8265168f891ee8b047a3c0021 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Thu, 20 Oct 2022 14:38:38 +0300 Subject: [PATCH 06/14] Quota: fixed adding quota --- common/ASC.Data.Storage/TenantQuotaController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/common/ASC.Data.Storage/TenantQuotaController.cs b/common/ASC.Data.Storage/TenantQuotaController.cs index 26ac178696..3970a12a7d 100644 --- a/common/ASC.Data.Storage/TenantQuotaController.cs +++ b/common/ASC.Data.Storage/TenantQuotaController.cs @@ -71,6 +71,7 @@ public class TenantQuotaController : IQuotaController CurrentSize += size; } + SetTenantQuotaRow(module, domain, size, dataTag, true, Guid.Empty); SetTenantQuotaRow(module, domain, size, dataTag, true, _authContext.CurrentAccount.ID); } From d2bc57cbb16af7ff39b35555c1caa017a9e7f0e1 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Thu, 20 Oct 2022 14:47:45 +0300 Subject: [PATCH 07/14] Quota: fixed deleting quota --- common/ASC.Data.Storage/TenantQuotaController.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/common/ASC.Data.Storage/TenantQuotaController.cs b/common/ASC.Data.Storage/TenantQuotaController.cs index 3970a12a7d..47c34c9cce 100644 --- a/common/ASC.Data.Storage/TenantQuotaController.cs +++ b/common/ASC.Data.Storage/TenantQuotaController.cs @@ -83,6 +83,7 @@ public class TenantQuotaController : IQuotaController CurrentSize += size; } + SetTenantQuotaRow(module, domain, size, dataTag, true, Guid.Empty); SetTenantQuotaRow(module, domain, size, dataTag, true, _authContext.CurrentAccount.ID); } From 60f2393940a36868c2ea3b17f6932d13244d3c7a Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Thu, 20 Oct 2022 14:53:38 +0300 Subject: [PATCH 08/14] Quota: fix --- common/ASC.Core.Common/Data/DbQuotaService.cs | 2 +- products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/common/ASC.Core.Common/Data/DbQuotaService.cs b/common/ASC.Core.Common/Data/DbQuotaService.cs index 2371fc5daa..f52d347c75 100644 --- a/common/ASC.Core.Common/Data/DbQuotaService.cs +++ b/common/ASC.Core.Common/Data/DbQuotaService.cs @@ -102,7 +102,7 @@ class DbQuotaService : IQuotaService using var tx = coreDbContext.Database.BeginTransaction(); - AddQuota(coreDbContext, row.UserId != Guid.Empty ? row.UserId : Guid.Empty); + AddQuota(coreDbContext, row.UserId); tx.Commit(); }); diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 9ac4cdef4a..5edbc7b146 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -24,9 +24,6 @@ // content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 // International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode -using ASC.Files.Core.Data; -using ASC.Web.Core; - namespace ASC.Web.Files; [Singletone(Additional = typeof(UsersQuotaOperationExtension))] From b33d55cfe73205c8160a4d956115a1550e35f9a3 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Mon, 24 Oct 2022 17:26:29 +0300 Subject: [PATCH 09/14] Quota: fix --- .../Configuration/FilesSpaceUsageStatManager.cs | 5 +++-- .../Core/Core/UsersQuotaSyncOperation.cs | 16 ++++++++-------- web/ASC.Web.Core/SpaceUsageStatManager.cs | 2 +- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs index 09d6fac8aa..83805fb34c 100644 --- a/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs +++ b/products/ASC.Files/Core/Configuration/FilesSpaceUsageStatManager.cs @@ -130,9 +130,10 @@ public class FilesSpaceUsageStatManager : SpaceUsageStatManager, IUserSpaceUsage .SumAsync(r => r.ContentLength); } - public void RecalculateUserQuota(int TenantId, Guid userId) + public async Task RecalculateUserQuota(int TenantId, Guid userId) { - var size = GetUserSpaceUsageAsync(userId).Result; + _tenantManager.SetCurrentTenant(TenantId); + var size = await GetUserSpaceUsageAsync(userId); _tenantManager.SetTenantQuotaRow( new TenantQuotaRow { Tenant = TenantId, Path = $"/{FileConstant.ModuleId}/", Counter = size, Tag = WebItemManager.DocumentsProductID.ToString(), UserId = userId, LastModified = DateTime.UtcNow }, diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 5edbc7b146..ec3d5413cc 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -49,14 +49,14 @@ public class UsersQuotaSyncOperation { item = _serviceProvider.GetRequiredService(); item.InitJob(tenant); - _progressQueue.EnqueueTask(item); + _progressQueue.EnqueueTask(item.RunJobAsync, item); } - item.PublishChanges(); + } - public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory) + public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory, IServiceScopeFactory serviceScopeFactory) { ; _serviceProvider = serviceProvider; @@ -78,7 +78,6 @@ public class UsersQuotaSyncOperation public class UsersQuotaSyncJob : DistributedTaskProgress { private readonly IServiceScopeFactory _serviceScopeFactory; - private readonly IDaoFactory _daoFactory; protected readonly IDbContextFactory _dbContextFactory; @@ -97,16 +96,15 @@ public class UsersQuotaSyncJob : DistributedTaskProgress } } - public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory, IDaoFactory daoFactory) + public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory) { _serviceScopeFactory = serviceScopeFactory; - _daoFactory = daoFactory; } public void InitJob(Tenant tenant) { TenantId = tenant.Id; } - protected override void DoJob() + public async Task RunJobAsync(DistributedTask _, CancellationToken cancellationToken) { try { @@ -117,6 +115,8 @@ public class UsersQuotaSyncJob : DistributedTaskProgress var _authentication = scope.ServiceProvider.GetRequiredService(); var _securityContext = scope.ServiceProvider.GetRequiredService(); var _webItemManagerSecurity = scope.ServiceProvider.GetRequiredService(); + + _tenantManager.SetCurrentTenant(TenantId); var users = _userManager.GetUsers(); var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); @@ -137,7 +137,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { continue; } - manager.RecalculateUserQuota(TenantId, user.Id); + await manager.RecalculateUserQuota(TenantId, user.Id); } } diff --git a/web/ASC.Web.Core/SpaceUsageStatManager.cs b/web/ASC.Web.Core/SpaceUsageStatManager.cs index 936ff575ec..fd2b58b4ca 100644 --- a/web/ASC.Web.Core/SpaceUsageStatManager.cs +++ b/web/ASC.Web.Core/SpaceUsageStatManager.cs @@ -44,5 +44,5 @@ public interface IUserSpaceUsage { Task GetUserSpaceUsageAsync(Guid userId); - void RecalculateUserQuota(int tenantId, Guid userId); + Task RecalculateUserQuota(int tenantId, Guid userId); } From 4ad83e725878950b8a6f005d38d696a99f879638 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Tue, 25 Oct 2022 17:31:25 +0300 Subject: [PATCH 10/14] Quota: quota recalculation check function --- common/ASC.Api.Core/Model/TaskProgressDto.cs | 43 +++++++++++++++++++ .../Core/Core/UsersQuotaSyncOperation.cs | 28 +++++++++++- products/ASC.Files/Core/GlobalUsings.cs | 2 + .../ASC.People/Server/Api/UserController.cs | 7 +++ products/ASC.People/Server/GlobalUsings.cs | 1 + 5 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 common/ASC.Api.Core/Model/TaskProgressDto.cs diff --git a/common/ASC.Api.Core/Model/TaskProgressDto.cs b/common/ASC.Api.Core/Model/TaskProgressDto.cs new file mode 100644 index 0000000000..6985c942f6 --- /dev/null +++ b/common/ASC.Api.Core/Model/TaskProgressDto.cs @@ -0,0 +1,43 @@ +// (c) Copyright Ascensio System SIA 2010-2022 +// +// This program is a free software product. +// You can redistribute it and/or modify it under the terms +// of the GNU Affero General Public License (AGPL) version 3 as published by the Free Software +// Foundation. In accordance with Section 7(a) of the GNU AGPL its Section 15 shall be amended +// to the effect that Ascensio System SIA expressly excludes the warranty of non-infringement of +// any third-party rights. +// +// This program is distributed WITHOUT ANY WARRANTY, without even the implied warranty +// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. For details, see +// the GNU AGPL at: http://www.gnu.org/licenses/agpl-3.0.html +// +// You can contact Ascensio System SIA at Lubanas st. 125a-25, Riga, Latvia, EU, LV-1021. +// +// The interactive user interfaces in modified source and object code versions of the Program must +// display Appropriate Legal Notices, as required under Section 5 of the GNU AGPL version 3. +// +// Pursuant to Section 7(b) of the License you must retain the original Product logo when +// distributing the program. Pursuant to Section 7(e) we decline to grant you any rights under +// trademark law for use of our trademarks. +// +// All the Product's GUI elements, including illustrations and icon sets, as well as technical writing +// content are licensed under the terms of the Creative Commons Attribution-ShareAlike 4.0 +// International. See the License terms at http://creativecommons.org/licenses/by-sa/4.0/legalcode + +namespace ASC.Api.Core.Model; +public class TaskProgressDto +{ + public bool IsCompleted { get; set; } + public int Progress { get; set; } + + public static TaskProgressDto GetSample() + { + return new TaskProgressDto + { + IsCompleted = true, + Progress = 0 + }; + } +} + + diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index ec3d5413cc..95644996e8 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -51,8 +51,27 @@ public class UsersQuotaSyncOperation item.InitJob(tenant); _progressQueue.EnqueueTask(item.RunJobAsync, item); } + } + public TaskProgressDto CheckRecalculateQuota(Tenant tenant) + { + var item = _progressQueue.GetAllTasks().FirstOrDefault(t => t.TenantId == tenant.Id); + var progress = new TaskProgressDto(); + if (item == null) + { + progress.IsCompleted = true; + return progress; + } + progress.IsCompleted = item.IsCompleted; + progress.Progress = (int)item.Percentage; + + if (item.IsCompleted) + { + _progressQueue.DequeueTask(item.Id); + } + + return progress; } @@ -121,9 +140,14 @@ public class UsersQuotaSyncJob : DistributedTaskProgress var users = _userManager.GetUsers(); var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); + var _user = users.FirstOrDefault(); + foreach (var user in users) { - var account = _authentication.GetAccountByID(TenantId, user.Id); + Percentage += 1.0 * 100 / users.Length; + PublishChanges(); + + var account = _authentication.GetAccountByID(TenantId, _user.Id); _securityContext.AuthenticateMe(account); foreach (var item in webItems) @@ -137,7 +161,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { continue; } - await manager.RecalculateUserQuota(TenantId, user.Id); + await manager.RecalculateUserQuota(TenantId, _user.Id); } } diff --git a/products/ASC.Files/Core/GlobalUsings.cs b/products/ASC.Files/Core/GlobalUsings.cs index 1689a3ab93..2049f1a21f 100644 --- a/products/ASC.Files/Core/GlobalUsings.cs +++ b/products/ASC.Files/Core/GlobalUsings.cs @@ -54,6 +54,7 @@ global using AppLimit.CloudComputing.SharpBox.StorageProvider.DropBox; global using ASC.Api.Collections; global using ASC.Api.Core; +global using ASC.Api.Core.Model; global using ASC.Api.Core.Security; global using ASC.Api.Utils; global using ASC.AuditTrail; @@ -150,6 +151,7 @@ global using ASC.Web.Files.Services.WCFService.FileOperations; global using ASC.Web.Files.ThirdPartyApp; global using ASC.Web.Files.Utils; global using ASC.Web.Studio.Core; +global using ASC.Web.Studio.Core.Quota; global using ASC.Web.Studio.Core.Notify; global using ASC.Web.Studio.Utility; diff --git a/products/ASC.People/Server/Api/UserController.cs b/products/ASC.People/Server/Api/UserController.cs index bc89ad0591..1140d46b95 100644 --- a/products/ASC.People/Server/Api/UserController.cs +++ b/products/ASC.People/Server/Api/UserController.cs @@ -1073,6 +1073,13 @@ public class UserController : PeopleControllerBase _usersQuotaSyncOperation.RecalculateQuota(_tenantManager.GetCurrentTenant()); } + [HttpGet("checkrecalculatequota")] + public TaskProgressDto CheckRecalculateQuota() + { + _permissionContext.DemandPermissions(SecutiryConstants.EditPortalSettings); + return _usersQuotaSyncOperation.CheckRecalculateQuota(_tenantManager.GetCurrentTenant()); + } + [HttpPut("quota")] public async IAsyncEnumerable UpdateUserQuota(UpdateMembersQuotaRequestDto inDto) { diff --git a/products/ASC.People/Server/GlobalUsings.cs b/products/ASC.People/Server/GlobalUsings.cs index 8e11fc0f82..6d028ab8e7 100644 --- a/products/ASC.People/Server/GlobalUsings.cs +++ b/products/ASC.People/Server/GlobalUsings.cs @@ -31,6 +31,7 @@ global using System.ServiceModel.Security; global using System.Web; global using ASC.Api.Core; +global using ASC.Api.Core.Model; global using ASC.Api.Core.Convention; global using ASC.Api.Core.Extensions; global using ASC.Api.Utils; From aac059274e88aad3ca18331a9bf47134196025aa Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Thu, 27 Oct 2022 17:44:20 +0300 Subject: [PATCH 11/14] Quota: fix --- products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 95644996e8..902d7f9c18 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -140,14 +140,12 @@ public class UsersQuotaSyncJob : DistributedTaskProgress var users = _userManager.GetUsers(); var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); - var _user = users.FirstOrDefault(); - foreach (var user in users) { Percentage += 1.0 * 100 / users.Length; PublishChanges(); - var account = _authentication.GetAccountByID(TenantId, _user.Id); + var account = _authentication.GetAccountByID(TenantId, user.Id); _securityContext.AuthenticateMe(account); foreach (var item in webItems) From e197a7b506226c27c0faf6ac2eb9c0570d6e77b9 Mon Sep 17 00:00:00 2001 From: Nikolay Rechkin Date: Fri, 28 Oct 2022 17:35:22 +0300 Subject: [PATCH 12/14] Quota: fix --- products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 902d7f9c18..6607c68da9 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -159,7 +159,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { continue; } - await manager.RecalculateUserQuota(TenantId, _user.Id); + await manager.RecalculateUserQuota(TenantId, user.Id); } } From 7d1717ac3e1a4bfeb3da3543e7e23a52a86eef45 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Wed, 2 Nov 2022 14:06:05 +0300 Subject: [PATCH 13/14] fix --- .../Core/Core/UsersQuotaSyncOperation.cs | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 6607c68da9..1beeea3d86 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -75,11 +75,9 @@ public class UsersQuotaSyncOperation } - public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory, IServiceScopeFactory serviceScopeFactory) + public UsersQuotaSyncOperation(IServiceProvider serviceProvider, IDistributedTaskQueueFactory queueFactory) { - ; _serviceProvider = serviceProvider; - _progressQueue = queueFactory.CreateQueue(CUSTOM_DISTRIBUTED_TASK_QUEUE_NAME); } @@ -118,11 +116,13 @@ public class UsersQuotaSyncJob : DistributedTaskProgress public UsersQuotaSyncJob(IServiceScopeFactory serviceScopeFactory) { _serviceScopeFactory = serviceScopeFactory; - } + } + public void InitJob(Tenant tenant) { TenantId = tenant.Id; - } + } + public async Task RunJobAsync(DistributedTask _, CancellationToken cancellationToken) { try @@ -135,13 +135,20 @@ public class UsersQuotaSyncJob : DistributedTaskProgress var _securityContext = scope.ServiceProvider.GetRequiredService(); var _webItemManagerSecurity = scope.ServiceProvider.GetRequiredService(); - _tenantManager.SetCurrentTenant(TenantId); - + _tenantManager.SetCurrentTenant(TenantId); + var users = _userManager.GetUsers(); var webItems = _webItemManagerSecurity.GetItems(Web.Core.WebZones.WebZoneType.All, ItemAvailableState.All); foreach (var user in users) - { + { + if (cancellationToken.IsCancellationRequested) + { + IsCompleted = true; + Status = DistributedTaskStatus.Canceled; + return; + } + Percentage += 1.0 * 100 / users.Length; PublishChanges(); @@ -149,7 +156,14 @@ public class UsersQuotaSyncJob : DistributedTaskProgress _securityContext.AuthenticateMe(account); foreach (var item in webItems) - { + { + if (cancellationToken.IsCancellationRequested) + { + IsCompleted = true; + Status = DistributedTaskStatus.Canceled; + return; + } + IUserSpaceUsage manager; if (item.ID == WebItemManager.DocumentsProductID) From 07937d9bebe916de9327824e36225da2cd201795 Mon Sep 17 00:00:00 2001 From: pavelbannov Date: Wed, 2 Nov 2022 14:07:27 +0300 Subject: [PATCH 14/14] fix --- .../ASC.Files/Core/Core/UsersQuotaSyncOperation.cs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs index 1beeea3d86..55c334b9df 100644 --- a/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs +++ b/products/ASC.Files/Core/Core/UsersQuotaSyncOperation.cs @@ -144,9 +144,8 @@ public class UsersQuotaSyncJob : DistributedTaskProgress { if (cancellationToken.IsCancellationRequested) { - IsCompleted = true; Status = DistributedTaskStatus.Canceled; - return; + break; } Percentage += 1.0 * 100 / users.Length; @@ -156,14 +155,7 @@ public class UsersQuotaSyncJob : DistributedTaskProgress _securityContext.AuthenticateMe(account); foreach (var item in webItems) - { - if (cancellationToken.IsCancellationRequested) - { - IsCompleted = true; - Status = DistributedTaskStatus.Canceled; - return; - } - + { IUserSpaceUsage manager; if (item.ID == WebItemManager.DocumentsProductID)