From 4dcd9be0411851c3cb410e3e61de8a51b3c35f91 Mon Sep 17 00:00:00 2001 From: MaksimChegulov Date: Thu, 25 Aug 2022 13:29:08 +0300 Subject: [PATCH 1/2] fix: removed IOptionsSnapshot --- .../LoginProviders/EncryptionLoginProvider.cs | 12 +++++------- .../ASC.Files/Core/ThirdPartyApp/BoxApp.cs | 13 ++++++------- .../Core/ThirdPartyApp/GoogleDriveApp.cs | 19 +++++++++---------- .../Server/Api/ThirdpartyController.cs | 17 ++++++----------- .../Api/AuthenticationController.cs | 9 ++++----- 5 files changed, 30 insertions(+), 40 deletions(-) diff --git a/common/ASC.FederatedLogin/LoginProviders/EncryptionLoginProvider.cs b/common/ASC.FederatedLogin/LoginProviders/EncryptionLoginProvider.cs index 4ab6aec3fe..a2e1d63568 100644 --- a/common/ASC.FederatedLogin/LoginProviders/EncryptionLoginProvider.cs +++ b/common/ASC.FederatedLogin/LoginProviders/EncryptionLoginProvider.cs @@ -33,20 +33,20 @@ public class EncryptionLoginProvider private readonly SecurityContext _securityContext; private readonly Signature _signature; private readonly InstanceCrypto _instanceCrypto; - private readonly IOptionsSnapshot _snapshot; + private readonly AccountLinker _accountLinker; public EncryptionLoginProvider( ILogger logger, SecurityContext securityContext, Signature signature, InstanceCrypto instanceCrypto, - IOptionsSnapshot snapshot) + AccountLinker accountLinker) { _logger = logger; _securityContext = securityContext; _signature = signature; _instanceCrypto = instanceCrypto; - _snapshot = snapshot; + _accountLinker = accountLinker; } @@ -63,8 +63,7 @@ public class EncryptionLoginProvider Name = _instanceCrypto.Encrypt(keys) }; - var linker = _snapshot.Get("webstudio"); - linker.AddLink(userId.ToString(), loginProfile); + _accountLinker.AddLink(userId.ToString(), loginProfile); } public string GetKeys() @@ -74,8 +73,7 @@ public class EncryptionLoginProvider public string GetKeys(Guid userId) { - var linker = _snapshot.Get("webstudio"); - var profile = linker.GetLinkedProfiles(userId.ToString(), ProviderConstants.Encryption).FirstOrDefault(); + var profile = _accountLinker.GetLinkedProfiles(userId.ToString(), ProviderConstants.Encryption).FirstOrDefault(); if (profile == null) { return null; diff --git a/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs b/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs index 761cb5e43b..d715c07e03 100644 --- a/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs +++ b/products/ASC.Files/Core/ThirdPartyApp/BoxApp.cs @@ -57,7 +57,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider private readonly SettingsManager _settingsManager; private readonly PersonalSettingsHelper _personalSettingsHelper; private readonly BaseCommonLinkUtility _baseCommonLinkUtility; - private readonly IOptionsSnapshot _snapshot; + private readonly AccountLinker _accountLinker; private readonly SetupInfo _setupInfo; private readonly TokenHelper _tokenHelper; private readonly DocumentServiceConnector _documentServiceConnector; @@ -85,7 +85,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider SettingsManager settingsManager, PersonalSettingsHelper personalSettingsHelper, BaseCommonLinkUtility baseCommonLinkUtility, - IOptionsSnapshot snapshot, + AccountLinker accountLinker, SetupInfo setupInfo, TokenHelper tokenHelper, DocumentServiceConnector documentServiceConnector, @@ -117,7 +117,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider _settingsManager = settingsManager; _personalSettingsHelper = personalSettingsHelper; _baseCommonLinkUtility = baseCommonLinkUtility; - _snapshot = snapshot; + _accountLinker = accountLinker; _setupInfo = setupInfo; _tokenHelper = tokenHelper; _documentServiceConnector = documentServiceConnector; @@ -465,8 +465,7 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider private bool CurrentUser(string boxUserId) { - var linkedProfiles = _snapshot.Get("webstudio") - .GetLinkedObjectsByHashId(HashHelper.MD5($"{ProviderConstants.Box}/{boxUserId}")); + var linkedProfiles = _accountLinker.GetLinkedObjectsByHashId(HashHelper.MD5($"{ProviderConstants.Box}/{boxUserId}")); return linkedProfiles.Any(profileId => Guid.TryParse(profileId, out var tmp) && tmp == _authContext.CurrentAccount.ID); } @@ -474,8 +473,8 @@ public class BoxApp : Consumer, IThirdPartyApp, IOAuthProvider private void AddLinker(string boxUserId) { _logger.DebugBoxAppAddLinker(boxUserId); - var linker = _snapshot.Get("webstudio"); - linker.AddLink(_authContext.CurrentAccount.ID.ToString(), boxUserId, ProviderConstants.Box); + + _accountLinker.AddLink(_authContext.CurrentAccount.ID.ToString(), boxUserId, ProviderConstants.Box); } private UserInfo GetUserInfo(Token token, out bool isNew) diff --git a/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs b/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs index a32a92d334..f658b74091 100644 --- a/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs +++ b/products/ASC.Files/Core/ThirdPartyApp/GoogleDriveApp.cs @@ -63,7 +63,7 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider private readonly BaseCommonLinkUtility _baseCommonLinkUtility; private readonly FileUtility _fileUtility; private readonly FilesSettingsHelper _filesSettingsHelper; - private readonly IOptionsSnapshot _snapshot; + private readonly AccountLinker _accountLinker; private readonly SetupInfo _setupInfo; private readonly GoogleLoginProvider _googleLoginProvider; private readonly TokenHelper _tokenHelper; @@ -97,7 +97,7 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider ILogger logger, FileUtility fileUtility, FilesSettingsHelper filesSettingsHelper, - IOptionsSnapshot snapshot, + AccountLinker accountLinker, SetupInfo setupInfo, GoogleLoginProvider googleLoginProvider, TokenHelper tokenHelper, @@ -111,9 +111,9 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider ICacheNotify cache, ConsumerFactory consumerFactory, IHttpClientFactory clientFactory, - OAuth20TokenHelper oAuth20TokenHelper, - RequestHelper requestHelper, - ThirdPartySelector thirdPartySelector, + OAuth20TokenHelper oAuth20TokenHelper, + RequestHelper requestHelper, + ThirdPartySelector thirdPartySelector, string name, int order, Dictionary additional) : base(tenantManager, coreBaseSettings, coreSettings, configuration, cache, consumerFactory, name, order, additional) { @@ -135,7 +135,7 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider _baseCommonLinkUtility = baseCommonLinkUtility; _fileUtility = fileUtility; _filesSettingsHelper = filesSettingsHelper; - _snapshot = snapshot; + _accountLinker = accountLinker; _setupInfo = setupInfo; _googleLoginProvider = googleLoginProvider; _tokenHelper = tokenHelper; @@ -618,8 +618,7 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider private bool CurrentUser(string googleId) { - var linker = _snapshot.Get("webstudio"); - var linkedProfiles = linker.GetLinkedObjectsByHashId(HashHelper.MD5($"{ProviderConstants.Google}/{googleId}")); + var linkedProfiles = _accountLinker.GetLinkedObjectsByHashId(HashHelper.MD5($"{ProviderConstants.Google}/{googleId}")); return linkedProfiles.Any(profileId => Guid.TryParse(profileId, out var tmp) && tmp == _authContext.CurrentAccount.ID); } @@ -627,8 +626,8 @@ public class GoogleDriveApp : Consumer, IThirdPartyApp, IOAuthProvider private void AddLinker(string googleUserId) { _logger.DebugGoogleDriveApAddLinker(googleUserId); - var linker = _snapshot.Get("webstudio"); - linker.AddLink(_authContext.CurrentAccount.ID.ToString(), googleUserId, ProviderConstants.Google); + + _accountLinker.AddLink(_authContext.CurrentAccount.ID.ToString(), googleUserId, ProviderConstants.Google); } private UserInfo GetUserInfo(Token token, out bool isNew) diff --git a/products/ASC.People/Server/Api/ThirdpartyController.cs b/products/ASC.People/Server/Api/ThirdpartyController.cs index 099d5d005d..be876c1c25 100644 --- a/products/ASC.People/Server/Api/ThirdpartyController.cs +++ b/products/ASC.People/Server/Api/ThirdpartyController.cs @@ -30,7 +30,7 @@ namespace ASC.People.Api; public class ThirdpartyController : ApiControllerBase { - private readonly IOptionsSnapshot _accountLinker; + private readonly AccountLinker _accountLinker; private readonly CookiesManager _cookiesManager; private readonly CoreBaseSettings _coreBaseSettings; private readonly DisplayUserSettingsHelper _displayUserSettingsHelper; @@ -52,7 +52,7 @@ public class ThirdpartyController : ApiControllerBase private readonly StudioNotifyService _studioNotifyService; public ThirdpartyController( - IOptionsSnapshot accountLinker, + AccountLinker accountLinker, CookiesManager cookiesManager, CoreBaseSettings coreBaseSettings, DisplayUserSettingsHelper displayUserSettingsHelper, @@ -104,7 +104,7 @@ public class ThirdpartyController : ApiControllerBase if (_authContext.IsAuthenticated) { - linkedAccounts = _accountLinker.Get("webstudio").GetLinkedProfiles(_authContext.CurrentAccount.ID.ToString()); + linkedAccounts = _accountLinker.GetLinkedProfiles(_authContext.CurrentAccount.ID.ToString()); } fromOnly = string.IsNullOrWhiteSpace(fromOnly) ? string.Empty : fromOnly.ToLower(); @@ -148,7 +148,7 @@ public class ThirdpartyController : ApiControllerBase if (string.IsNullOrEmpty(profile.AuthorizationError)) { - GetLinker().AddLink(_securityContext.CurrentAccount.ID.ToString(), profile); + _accountLinker.AddLink(_securityContext.CurrentAccount.ID.ToString(), profile); _messageService.Send(MessageAction.UserLinkedSocialAccount, GetMeaningfulProviderName(profile.Provider)); } else @@ -204,7 +204,7 @@ public class ThirdpartyController : ApiControllerBase SaveContactImage(userID, thirdPartyProfile.Avatar); } - GetLinker().AddLink(userID.ToString(), thirdPartyProfile); + _accountLinker.AddLink(userID.ToString(), thirdPartyProfile); } finally { @@ -232,7 +232,7 @@ public class ThirdpartyController : ApiControllerBase [HttpDelete("thirdparty/unlinkaccount")] public void UnlinkAccount(string provider) { - GetLinker().RemoveProvider(_securityContext.CurrentAccount.ID.ToString(), provider); + _accountLinker.RemoveProvider(_securityContext.CurrentAccount.ID.ToString(), provider); _messageService.Send(MessageAction.UserUnlinkedSocialAccount, GetMeaningfulProviderName(provider)); } @@ -262,11 +262,6 @@ public class ThirdpartyController : ApiControllerBase return _userManagerWrapper.AddUser(userInfo, passwordHash, true, true, isVisitor, fromInviteLink); } - private AccountLinker GetLinker() - { - return _accountLinker.Get("webstudio"); - } - private void SaveContactImage(Guid userID, string url) { using (var memstream = new MemoryStream()) diff --git a/web/ASC.Web.Api/Api/AuthenticationController.cs b/web/ASC.Web.Api/Api/AuthenticationController.cs index e9de9d48ea..8c197fa9e4 100644 --- a/web/ASC.Web.Api/Api/AuthenticationController.cs +++ b/web/ASC.Web.Api/Api/AuthenticationController.cs @@ -46,7 +46,7 @@ public class AuthenticationController : ControllerBase private readonly SetupInfo _setupInfo; private readonly MessageService _messageService; private readonly ProviderManager _providerManager; - private readonly IOptionsSnapshot _accountLinker; + private readonly AccountLinker _accountLinker; private readonly CoreBaseSettings _coreBaseSettings; private readonly PersonalSettingsHelper _personalSettingsHelper; private readonly StudioNotifyService _studioNotifyService; @@ -80,7 +80,7 @@ public class AuthenticationController : ControllerBase SetupInfo setupInfo, MessageService messageService, ProviderManager providerManager, - IOptionsSnapshot accountLinker, + AccountLinker accountLinker, CoreBaseSettings coreBaseSettings, PersonalSettingsHelper personalSettingsHelper, StudioNotifyService studioNotifyService, @@ -534,8 +534,7 @@ public class AuthenticationController : ControllerBase } } - var linker = _accountLinker.Get("webstudio"); - linker.AddLink(userInfo.Id.ToString(), loginProfile); + _accountLinker.AddLink(userInfo.Id.ToString(), loginProfile); return userInfo; } @@ -581,7 +580,7 @@ public class AuthenticationController : ControllerBase return false; } - var linkedProfiles = _accountLinker.Get("webstudio").GetLinkedObjectsByHashId(hashId); + var linkedProfiles = _accountLinker.GetLinkedObjectsByHashId(hashId); var tmp = Guid.Empty; if (linkedProfiles.Any(profileId => Guid.TryParse(profileId, out tmp) && _userManager.UserExists(tmp))) { From ff8e3c38e9b161acadb89f459a42c087407a8d2b Mon Sep 17 00:00:00 2001 From: MaksimChegulov Date: Thu, 25 Aug 2022 13:54:11 +0300 Subject: [PATCH 2/2] removed unnecessary --- .../Caching/CachedUserService.cs | 36 ------------------- .../Context/Impl/CoreConfiguration.cs | 33 +---------------- common/ASC.Core.Common/Tenants/TenantUtil.cs | 28 --------------- 3 files changed, 1 insertion(+), 96 deletions(-) diff --git a/common/ASC.Core.Common/Caching/CachedUserService.cs b/common/ASC.Core.Common/Caching/CachedUserService.cs index 17d433a1a5..b8e8f7a0c5 100644 --- a/common/ASC.Core.Common/Caching/CachedUserService.cs +++ b/common/ASC.Core.Common/Caching/CachedUserService.cs @@ -134,42 +134,6 @@ public class UserServiceCache } } -[Scope] -class ConfigureCachedUserService : IConfigureNamedOptions -{ - internal readonly IOptionsSnapshot Service; - internal readonly UserServiceCache UserServiceCache; - internal readonly CoreBaseSettings CoreBaseSettings; - - public ConfigureCachedUserService( - IOptionsSnapshot service, - UserServiceCache userServiceCache, - CoreBaseSettings coreBaseSettings) - { - Service = service; - UserServiceCache = userServiceCache; - CoreBaseSettings = coreBaseSettings; - } - - public void Configure(string name, CachedUserService options) - { - Configure(options); - options.Service = Service.Get(name); - } - - public void Configure(CachedUserService options) - { - options.Service = Service.Value; - options.CoreBaseSettings = CoreBaseSettings; - options.UserServiceCache = UserServiceCache; - options.Cache = UserServiceCache.Cache; - options.CacheUserInfoItem = UserServiceCache.CacheUserInfoItem; - options.CacheUserPhotoItem = UserServiceCache.CacheUserPhotoItem; - options.CacheGroupCacheItem = UserServiceCache.CacheGroupCacheItem; - options.CacheUserGroupRefItem = UserServiceCache.CacheUserGroupRefItem; - } -} - [Scope] public class CachedUserService : IUserService, ICachedService { diff --git a/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs b/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs index 77f6f291cb..010ce6e141 100644 --- a/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs +++ b/common/ASC.Core.Common/Context/Impl/CoreConfiguration.cs @@ -66,38 +66,7 @@ public class CoreBaseSettings public bool DisableDocSpace => _disableDocSpace ?? (bool)(_disableDocSpace = string.Equals(Configuration["core:disableDocspace"], "true", StringComparison.OrdinalIgnoreCase)); } -class ConfigureCoreSettings : IConfigureNamedOptions -{ - private readonly IOptionsSnapshot _tenantService; - private readonly CoreBaseSettings _coreBaseSettings; - private readonly IConfiguration _configuration; - - public ConfigureCoreSettings( - IOptionsSnapshot tenantService, - CoreBaseSettings coreBaseSettings, - IConfiguration configuration - ) - { - _tenantService = tenantService; - _coreBaseSettings = coreBaseSettings; - _configuration = configuration; - } - - public void Configure(string name, CoreSettings options) - { - Configure(options); - options.TenantService = _tenantService.Get(name); - } - - public void Configure(CoreSettings options) - { - options.Configuration = _configuration; - options.CoreBaseSettings = _coreBaseSettings; - options.TenantService = _tenantService.Value; - } -} - -[Scope(typeof(ConfigureCoreSettings))] +[Scope] public class CoreSettings { public string BaseDomain diff --git a/common/ASC.Core.Common/Tenants/TenantUtil.cs b/common/ASC.Core.Common/Tenants/TenantUtil.cs index 30c77bb27f..fea42b4294 100644 --- a/common/ASC.Core.Common/Tenants/TenantUtil.cs +++ b/common/ASC.Core.Common/Tenants/TenantUtil.cs @@ -27,34 +27,6 @@ namespace ASC.Core.Tenants; [Scope] -class ConfigureTenantUtil : IConfigureNamedOptions -{ - private readonly IOptionsSnapshot _tenantManager; - private readonly TimeZoneConverter _timeZoneConverter; - - public ConfigureTenantUtil( - IOptionsSnapshot tenantManager, - TimeZoneConverter timeZoneConverter - ) - { - _tenantManager = tenantManager; - _timeZoneConverter = timeZoneConverter; - } - - public void Configure(string name, TenantUtil options) - { - Configure(options); - options._tenantManager = _tenantManager.Get(name); - } - - public void Configure(TenantUtil options) - { - options._timeZoneConverter = _timeZoneConverter; - options._tenantManager = _tenantManager.Value; - } -} - -[Scope(typeof(ConfigureTenantUtil))] public class TenantUtil { internal TenantManager _tenantManager;