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) {