From b176c8ca9b92c11b7046b1aa291d90434f189b8c Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 29 May 2024 10:24:07 -0700 Subject: [PATCH 1/8] Add helpful SiteService extension --- .../Services/AuditTrailBackgroundTask.cs | 2 +- .../ContentRequestCultureProvider.cs | 2 +- .../Controllers/ContentCulturePickerController.cs | 2 +- .../OrchardCore.Contents/AdminMenu.cs | 2 +- .../AuditTrail/Handlers/AuditTrailContentHandler.cs | 3 +-- .../ExportContentToDeploymentTargetContentDriver.cs | 8 ++++---- ...DeploymentTargetContentsAdminListDisplayDriver.cs | 4 ++-- .../OrchardCore.Cors/Services/CorsService.cs | 3 +-- .../Services/AzureEmailOptionsConfiguration.cs | 5 ++--- .../Services/SmtpOptionsConfiguration.cs | 6 +++--- .../OrchardCore.Email/Migrations/EmailMigrations.cs | 4 +--- .../Filters/FacebookPixelFilter.cs | 2 +- .../Login/Services/FacebookLoginService.cs | 5 ++--- .../OrchardCore.Facebook/ScriptsMiddleware.cs | 4 ++-- .../OrchardCore.Facebook/Services/FacebookService.cs | 5 ++--- .../Views/FacebookPluginPart.Summary.cshtml | 4 ++-- .../Views/FacebookPluginPart.cshtml | 4 ++-- .../Services/GithubAuthenticationService.cs | 5 ++--- .../Analytics/GoogleAnalyticsFilter.cs | 2 +- .../Analytics/Services/GoogleAnalyticsService.cs | 5 ++--- .../TagManager/GoogleTagManagerFilter.cs | 2 +- .../TagManager/Services/GoogleTagManagerService.cs | 5 ++--- .../OrchardCore.Https/Services/HttpsService.cs | 5 ++--- .../Controllers/AdminController.cs | 3 +-- .../Deployment/AllLayersDeploymentSource.cs | 4 ++-- .../Services/LocalizationService.cs | 6 +----- .../Processing/MediaTokenOptionsConfiguration.cs | 6 +++--- .../Processing/MediaTokenSettingsUpdater.cs | 2 +- .../Services/AzureADService.cs | 5 ++--- .../Services/MicrosoftAccountService.cs | 5 ++--- .../Services/OpenIdClientService.cs | 5 ++--- .../ReCaptchaForgotPasswordFormDisplayDriver.cs | 2 +- .../Drivers/ReCaptchaLoginFormDisplayDriver.cs | 2 +- .../ReCaptchaResetPasswordFormDisplayDriver.cs | 2 +- .../Drivers/RegisterUserFormDisplayDriver.cs | 2 +- .../Forms/ReCaptchaPartDisplayDriver.cs | 6 ++---- .../Services/ReverseProxyService.cs | 5 ++--- .../Handlers/ElasticsearchAuthorizationHandler.cs | 3 +-- .../Services/ElasticSearchService.cs | 3 +-- .../Handler/LuceneAuthorizationHandler.cs | 3 +-- .../Services/LuceneIndexingService.cs | 12 ++---------- .../Services/LuceneSearchService.cs | 4 +--- .../Controllers/SearchController.cs | 4 +--- .../Deployment/SearchSettingsDeploymentSource.cs | 7 +++---- .../Services/SearchSettingsConfiguration.cs | 10 +++++----- .../OrchardCore.Security/Services/SecurityService.cs | 6 ++---- .../Services/SiteSettingsRobotsProvider.cs | 2 +- .../PagerOptionsConfiguration.cs | 4 +++- .../ResourceOptionsConfiguration.cs | 4 +++- .../TaxonomyContentsAdminListDisplayDriver.cs | 4 ++-- .../Services/TaxonomyContentsAdminListFilter.cs | 2 +- .../Drivers/ToggleThemeNavbarDisplayDriver.cs | 2 +- .../Services/ThemeTogglerService.cs | 2 +- .../Services/TwitterSettingsService.cs | 5 ++--- .../Signin/Services/TwitterSigninService.cs | 5 ++--- .../Controllers/AccountController.cs | 12 ++++++------ .../Controllers/AuthenticatorAppController.cs | 4 ++-- .../Controllers/ChangeEmailController.cs | 4 ++-- .../Controllers/RegistrationController.cs | 4 ++-- .../Controllers/ResetPasswordController.cs | 10 +++++----- .../Controllers/SmsAuthenticatorController.cs | 6 +++--- .../TwoFactorAuthenticationBaseController.cs | 2 +- .../Controllers/TwoFactorAuthenticationController.cs | 6 +++--- .../Drivers/ForgotPasswordLoginFormDisplayDriver.cs | 2 +- .../Drivers/RegisterUserLoginFormDisplayDriver.cs | 2 +- .../Drivers/UserInformationDisplayDriver.cs | 6 ++---- .../Endpoints/EmailAuthenticator/SendCode.cs | 2 +- .../Endpoints/SmsAuthenticator/SendCode.cs | 4 ++-- .../Extensions/ControllerExtensions.cs | 2 +- .../Handlers/ScriptExternalLoginEventHandler.cs | 4 ++-- .../Services/IdentityOptionsConfigurations.cs | 6 +++--- .../Services/RoleTwoFactorAuthenticationHandler.cs | 2 +- .../OrchardCore.Users/Services/UsersThemeSelector.cs | 12 ++++++------ .../OrchardCore.Users/Views/Account/Login.cshtml | 2 +- .../Services/EmailOptionsConfiguration.cs | 6 +++--- .../Settings/SiteServiceExtensions.cs | 11 +++++++++++ .../Configuration/ReCaptchaSettingsConfiguration.cs | 6 +++--- .../AzureAISearchSettingsDeploymentSource.cs | 4 +--- .../Handlers/AzureAISearchAuthorizationHandler.cs | 3 +-- .../AzureAISearchDefaultOptionsConfigurations.cs | 3 +-- .../Services/AzureAISearchService.cs | 3 +-- .../Services/ElasticIndexingService.cs | 10 ++-------- .../SiteSettingsPropertyDeploymentSource.cs | 4 +--- .../Services/DefaultSmsProviderResolver.cs | 4 +--- .../Services/SmsSettingsConfiguration.cs | 6 +++--- .../Services/TwilioProviderOptionsConfigurations.cs | 5 +++-- .../Services/TwilioSmsProvider.cs | 2 +- .../DefaultTwoFactorAuthenticationHandler.cs | 2 +- .../OrchardCore.Users.Core/Services/UserService.cs | 2 +- 89 files changed, 173 insertions(+), 216 deletions(-) create mode 100644 src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs diff --git a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs index f9a40a7bb1b..b7e228a5cb3 100644 --- a/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs +++ b/src/OrchardCore.Modules/OrchardCore.AuditTrail/Services/AuditTrailBackgroundTask.cs @@ -23,7 +23,7 @@ public async Task DoWorkAsync(IServiceProvider serviceProvider, CancellationToke { var siteService = serviceProvider.GetRequiredService(); - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); if (settings.Disabled) { return; diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs index beb5afec15e..6302191019f 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/ContentRequestCultureProvider.cs @@ -24,7 +24,7 @@ public override async Task DetermineProviderCultureResult if (localization != null) { - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); if (settings.SetCookie) { culturePickerService.SetContentCulturePickerCookie(localization.Culture); diff --git a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs index 1f4917ec918..bf8177fa01e 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentLocalization/Controllers/ContentCulturePickerController.cs @@ -47,7 +47,7 @@ public async Task RedirectToLocalizedContent(string targetCulture if (supportedCultures.Any(t => t == targetCulture)) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.SetCookie) { _culturePickerService.SetContentCulturePickerCookie(targetCulture); diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs index 188aad57cb9..08999ac4f83 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AdminMenu.cs @@ -83,7 +83,7 @@ await content.AddAsync(S["Content Items"], S["Content Items"].PrefixPosition(), }); }); - var adminSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var adminSettings = await _siteService.GetSettingsAsync(); if (adminSettings.DisplayNewMenu && contentTypes.Any()) { diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs index 641439157ef..9ec5cfa7ff2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/AuditTrail/Handlers/AuditTrailContentHandler.cs @@ -72,9 +72,8 @@ private async Task RecordAuditTrailEventAsync(string name, ContentItem content) return; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); + var settings = await _siteService.GetSettingsAsync(); - var settings = siteSettings.As(); if (!settings.AllowedContentTypes.Contains(content.ContentItem.ContentType)) { return; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs index 92619b9059f..b21e82475e6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentDriver.cs @@ -29,8 +29,8 @@ public override IDisplayResult Display(ContentItem model) { if (await _deploymentPlanService.DoesUserHaveExportPermissionAsync()) { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var exportContentToDeploymentTargetSettings = siteSettings.As(); + var exportContentToDeploymentTargetSettings = await _siteService.GetSettingsAsync(); + if (exportContentToDeploymentTargetSettings.ExportContentToDeploymentTargetPlanId != 0) { return true; @@ -45,8 +45,8 @@ public override IDisplayResult Display(ContentItem model) { if (await _deploymentPlanService.DoesUserHaveExportPermissionAsync()) { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var exportContentToDeploymentTargetSettings = siteSettings.As(); + var exportContentToDeploymentTargetSettings = await _siteService.GetSettingsAsync(); + if (exportContentToDeploymentTargetSettings.ExportContentToDeploymentTargetPlanId != 0) { return true; diff --git a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs index 09874c97824..abf6f3818c3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Contents/Deployment/ExportContentToDeploymentTarget/ExportContentToDeploymentTargetContentsAdminListDisplayDriver.cs @@ -24,8 +24,8 @@ public override async Task DisplayAsync(ContentOptionsViewModel { if (await _deploymentPlanService.DoesUserHaveExportPermissionAsync()) { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var exportContentToDeploymentTargetSettings = siteSettings.As(); + var exportContentToDeploymentTargetSettings = await _siteService.GetSettingsAsync(); + if (exportContentToDeploymentTargetSettings.ExportContentToDeploymentTargetPlanId != 0) { return Combine( diff --git a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs index 25d33fc0161..ac3f97f58fc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Cors/Services/CorsService.cs @@ -16,8 +16,7 @@ public CorsService(ISiteService siteService) public async Task GetSettingsAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As(); + return await _siteService.GetSettingsAsync(); } internal async Task UpdateSettingsAsync(CorsSettings corsSettings) diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs index 5b639b6d285..48c07365e0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Azure/Services/AzureEmailOptionsConfiguration.cs @@ -23,10 +23,9 @@ public AzureEmailOptionsConfiguration( public void Configure(AzureEmailOptions options) { - var settings = _siteService.GetSiteSettingsAsync() + var settings = _siteService.GetSettingsAsync() .GetAwaiter() - .GetResult() - .As(); + .GetResult(); options.IsEnabled = settings.IsEnabled; options.DefaultSender = settings.DefaultSender; diff --git a/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs index 0ac92e3870f..28b4a52b838 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email.Smtp/Services/SmtpOptionsConfiguration.cs @@ -25,9 +25,9 @@ public SmtpOptionsConfiguration( public void Configure(SmtpOptions options) { - var settings = _siteService.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.DefaultSender = settings.DefaultSender; options.DeliveryMethod = settings.DeliveryMethod; diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs index 131fc687e3a..6ba250bcdac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs @@ -32,9 +32,7 @@ public int Create() return; } - var site = await siteService.GetSiteSettingsAsync(); - - var smtpSettings = site.As(); + var smtpSettings = await siteService.GetSettingsAsync(); if (!string.IsNullOrEmpty(smtpSettings.DefaultSender) || scope.ServiceProvider.GetService>()?.Value.ConfigurationExists() == true) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs index 5593343cd4d..35b0fabc1c0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Filters/FacebookPixelFilter.cs @@ -34,7 +34,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if (_scriptsCache == null && canTrack) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!string.IsNullOrWhiteSpace(settings?.PixelId)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs index adcd8ce2967..8a8b01e7a26 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs @@ -19,10 +19,9 @@ public FacebookLoginService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs index d42ab4ac2f8..abfc058c76d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/ScriptsMiddleware.cs @@ -26,8 +26,8 @@ public async Task Invoke(HttpContext httpContext) if (httpContext.Request.Path.StartsWithSegments("/OrchardCore.Facebook/sdk", StringComparison.OrdinalIgnoreCase)) { var script = default(string); - var site = (await _siteService.GetSiteSettingsAsync()); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); + if (Path.GetFileName(httpContext.Request.Path.Value) == "fbsdk.js") { var locale = CultureInfo.CurrentUICulture.Name.Replace('-', '_'); diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs index c4e0ff96c47..7a3f4cb6963 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs @@ -23,10 +23,9 @@ public FacebookService( S = stringLocalizer; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task UpdateSettingsAsync(FacebookSettings settings) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml index e00313a1ee8..dad761f16b4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.Summary.cshtml @@ -2,9 +2,9 @@ @using OrchardCore.Settings @using OrchardCore.Facebook.Settings @model OrchardCore.Facebook.Widgets.ViewModels.FacebookPluginPartViewModel -@inject ISiteService _site +@inject ISiteService SiteService @{ - var fbInit = (await _site.GetSiteSettingsAsync()).As().FBInit; + var fbInit = (await SiteService.GetSettingsAsync()).FBInit; } @Html.Raw(Model.Html) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml index e00313a1ee8..dad761f16b4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Views/FacebookPluginPart.cshtml @@ -2,9 +2,9 @@ @using OrchardCore.Settings @using OrchardCore.Facebook.Settings @model OrchardCore.Facebook.Widgets.ViewModels.FacebookPluginPartViewModel -@inject ISiteService _site +@inject ISiteService SiteService @{ - var fbInit = (await _site.GetSiteSettingsAsync()).As().FBInit; + var fbInit = (await SiteService.GetSettingsAsync()).FBInit; } @Html.Raw(Model.Html) diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs index 4d954cff7c2..0dad564eaca 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs @@ -22,10 +22,9 @@ public GitHubAuthenticationService( S = stringLocalizer; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs index 31671da1642..5d71ab5faac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/GoogleAnalyticsFilter.cs @@ -33,7 +33,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if (_scriptsCache == null && canTrack) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!string.IsNullOrWhiteSpace(settings?.TrackingID)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs index e356ebf9431..fd1c13225a6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs @@ -14,10 +14,9 @@ public GoogleAnalyticsService( _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs index 75365c9670c..108f2c0e9eb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/GoogleTagManagerFilter.cs @@ -33,7 +33,7 @@ public async Task OnResultExecutionAsync(ResultExecutingContext context, ResultE if (_scriptsCache == null && canTrack) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!string.IsNullOrWhiteSpace(settings?.ContainerID)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs index 822fbf76805..89073e5fd68 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs @@ -13,10 +13,9 @@ public GoogleTagManagerService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs b/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs index 8de37114e43..db3587c82ba 100644 --- a/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs @@ -13,10 +13,9 @@ public HttpsService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As(); + return _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs index fa5fd65b26c..98df4a0f18e 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Controllers/AdminController.cs @@ -99,10 +99,9 @@ public async Task Index() var model = new LayersIndexViewModel { Layers = layers.Layers.ToList() }; - var siteSettings = await _siteService.GetSiteSettingsAsync(); var contentDefinitions = await _contentDefinitionManager.ListTypeDefinitionsAsync(); - model.Zones = siteSettings.As().Zones ?? []; + model.Zones = (await _siteService.GetSettingsAsync()).Zones ?? []; model.Widgets = []; foreach (var widget in widgets.OrderBy(x => x.Position)) diff --git a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs index 746122cded8..74f4bbaea4d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Layers/Deployment/AllLayersDeploymentSource.cs @@ -41,13 +41,13 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan ["Layers"] = JArray.FromObject(layers.Layers, _jsonSerializerOptions), }); - var siteSettings = await _siteService.GetSiteSettingsAsync(); + var layerSettings = await _siteService.GetSettingsAsync(); // Adding Layer settings result.Steps.Add(new JsonObject { ["name"] = "Settings", - ["LayerSettings"] = JObject.FromObject(siteSettings.As()), + ["LayerSettings"] = JObject.FromObject(layerSettings), }); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs b/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs index 7285b30bc05..0de425edef6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Localization/Services/LocalizationService.cs @@ -47,11 +47,7 @@ public async Task GetSupportedCulturesAsync() private async Task InitializeLocalizationSettingsAsync() { - if (_localizationSettings == null) - { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - _localizationSettings = siteSettings.As(); - } + _localizationSettings ??= await _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs index 19302b3b138..f38d82c019a 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenOptionsConfiguration.cs @@ -14,9 +14,9 @@ public MediaTokenOptionsConfiguration(ISiteService siteService) public void Configure(MediaTokenOptions options) { - options.HashKey = _siteService.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As() + options.HashKey = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult() .HashKey; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs index a42e4693d63..a6e1880b8a8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Processing/MediaTokenSettingsUpdater.cs @@ -34,7 +34,7 @@ public async Task ActivatedAsync() return; } - var mediaTokenSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var mediaTokenSettings = await _siteService.GetSettingsAsync(); if (mediaTokenSettings.HashKey == null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs index 514cadd4dcc..bf27600393c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs @@ -22,10 +22,9 @@ public AzureADService( S = stringLocalizer; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs index 2424d0f4f3e..b4bdc213e42 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs @@ -22,10 +22,9 @@ public MicrosoftAccountService( S = stringLocalizer; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs index af48416387c..20e15eb18b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs @@ -24,10 +24,9 @@ public OpenIdClientService( S = stringLocalizer; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs index f3f6943ca40..971be8ecdeb 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaForgotPasswordFormDisplayDriver.cs @@ -18,7 +18,7 @@ public ReCaptchaForgotPasswordFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(ForgotPasswordForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs index 08be62e8225..02ec8a5aa45 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaLoginFormDisplayDriver.cs @@ -23,7 +23,7 @@ public ReCaptchaLoginFormDisplayDriver( public override async Task EditAsync(LoginForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid() || !_reCaptchaService.IsThisARobot()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs index 010fe0cba4a..a75a24820f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/ReCaptchaResetPasswordFormDisplayDriver.cs @@ -18,7 +18,7 @@ public ReCaptchaResetPasswordFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(ResetPasswordForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs index 2ab32c34563..ec3bcf2b56b 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs @@ -18,7 +18,7 @@ public RegisterUserFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(RegisterUserForm model, BuildEditorContext context) { - var _reCaptchaSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var _reCaptchaSettings = await _siteService.GetSettingsAsync(); if (!_reCaptchaSettings.IsValid()) { diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs index a09409f0247..3937b598a88 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Forms/ReCaptchaPartDisplayDriver.cs @@ -19,8 +19,7 @@ public override IDisplayResult Display(ReCaptchaPart part, BuildPartDisplayConte { return Initialize("ReCaptchaPart", async model => { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var settings = siteSettings.As(); + var settings = await _siteService.GetSettingsAsync(); model.SettingsAreConfigured = settings.IsValid(); }).Location("Detail", "Content"); } @@ -29,8 +28,7 @@ public override IDisplayResult Edit(ReCaptchaPart part, BuildPartEditorContext c { return Initialize("ReCaptchaPart_Fields_Edit", async model => { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var settings = siteSettings.As(); + var settings = await _siteService.GetSettingsAsync(); model.SettingsAreConfigured = settings.IsValid(); }); } diff --git a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs index 6873ca847bb..09883b61877 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs @@ -13,10 +13,9 @@ public ReverseProxyService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As(); + return _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs index a7f1b382d80..6399cac7bd3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Handlers/ElasticsearchAuthorizationHandler.cs @@ -62,8 +62,7 @@ private async Task GetIndexNameAsync(SearchPermissionParameters paramete } _siteService ??= _serviceProvider.GetRequiredService(); - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs index 15f8e097b5d..9f675bf3c26 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Elasticsearch/Services/ElasticSearchService.cs @@ -66,8 +66,7 @@ public async Task SearchAsync(string indexName, string term, int s return result; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var searchSettings = siteSettings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); var index = !string.IsNullOrWhiteSpace(indexName) ? indexName.Trim() : searchSettings.SearchIndex; diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs index 1b662abecdf..a63926e3e7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Handler/LuceneAuthorizationHandler.cs @@ -61,8 +61,7 @@ private async Task GetIndexNameAsync(SearchPermissionParameters paramete } _siteService ??= _serviceProvider.GetRequiredService(); - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs index 415452028fe..8e8d37441c8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs @@ -6,7 +6,6 @@ using Microsoft.Extensions.Logging; using OrchardCore.ContentLocalization; using OrchardCore.ContentManagement; -using OrchardCore.Entities; using OrchardCore.Environment.Shell; using OrchardCore.Indexing; using OrchardCore.Modules; @@ -299,16 +298,9 @@ public async Task RebuildIndexAsync(string indexName) public async Task GetLuceneSettingsAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); + var luceneSettings = await _siteService.GetSettingsAsync(); - if (siteSettings.Has()) - { - return siteSettings.As(); - } - else - { - return new LuceneSettings(); - } + return luceneSettings ?? new LuceneSettings(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs index c22c388e469..53f935b9178 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs @@ -80,9 +80,7 @@ public async Task SearchAsync(string indexName, string term, int s private async Task DefaultIndexAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); - - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } private async Task GetSearchFieldsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs index b6b1d00ade2..07bc4d414c0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs @@ -69,9 +69,7 @@ public async Task Search(SearchViewModel viewModel, PagerSlimPara return View(); } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - - var searchSettings = siteSettings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); ISearchService searchService = null; if (!string.IsNullOrEmpty(searchSettings.ProviderName)) diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs b/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs index a461a61f723..9d1c201a7a6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Deployment/SearchSettingsDeploymentSource.cs @@ -8,11 +8,11 @@ namespace OrchardCore.Search.Deployment { public class SearchSettingsDeploymentSource : IDeploymentSource { - private readonly ISiteService _site; + private readonly ISiteService _siteService; public SearchSettingsDeploymentSource(ISiteService site) { - _site = site; + _siteService = site; } public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlanResult result) @@ -22,8 +22,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var settings = await _site.GetSiteSettingsAsync(); - var searchSettings = settings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); result.Steps.Add(new JsonObject { diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs index cb8ea451d30..c4c855b2ef6 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Services/SearchSettingsConfiguration.cs @@ -6,18 +6,18 @@ namespace OrchardCore.Search.Configuration { public class SearchSettingsConfiguration : IConfigureOptions { - private readonly ISiteService _site; + private readonly ISiteService _siteService; public SearchSettingsConfiguration(ISiteService site) { - _site = site; + _siteService = site; } public void Configure(SearchSettings options) { - var settings = _site.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.ProviderName = settings.ProviderName; } diff --git a/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs b/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs index d1f1db889f6..286261e0bc1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs @@ -13,11 +13,9 @@ public SecurityService(ISiteService siteService) _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var securityHeadersSettings = await _siteService.GetSiteSettingsAsync(); - - return securityHeadersSettings.As(); + return _siteService.GetSettingsAsync(); } } } diff --git a/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs b/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs index 2ab7ce3eecc..d7d139323d1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs +++ b/src/OrchardCore.Modules/OrchardCore.Seo/Services/SiteSettingsRobotsProvider.cs @@ -21,7 +21,7 @@ public SiteSettingsRobotsProvider( public async Task GetContentAsync() { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); var content = new StringBuilder(); diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs index 573767e03f9..a2d8e60abe8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/PagerOptionsConfiguration.cs @@ -14,7 +14,9 @@ public PagerOptionsConfiguration(ISiteService siteService) public void PostConfigure(string name, PagerOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); + var site = _siteService.GetSiteSettingsAsync() + .GetAwaiter() + .GetResult(); options.MaxPageSize = site.MaxPageSize; options.MaxPagedCount = site.MaxPagedCount; diff --git a/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs b/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs index a4589bf1750..43942989034 100644 --- a/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs +++ b/src/OrchardCore.Modules/OrchardCore.Settings/ResourceOptionsConfiguration.cs @@ -14,7 +14,9 @@ public ResourceOptionsConfiguration(ISiteService siteService) public void PostConfigure(string name, ResourceOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); + var site = _siteService.GetSiteSettingsAsync() + .GetAwaiter() + .GetResult(); options.ResourceDebugMode = site.ResourceDebugMode; options.UseCdn = site.UseCdn; diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs index 240518005cc..d672f8ca193 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Drivers/TaxonomyContentsAdminListDisplayDriver.cs @@ -45,7 +45,7 @@ public TaxonomyContentsAdminListDisplayDriver( public override async Task EditAsync(ContentOptionsViewModel model, IUpdateModel updater) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.TaxonomyContentItemIds.Length == 0) { @@ -117,7 +117,7 @@ public override async Task EditAsync(ContentOptionsViewModel mod public override async Task UpdateAsync(ContentOptionsViewModel model, IUpdateModel updater) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); foreach (var contentItemId in settings.TaxonomyContentItemIds) { var viewModel = new TaxonomyContentsAdminFilterViewModel(); diff --git a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs index c1760a77678..922cdda0e65 100644 --- a/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs +++ b/src/OrchardCore.Modules/OrchardCore.Taxonomies/Services/TaxonomyContentsAdminListFilter.cs @@ -26,7 +26,7 @@ public TaxonomyContentsAdminListFilter(ISiteService siteService) public async Task FilterAsync(ContentOptionsViewModel model, IQuery query, IUpdateModel updater) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); foreach (var contentItemId in settings.TaxonomyContentItemIds) { var viewModel = new TaxonomyContentsAdminFilterViewModel(); diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs index 76e85554c93..34388fc97ac 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/Drivers/ToggleThemeNavbarDisplayDriver.cs @@ -17,7 +17,7 @@ public ToggleThemeNavbarDisplayDriver(ISiteService siteService) public override IDisplayResult Display(Navbar model) { return View("ToggleTheme", model) - .RenderWhen(async () => (await _siteService.GetSiteSettingsAsync()).As().DisplayThemeToggler) + .RenderWhen(async () => (await _siteService.GetSettingsAsync()).DisplayThemeToggler) .Location("Detail", "Content:10") .Location("DetailAdmin", "Content:10"); } diff --git a/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs b/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs index a134f22e182..ed77b2179ec 100644 --- a/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Themes/Services/ThemeTogglerService.cs @@ -25,7 +25,7 @@ public ThemeTogglerService( public async Task CurrentTheme() { - var adminSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var adminSettings = await _siteService.GetSettingsAsync(); if (adminSettings.DisplayThemeToggler) { diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs index bbbeb3920fc..34920464d39 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs @@ -22,10 +22,9 @@ public TwitterSettingsService( S = stringLocalizer; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs index 11182f78f51..6a2fec5298d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs @@ -16,10 +16,9 @@ public TwitterSigninService( _siteService = siteService; } - public async Task GetSettingsAsync() + public Task GetSettingsAsync() { - var container = await _siteService.GetSiteSettingsAsync(); - return container.As(); + return _siteService.GetSettingsAsync(); } public async Task LoadSettingsAsync() diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs index 2beb653a08f..82fd0d68430 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AccountController.cs @@ -100,7 +100,7 @@ public async Task Login(string returnUrl = null) // Clear the existing external cookie to ensure a clean login process. await HttpContext.SignOutAsync(IdentityConstants.ExternalScheme); - var loginSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.UseExternalProviderIfOnlyOneDefined) { var schemes = await _signInManager.GetExternalAuthenticationSchemesAsync(); @@ -131,7 +131,7 @@ public async Task Login(string returnUrl = null) [AllowAnonymous] public async Task DefaultExternalLogin(string protectedToken, string returnUrl = null) { - var loginSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.UseExternalProviderIfOnlyOneDefined) { var schemes = await _signInManager.GetExternalAuthenticationSchemesAsync(); @@ -174,7 +174,7 @@ public async Task LoginPOST(string returnUrl = null) var formShape = await _loginFormDisplayManager.UpdateEditorAsync(model, _updateModelAccessor.ModelUpdater, false, string.Empty, string.Empty); - var disableLocalLogin = (await _siteService.GetSiteSettingsAsync()).As().DisableLocalLogin; + var disableLocalLogin = (await _siteService.GetSettingsAsync()).DisableLocalLogin; if (disableLocalLogin) { @@ -360,7 +360,7 @@ public async Task ExternalLoginCallback(string returnUrl = null, return RedirectToLogin(returnUrl); } - var registrationSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var registrationSettings = await _siteService.GetSettingsAsync(); var iUser = await _userManager.FindByLoginAsync(info.LoginProvider, info.ProviderKey); CopyTempDataErrorsToModelState(); @@ -521,7 +521,7 @@ public async Task RegisterExternalLogin(RegisterExternalLoginView return NotFound(); } - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister == UserRegistrationType.NoRegistration) { @@ -869,7 +869,7 @@ private async Task AddConfirmEmailErrorAsync(IUser user) return false; } - var registrationSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var registrationSettings = await _siteService.GetSettingsAsync(); if (registrationSettings.UsersMustValidateEmail) { // Require that the users have a confirmed email before they can log on. diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs index 0072a7f730b..9ce1c2326ce 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/AuthenticatorAppController.cs @@ -67,7 +67,7 @@ public async Task Index(string returnUrl) return UserNotFound(); } - var loginSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var loginSettings = await SiteService.GetSettingsAsync(); var model = await LoadSharedKeyAndQrCodeUriAsync(user, loginSettings); @@ -96,7 +96,7 @@ public async Task Index(EnableAuthenticatorViewModel model) { ModelState.AddModelError(model.Code, S["Verification code is invalid."]); - var loginSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var loginSettings = await SiteService.GetSettingsAsync(); return View(await LoadSharedKeyAndQrCodeUriAsync(user, loginSettings)); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs index 965e620d918..9a07da48e68 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ChangeEmailController.cs @@ -37,7 +37,7 @@ public ChangeEmailController( [Authorize] public async Task Index() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowChangeEmail) + if (!(await _siteService.GetSettingsAsync()).AllowChangeEmail) { return NotFound(); } @@ -51,7 +51,7 @@ public async Task Index() [ValidateAntiForgeryToken] public async Task Index(ChangeEmailViewModel model) { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowChangeEmail) + if (!(await _siteService.GetSettingsAsync()).AllowChangeEmail) { return NotFound(); } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs index 120f748c02c..cdfb02789c1 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/RegistrationController.cs @@ -55,7 +55,7 @@ public RegistrationController( [AllowAnonymous] public async Task Register(string returnUrl = null) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.AllowRegistration) { return NotFound(); @@ -74,7 +74,7 @@ public async Task Register(string returnUrl = null) [ActionName(nameof(Register))] public async Task RegisterPOST(string returnUrl = null) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.AllowRegistration) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs index ce825aea29f..b4c8c8d5ef7 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/ResetPasswordController.cs @@ -65,7 +65,7 @@ public ResetPasswordController( [AllowAnonymous] public async Task ForgotPassword() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -80,7 +80,7 @@ public async Task ForgotPassword() [ActionName(nameof(ForgotPassword))] public async Task ForgotPasswordPOST() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -130,7 +130,7 @@ public IActionResult ForgotPasswordConfirmation() [AllowAnonymous] public async Task ResetPassword(string code = null) { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -152,7 +152,7 @@ public async Task ResetPassword(string code = null) [ActionName(nameof(ResetPassword))] public async Task ResetPasswordPOST() { - if (!(await _siteService.GetSiteSettingsAsync()).As().AllowResetPassword) + if (!(await _siteService.GetSettingsAsync()).AllowResetPassword) { return NotFound(); } @@ -191,7 +191,7 @@ private async Task MustValidateEmailAsync(User user) return false; } - return (await _siteService.GetSiteSettingsAsync()).As().UsersMustValidateEmail + return (await _siteService.GetSettingsAsync()).UsersMustValidateEmail && !await _userManager.IsEmailConfirmedAsync(user); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs index 1acf3129dc4..e9a96334c45 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/SmsAuthenticatorController.cs @@ -78,7 +78,7 @@ public async Task Index() return UserNotFound(); } - var settings = (await SiteService.GetSiteSettingsAsync()).As(); + var settings = await SiteService.GetSettingsAsync(); var currentPhoneNumber = await UserManager.GetPhoneNumberAsync(user); @@ -103,7 +103,7 @@ public async Task IndexPost(RequestCodeSmsAuthenticatorViewModel return UserNotFound(); } - var settings = (await SiteService.GetSiteSettingsAsync()).As(); + var settings = await SiteService.GetSettingsAsync(); var currentPhoneNumber = await UserManager.GetPhoneNumberAsync(user); @@ -123,7 +123,7 @@ public async Task IndexPost(RequestCodeSmsAuthenticatorViewModel var phoneNumber = canSetNewPhone ? model.PhoneNumber : currentPhoneNumber; var code = await UserManager.GenerateChangePhoneNumberTokenAsync(user, phoneNumber); - var smsSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var smsSettings = await SiteService.GetSettingsAsync(); var message = new SmsMessage() { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs index f3b8169df39..f7be675bedf 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationBaseController.cs @@ -139,7 +139,7 @@ protected async Task RedirectToTwoFactorAsync(IUser user) { if (await UserManager.CountRecoveryCodesAsync(user) == 0) { - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var recoveryCodes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, twoFactorSettings.NumberOfRecoveryCodesToGenerate); await SetRecoveryCodesAsync(recoveryCodes.ToArray(), await UserManager.GetUserIdAsync(user)); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs index 16e4667468b..d50fd58cc68 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Controllers/TwoFactorAuthenticationController.cs @@ -86,7 +86,7 @@ public async Task LoginWithTwoFactorAuthentication(bool rememberM return RedirectToAccountLogin(); } - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var model = new LoginWithTwoFactorAuthenticationViewModel { @@ -125,7 +125,7 @@ public async Task LoginWithTwoFactorAuthenticationPost(LoginWithT if (ModelState.IsValid) { - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var rememberDevice = twoFactorSettings.AllowRememberClientTwoFactorAuthentication && model.RememberDevice; var authenticatorCode = StripToken(model.VerificationCode); @@ -322,7 +322,7 @@ public async Task GenerateRecoveryCodesPost() return RedirectToAction(nameof(Index)); } - var twoFactorSettings = (await SiteService.GetSiteSettingsAsync()).As(); + var twoFactorSettings = await SiteService.GetSettingsAsync(); var recoveryCodes = await UserManager.GenerateNewTwoFactorRecoveryCodesAsync(user, twoFactorSettings.NumberOfRecoveryCodesToGenerate); await SetRecoveryCodesAsync(recoveryCodes.ToArray(), await UserManager.GetUserIdAsync(user)); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs index 142225ebf7a..edd58581177 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/ForgotPasswordLoginFormDisplayDriver.cs @@ -17,7 +17,7 @@ public ForgotPasswordLoginFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(LoginForm model, BuildEditorContext context) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (!settings.AllowResetPassword) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs index 707d406a26a..7d22481655f 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/RegisterUserLoginFormDisplayDriver.cs @@ -17,7 +17,7 @@ public RegisterUserLoginFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(LoginForm model, BuildEditorContext context) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.AllowRegistration) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs index b93fcace0ff..e5c1de87b82 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Drivers/UserInformationDisplayDriver.cs @@ -42,8 +42,7 @@ public override async Task EditAsync(User user, BuildEditorConte return null; } - var site = await _siteService.GetSiteSettingsAsync(); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); var canEditUserInfo = await CanEditUserInfoAsync(user); return Combine( Initialize("UserName_Edit", model => @@ -113,8 +112,7 @@ public override async Task UpdateAsync(User user, UpdateEditorCo } else { - var site = await _siteService.GetSiteSettingsAsync(); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); if (await CanEditUserInfoAsync(user)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs index 461449be49e..25c7e9e56b5 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/EmailAuthenticator/SendCode.cs @@ -50,7 +50,7 @@ private static async Task HandleAsync( }); } - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); var code = await userManager.GenerateTwoFactorTokenAsync(user, TokenOptions.DefaultEmailProvider); var to = await userManager.GetEmailAsync(user); diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs index b700b3e99dd..35e6bc54c89 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Endpoints/SmsAuthenticator/SendCode.cs @@ -52,7 +52,7 @@ private static async Task HandleAsync( }); } - var settings = (await siteService.GetSiteSettingsAsync()).As(); + var settings = await siteService.GetSettingsAsync(); var code = await userManager.GenerateTwoFactorTokenAsync(user, identityOptions.Value.Tokens.ChangePhoneNumberTokenProvider); var message = new SmsMessage() @@ -70,7 +70,7 @@ private static async Task HandleAsync( : errorMessage.Value, }); } - + private static Task GetBodyAsync( SmsAuthenticatorLoginSettings settings, IUser user, diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs b/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs index 4e07b7833f0..39fc1983a0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Extensions/ControllerExtensions.cs @@ -61,7 +61,7 @@ internal static async Task RegisterUser(this Controller controller, Regis return null; } - var settings = (await controller.ControllerContext.HttpContext.RequestServices.GetRequiredService().GetSiteSettingsAsync()).As(); + var settings = await controller.ControllerContext.HttpContext.RequestServices.GetRequiredService().GetSettingsAsync(); if (settings.UsersCanRegister != UserRegistrationType.NoRegistration) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs index 14a3cdf45f2..a4c1999a78d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Handlers/ScriptExternalLoginEventHandler.cs @@ -28,7 +28,7 @@ ILogger logger public async Task GenerateUserName(string provider, IEnumerable claims) { - var registrationSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var registrationSettings = await _siteService.GetSettingsAsync(); if (registrationSettings.UseScriptToGenerateUsername) { @@ -47,7 +47,7 @@ public async Task GenerateUserName(string provider, IEnumerable(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.UseScriptToSyncRoles) { var script = $"js: function syncRoles(context) {{\n{loginSettings.SyncRolesScript}\n}}\nvar context={JConvert.SerializeObject(context, JOptions.CamelCase)};\nsyncRoles(context);\nreturn context;"; diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs index dc807379aa8..ea1f6d07962 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/IdentityOptionsConfigurations.cs @@ -16,9 +16,9 @@ public IdentityOptionsConfigurations(ISiteService siteService) public void Configure(IdentityOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - - var settings = site.As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); if (!string.IsNullOrEmpty(settings.UserSettings?.AllowedUserNameCharacters)) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs index 5154f79ebca..f9ab298e5ea 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/RoleTwoFactorAuthenticationHandler.cs @@ -24,7 +24,7 @@ public async Task IsRequiredAsync(IUser user) { ArgumentNullException.ThrowIfNull(user); - var loginSettings = (await _siteService.GetSiteSettingsAsync()).As(); + var loginSettings = await _siteService.GetSettingsAsync(); if (loginSettings.RequireTwoFactorAuthenticationForSpecificRoles && loginSettings.Roles != null) { diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs b/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs index 536c335e20b..84a99e555a4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs +++ b/src/OrchardCore.Modules/OrchardCore.Users/Services/UsersThemeSelector.cs @@ -43,33 +43,33 @@ public async Task GetThemeAsync() switch (routeValues["controller"]?.ToString()) { case "Account": - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; break; case "TwoFactorAuthentication": { if (routeValues["action"] != null && routeValues["action"].ToString().StartsWith("LoginWith", StringComparison.OrdinalIgnoreCase) - && (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme) + && (await _siteService.GetSettingsAsync()).UseSiteTheme) { useSiteTheme = true; } else { - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; } } break; case "SmsAuthenticator": case "AuthenticatorApp": { - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; } break; case "Registration": - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; break; case "ResetPassword": - useSiteTheme = (await _siteService.GetSiteSettingsAsync()).As().UseSiteTheme; + useSiteTheme = (await _siteService.GetSettingsAsync()).UseSiteTheme; break; default: return null; diff --git a/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml b/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml index 2ba0283caed..ae85e1c2ee4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml +++ b/src/OrchardCore.Modules/OrchardCore.Users/Views/Account/Login.cshtml @@ -15,7 +15,7 @@ ViewLayout = "Layout__Login"; var loginProviders = (await SignInManager.GetExternalAuthenticationSchemesAsync()).ToList(); - var disableLocalLogin = (await SiteService.GetSiteSettingsAsync()).As().DisableLocalLogin; + var disableLocalLogin = (await SiteService.GetSettingsAsync()).DisableLocalLogin; } diff --git a/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs b/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs index a83e0be8ab8..0a010eda3a0 100644 --- a/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.Email.Core/Services/EmailOptionsConfiguration.cs @@ -19,9 +19,9 @@ public EmailOptionsConfiguration( public void Configure(EmailOptions options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - - var emailSettings = site.As(); + var emailSettings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); if (!string.IsNullOrEmpty(emailSettings.DefaultProviderName) && _emailProviderOptions.Providers.TryGetValue(emailSettings.DefaultProviderName, out var provider) diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs new file mode 100644 index 00000000000..81b9b32de9a --- /dev/null +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs @@ -0,0 +1,11 @@ +using System.Threading.Tasks; + +namespace OrchardCore.Settings; + +public static class SiteServiceExtensions +{ + public static async Task GetSettingsAsync(this ISiteService siteService) where T : new() + { + return (await siteService.GetSiteSettingsAsync()).As(); + } +} diff --git a/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs b/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs index 93a3a6e1a67..e3e74d71274 100644 --- a/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.ReCaptcha.Core/Configuration/ReCaptchaSettingsConfiguration.cs @@ -14,9 +14,9 @@ public ReCaptchaSettingsConfiguration(ISiteService site) public void Configure(ReCaptchaSettings options) { - var settings = _site.GetSiteSettingsAsync() - .GetAwaiter().GetResult() - .As(); + var settings = _site.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.SiteKey = settings.SiteKey; options.SecretKey = settings.SecretKey; diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs index f813c5d06ee..ebc6afeaf53 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Deployment/AzureAISearchSettingsDeploymentSource.cs @@ -17,9 +17,7 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var site = await _siteService.GetSiteSettingsAsync(); - - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); result.Steps.Add(new JsonObject { diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs index 89ec03f68fc..9ecb34d6cc1 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Handlers/AzureAISearchAuthorizationHandler.cs @@ -66,8 +66,7 @@ private async Task GetIndexNameAsync(SearchPermissionParameters paramete } _siteService ??= _serviceProvider.GetRequiredService(); - var siteSettings = await _siteService.GetSiteSettingsAsync(); - return siteSettings.As().SearchIndex; + return (await _siteService.GetSettingsAsync()).SearchIndex; } } diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs index a54eae036a8..f6cd1e96c17 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchDefaultOptionsConfigurations.cs @@ -49,8 +49,7 @@ public async void Configure(AzureAISearchDefaultOptions options) else { // At this point, we can allow the user to update the settings from UI. - var site = await _siteService.GetSiteSettingsAsync(); - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); if (settings.UseCustomConfiguration) { diff --git a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs index e34c634e412..186828c47a3 100644 --- a/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs +++ b/src/OrchardCore/OrchardCore.Search.AzureAI.Core/Services/AzureAISearchService.cs @@ -47,8 +47,7 @@ public async Task SearchAsync(string indexName, string term, int s return result; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var searchSettings = siteSettings.As(); + var searchSettings = await _siteService.GetSettingsAsync(); var index = !string.IsNullOrWhiteSpace(indexName) ? indexName.Trim() : searchSettings.SearchIndex; diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs index a463bd11635..3542c23cc9d 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs @@ -9,7 +9,6 @@ using OrchardCore.ContentManagement; using OrchardCore.ContentManagement.Metadata; using OrchardCore.ContentManagement.Records; -using OrchardCore.Entities; using OrchardCore.Environment.Shell; using OrchardCore.Indexing; using OrchardCore.Modules; @@ -282,14 +281,9 @@ public async Task RebuildIndexAsync(ElasticIndexSettings elasticIndexSettings) public async Task GetElasticSettingsAsync() { - var siteSettings = await _siteService.GetSiteSettingsAsync(); + var elasticSettings = await _siteService.GetSettingsAsync(); - if (siteSettings.Has()) - { - return siteSettings.As(); - } - - return new ElasticSettings(); + return elasticSettings ?? new ElasticSettings(); } /// diff --git a/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs b/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs index 1f57c38402c..ef3c3e278a5 100644 --- a/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs +++ b/src/OrchardCore/OrchardCore.Settings.Core/Deployment/SiteSettingsPropertyDeploymentSource.cs @@ -21,10 +21,8 @@ public async Task ProcessDeploymentStepAsync(DeploymentStep step, DeploymentPlan return; } - var siteSettings = await _siteService.GetSiteSettingsAsync(); - var settingJPropertyName = typeof(TModel).Name; - var settingJPropertyValue = JObject.FromObject(siteSettings.As()); + var settingJPropertyValue = JObject.FromObject(await _siteService.GetSettingsAsync()); var settingsStepJObject = result.Steps.FirstOrDefault(s => s["name"]?.ToString() == "Settings"); if (settingsStepJObject != null) diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs index aab4b71fcef..bfc68db7603 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/DefaultSmsProviderResolver.cs @@ -31,9 +31,7 @@ public async Task GetAsync(string name = null) { if (string.IsNullOrEmpty(name)) { - var site = await _siteService.GetSiteSettingsAsync(); - - var settings = site.As(); + var settings = await _siteService.GetSettingsAsync(); name = settings.DefaultProviderName; } diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs index 726145cf60b..91a5c9d2976 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/SmsSettingsConfiguration.cs @@ -14,9 +14,9 @@ public SmsSettingsConfiguration(ISiteService siteService) public void PostConfigure(string name, SmsSettings options) { - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - - var settings = site.As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); options.DefaultProviderName = settings.DefaultProviderName; } diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs index cf027b2ee9d..5cd9d2a7538 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioProviderOptionsConfigurations.cs @@ -17,8 +17,9 @@ public void Configure(SmsProviderOptions options) { var typeOptions = new SmsProviderTypeOptions(typeof(TwilioSmsProvider)); - var site = _siteService.GetSiteSettingsAsync().GetAwaiter().GetResult(); - var settings = site.As(); + var settings = _siteService.GetSettingsAsync() + .GetAwaiter() + .GetResult(); typeOptions.IsEnabled = settings.IsEnabled; diff --git a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs index c81848ddb2e..6fd3a97ade5 100644 --- a/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs +++ b/src/OrchardCore/OrchardCore.Sms.Core/Services/TwilioSmsProvider.cs @@ -116,7 +116,7 @@ private async Task GetSettingsAsync() { if (_settings == null) { - var settings = (await _siteService.GetSiteSettingsAsync()).As(); + var settings = await _siteService.GetSettingsAsync(); var protector = _dataProtectionProvider.CreateProtector(ProtectorName); diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs index aa9db239c36..21f2cc1cfa6 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs @@ -16,6 +16,6 @@ public DefaultTwoFactorAuthenticationHandler(ISiteService siteService) public async Task IsRequiredAsync(IUser user) { - return (await _siteService.GetSiteSettingsAsync()).As().RequireTwoFactorAuthentication; + return (await _siteService.GetSettingsAsync()).RequireTwoFactorAuthentication; } } diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs index 2e40d3110f1..e03996e5b82 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/UserService.cs @@ -47,7 +47,7 @@ public UserService( public async Task AuthenticateAsync(string usernameOrEmail, string password, Action reportError) { - var disableLocalLogin = (await _siteService.GetSiteSettingsAsync()).As().DisableLocalLogin; + var disableLocalLogin = (await _siteService.GetSettingsAsync()).DisableLocalLogin; if (disableLocalLogin) { From 863e7f1a2f6bf5fc1420ba53dd22bdad913df95e Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 29 May 2024 10:41:17 -0700 Subject: [PATCH 2/8] Fix build --- .../OrchardCore.Search/Controllers/SearchController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs index 07bc4d414c0..1620410a89c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search/Controllers/SearchController.cs @@ -68,8 +68,8 @@ public async Task Search(SearchViewModel viewModel, PagerSlimPara return View(); } - - var searchSettings = await _siteService.GetSettingsAsync(); + var siteSettings = await _siteService.GetSiteSettingsAsync(); + var searchSettings = siteSettings.As(); ISearchService searchService = null; if (!string.IsNullOrEmpty(searchSettings.ProviderName)) From eca91151aedc2d504105e2000aea768f9bb34f5c Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 29 May 2024 15:52:40 -0700 Subject: [PATCH 3/8] use expression bodied methods --- .../Login/Services/FacebookLoginService.cs | 5 ++--- .../OrchardCore.Facebook/Services/FacebookService.cs | 4 +--- .../Services/GithubAuthenticationService.cs | 5 ++--- .../Analytics/Services/GoogleAnalyticsService.cs | 4 +--- .../TagManager/Services/GoogleTagManagerService.cs | 4 +--- .../OrchardCore.Https/Services/HttpsService.cs | 4 +--- .../Services/AzureADService.cs | 4 +--- .../Services/MicrosoftAccountService.cs | 4 +--- .../OrchardCore.OpenId/Services/OpenIdClientService.cs | 4 +--- .../Services/ReverseProxyService.cs | 4 +--- .../Services/LuceneIndexingService.cs | 6 +----- .../Services/LuceneSearchService.cs | 4 +--- .../OrchardCore.Security/Services/SecurityService.cs | 4 +--- .../Services/TwitterSettingsService.cs | 4 +--- .../Signin/Services/TwitterSigninService.cs | 4 +--- .../Settings/SiteServiceExtensions.cs | 5 ++--- .../Services/ElasticIndexingService.cs | 8 ++------ .../Services/DefaultTwoFactorAuthenticationHandler.cs | 4 +--- 18 files changed, 22 insertions(+), 59 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs index 8a8b01e7a26..66e0b4028c3 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs @@ -20,9 +20,8 @@ public FacebookLoginService(ISiteService siteService) } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); + public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs index 7a3f4cb6963..2cf5856c730 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Services/FacebookService.cs @@ -24,9 +24,7 @@ public FacebookService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); public async Task UpdateSettingsAsync(FacebookSettings settings) { diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs index 0dad564eaca..ecf0c5d9453 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs @@ -23,9 +23,8 @@ public GitHubAuthenticationService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); + public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs index fd1c13225a6..70cacb3205d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/Analytics/Services/GoogleAnalyticsService.cs @@ -15,8 +15,6 @@ public GoogleAnalyticsService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs index 89073e5fd68..9462a1700e4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Google/TagManager/Services/GoogleTagManagerService.cs @@ -14,8 +14,6 @@ public GoogleTagManagerService(ISiteService siteService) } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs b/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs index db3587c82ba..cc12eec7fa2 100644 --- a/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Https/Services/HttpsService.cs @@ -14,8 +14,6 @@ public HttpsService(ISiteService siteService) } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs index bf27600393c..02a5e94ffb8 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/AzureADService.cs @@ -23,9 +23,7 @@ public AzureADService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs index b4bdc213e42..96dbc9055a0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Microsoft.Authentication/Services/MicrosoftAccountService.cs @@ -23,9 +23,7 @@ public MicrosoftAccountService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs index 20e15eb18b9..739a33ab9b8 100644 --- a/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs +++ b/src/OrchardCore.Modules/OrchardCore.OpenId/Services/OpenIdClientService.cs @@ -25,9 +25,7 @@ public OpenIdClientService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs index 09883b61877..69e16baa3ca 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReverseProxy/Services/ReverseProxyService.cs @@ -14,8 +14,6 @@ public ReverseProxyService(ISiteService siteService) } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs index 8e8d37441c8..c633e130e8d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneIndexingService.cs @@ -297,10 +297,6 @@ public async Task RebuildIndexAsync(string indexName) } public async Task GetLuceneSettingsAsync() - { - var luceneSettings = await _siteService.GetSettingsAsync(); - - return luceneSettings ?? new LuceneSettings(); - } + => await _siteService.GetSettingsAsync() ?? new LuceneSettings(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs index 53f935b9178..b5f21f6986b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Search.Lucene/Services/LuceneSearchService.cs @@ -79,9 +79,7 @@ public async Task SearchAsync(string indexName, string term, int s } private async Task DefaultIndexAsync() - { - return (await _siteService.GetSettingsAsync()).SearchIndex; - } + => (await _siteService.GetSettingsAsync()).SearchIndex; private async Task GetSearchFieldsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs b/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs index 286261e0bc1..11599cc8136 100644 --- a/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Security/Services/SecurityService.cs @@ -14,8 +14,6 @@ public SecurityService(ISiteService siteService) } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); } } diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs index 34920464d39..5905d377bad 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Services/TwitterSettingsService.cs @@ -23,9 +23,7 @@ public TwitterSettingsService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs index 6a2fec5298d..f71509297f0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Twitter/Signin/Services/TwitterSigninService.cs @@ -17,9 +17,7 @@ public TwitterSigninService( } public Task GetSettingsAsync() - { - return _siteService.GetSettingsAsync(); - } + => _siteService.GetSettingsAsync(); public async Task LoadSettingsAsync() { diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs index 81b9b32de9a..4d5df0d932a 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs @@ -5,7 +5,6 @@ namespace OrchardCore.Settings; public static class SiteServiceExtensions { public static async Task GetSettingsAsync(this ISiteService siteService) where T : new() - { - return (await siteService.GetSiteSettingsAsync()).As(); - } + => (await siteService.GetSiteSettingsAsync()).As(); + } diff --git a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs index 3542c23cc9d..55991703176 100644 --- a/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs +++ b/src/OrchardCore/OrchardCore.Search.Elasticsearch.Core/Services/ElasticIndexingService.cs @@ -279,12 +279,8 @@ public async Task RebuildIndexAsync(ElasticIndexSettings elasticIndexSettings) await ResetIndexAsync(elasticIndexSettings.IndexName); } - public async Task GetElasticSettingsAsync() - { - var elasticSettings = await _siteService.GetSettingsAsync(); - - return elasticSettings ?? new ElasticSettings(); - } + public async Task GetElasticSettingsAsync() + => await _siteService.GetSettingsAsync() ?? new ElasticSettings(); /// /// Synchronizes Elasticsearch content index settings with Lucene ones. diff --git a/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs b/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs index 21f2cc1cfa6..098e96f33e1 100644 --- a/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs +++ b/src/OrchardCore/OrchardCore.Users.Core/Services/DefaultTwoFactorAuthenticationHandler.cs @@ -15,7 +15,5 @@ public DefaultTwoFactorAuthenticationHandler(ISiteService siteService) } public async Task IsRequiredAsync(IUser user) - { - return (await _siteService.GetSettingsAsync()).RequireTwoFactorAuthentication; - } + => (await _siteService.GetSettingsAsync()).RequireTwoFactorAuthentication; } From 69aceba0d00e37bfe19fa8a0352500648ba21f1c Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 29 May 2024 16:00:08 -0700 Subject: [PATCH 4/8] cleanup --- .../Login/Services/FacebookLoginService.cs | 1 - .../Services/GithubAuthenticationService.cs | 1 - .../Drivers/RegisterUserFormDisplayDriver.cs | 4 ++-- .../Settings/SiteServiceExtensions.cs | 1 - 4 files changed, 2 insertions(+), 5 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs index 66e0b4028c3..19ae818b849 100644 --- a/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs +++ b/src/OrchardCore.Modules/OrchardCore.Facebook/Login/Services/FacebookLoginService.cs @@ -22,7 +22,6 @@ public FacebookLoginService(ISiteService siteService) public Task GetSettingsAsync() => _siteService.GetSettingsAsync(); - public async Task LoadSettingsAsync() { var container = await _siteService.LoadSiteSettingsAsync(); diff --git a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs index ecf0c5d9453..36acc67972b 100644 --- a/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs +++ b/src/OrchardCore.Modules/OrchardCore.GitHub/Services/GithubAuthenticationService.cs @@ -25,7 +25,6 @@ public GitHubAuthenticationService( public Task GetSettingsAsync() => _siteService.GetSettingsAsync(); - public async Task LoadSettingsAsync() { var container = await _siteService.LoadSiteSettingsAsync(); diff --git a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs index ec3bcf2b56b..412a1622cce 100644 --- a/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs +++ b/src/OrchardCore.Modules/OrchardCore.ReCaptcha/Drivers/RegisterUserFormDisplayDriver.cs @@ -18,9 +18,9 @@ public RegisterUserFormDisplayDriver(ISiteService siteService) public override async Task EditAsync(RegisterUserForm model, BuildEditorContext context) { - var _reCaptchaSettings = await _siteService.GetSettingsAsync(); + var reCaptchaSettings = await _siteService.GetSettingsAsync(); - if (!_reCaptchaSettings.IsValid()) + if (!reCaptchaSettings.IsValid()) { return null; } diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs index 4d5df0d932a..088e13e1c4a 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs @@ -6,5 +6,4 @@ public static class SiteServiceExtensions { public static async Task GetSettingsAsync(this ISiteService siteService) where T : new() => (await siteService.GetSiteSettingsAsync()).As(); - } From 446e487d9d8703d967479cb4c2051e3a85539a4b Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 29 May 2024 16:05:03 -0700 Subject: [PATCH 5/8] release notes --- src/docs/releases/2.0.0.md | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index 9deac8831e2..206117a8e56 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -515,3 +515,17 @@ public class ReverseProxySettingsDisplayDriver : SectionDisplayDriver()` has been added to `ISiteService` interface. This method allows you to retrieve specific settings with a single line of code. For example, to get the `LoginSettings`, you can now use: + +```csharp +await _siteService.GetSettingsAsync(); +``` + +Previously, achieving the same result required more code: + +```csharp +(await _siteService.GetSiteSettingsAsync()).As(); +``` From 0f47fbdaef60a0bc4004269fab2b3b92bb448336 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 29 May 2024 20:41:01 -0700 Subject: [PATCH 6/8] Update src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs Co-authored-by: Tony Han --- .../OrchardCore.Email/Migrations/EmailMigrations.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs b/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs index 490fcf2f96f..4c21c5a48b9 100644 --- a/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs +++ b/src/OrchardCore.Modules/OrchardCore.Email/Migrations/EmailMigrations.cs @@ -27,6 +27,7 @@ public int Create() return; } + var siteService = scope.ServiceProvider.GetRequiredService(); var smtpSettings = await siteService.GetSettingsAsync(); if (!string.IsNullOrEmpty(smtpSettings.DefaultSender) || From f137b0584f9471cfc950f88cd606d036846b5032 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 30 May 2024 21:04:38 -0700 Subject: [PATCH 7/8] Update 2.0.0.md Co-authored-by: Hisham Bin Ateya --- src/docs/releases/2.0.0.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/docs/releases/2.0.0.md b/src/docs/releases/2.0.0.md index 0cde9c051ab..96198fd6f91 100644 --- a/src/docs/releases/2.0.0.md +++ b/src/docs/releases/2.0.0.md @@ -518,7 +518,7 @@ Prior to this release, if you had a module with multiple features, you had to us ### Site Settings -A new extension method named `GetSettingsAsync()` has been added to `ISiteService` interface. This method allows you to retrieve specific settings with a single line of code. For example, to get the `LoginSettings`, you can now use: +A new extension method named `GetSettingsAsync()` has been added to the `ISiteService` interface. This method allows you to retrieve specific settings with a single line of code. For example, to get the `LoginSettings`, you can now use: ```csharp await _siteService.GetSettingsAsync(); From b8bdcd69f6b1fff9a901b6ee3c3a810b6a4f10cd Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Thu, 30 May 2024 21:53:58 -0700 Subject: [PATCH 8/8] comments --- .../Settings/SiteServiceExtensions.cs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs index 088e13e1c4a..4ac36da4716 100644 --- a/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs +++ b/src/OrchardCore/OrchardCore.Infrastructure.Abstractions/Settings/SiteServiceExtensions.cs @@ -4,6 +4,12 @@ namespace OrchardCore.Settings; public static class SiteServiceExtensions { + /// + /// Gets an instance of the specified settings if it exists. + /// + /// The type of the settings to attempt to get. + /// The site service. + /// An instance of the given type if one exists. public static async Task GetSettingsAsync(this ISiteService siteService) where T : new() => (await siteService.GetSiteSettingsAsync()).As(); }