Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Seal and cleanup all recipe handlers #16464

Merged
merged 9 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace OrchardCore.AdminMenu.Recipes
/// <summary>
/// This recipe step creates a set of admin menus.
/// </summary>
public class AdminMenuStep : IRecipeStepHandler
public sealed class AdminMenuStep : IRecipeStepHandler
{
private readonly IAdminMenuService _adminMenuService;
private readonly JsonSerializerOptions _serializationOptions;
Expand Down Expand Up @@ -45,7 +45,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
// When the id is not supplied generate an id, otherwise replace the menu if it exists, or create a new menu.
if (string.IsNullOrEmpty(adminMenu.Id))
{
adminMenu.Id = Guid.NewGuid().ToString("n");
adminMenu.Id = IdGenerator.GenerateId();
}

await _adminMenuService.SaveAsync(adminMenu);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ namespace OrchardCore.ContentTypes.RecipeSteps
/// <summary>
/// This recipe step creates content definitions.
/// </summary>
public class ContentDefinitionStep : IRecipeStepHandler
public sealed class ContentDefinitionStep : IRecipeStepHandler
{
private readonly IContentDefinitionManager _contentDefinitionManager;

protected readonly IStringLocalizer S;
internal readonly IStringLocalizer S;

public ContentDefinitionStep(
IContentDefinitionManager contentDefinitionManager,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OrchardCore.ContentTypes.RecipeSteps
/// <summary>
/// This recipe step deletes content definition records.
/// </summary>
public class DeleteContentDefinitionStep : IRecipeStepHandler
public sealed class DeleteContentDefinitionStep : IRecipeStepHandler
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OrchardCore.ContentTypes.RecipeSteps
/// <summary>
/// This recipe step replaces content definition records.
/// </summary>
public class ReplaceContentDefinitionStep : IRecipeStepHandler
public sealed class ReplaceContentDefinitionStep : IRecipeStepHandler
{
private readonly IContentDefinitionManager _contentDefinitionManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OrchardCore.Contents.Recipes
/// <summary>
/// This recipe step creates a set of content items.
/// </summary>
public class ContentStep : IRecipeStepHandler
public sealed class ContentStep : IRecipeStepHandler
{
public Task ExecuteAsync(RecipeExecutionContext context)
{
Expand Down Expand Up @@ -43,7 +43,7 @@ public Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class ContentStepModel
public sealed class ContentStepModel
{
public JsonArray Data { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace OrchardCore.CustomSettings.Recipes
/// <summary>
/// This recipe step updates the site settings.
/// </summary>
public class CustomSettingsStep : IRecipeStepHandler
public sealed class CustomSettingsStep : IRecipeStepHandler
{
private readonly ISiteService _siteService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Json;
using OrchardCore.Recipes.Models;
Expand All @@ -15,20 +16,24 @@ namespace OrchardCore.Deployment.Recipes
/// <summary>
/// This recipe step creates a deployment plan.
/// </summary>
public class DeploymentPlansRecipeStep : IRecipeStepHandler
public sealed class DeploymentPlansRecipeStep : IRecipeStepHandler
{
private readonly IServiceProvider _serviceProvider;
private readonly JsonSerializerOptions _jsonSerializerOptions;
private readonly IDeploymentPlanService _deploymentPlanService;

internal readonly IStringLocalizer S;

public DeploymentPlansRecipeStep(
IServiceProvider serviceProvider,
IOptions<DocumentJsonSerializerOptions> jsonSerializerOptions,
IDeploymentPlanService deploymentPlanService)
IDeploymentPlanService deploymentPlanService,
IStringLocalizer<DeploymentPlansRecipeStep> stringLocalizer)
{
_serviceProvider = serviceProvider;
_jsonSerializerOptions = jsonSerializerOptions.Value.SerializerOptions;
_deploymentPlanService = deploymentPlanService;
S = stringLocalizer;
}

public Task ExecuteAsync(RecipeExecutionContext context)
Expand Down Expand Up @@ -71,10 +76,11 @@ public Task ExecuteAsync(RecipeExecutionContext context)

if (unknownTypes.Count != 0)
{
var prefix = "No changes have been made. The following types of deployment plans cannot be added:";
var suffix = "Please ensure that the related features are enabled to add these types of deployment plans.";
context.Errors.Add(
S["No changes have been made. The following types of deployment plans cannot be added: {0}. Please ensure that the related features are enabled to add these types of deployment plans.",
string.Join(", ", unknownTypes)]);

throw new InvalidOperationException($"{prefix} {string.Join(", ", unknownTypes)}. {suffix}");
return Task.CompletedTask;
}

return _deploymentPlanService.CreateOrUpdateDeploymentPlansAsync(deploymentPlans);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OrchardCore.Facebook.Login.Recipes
/// <summary>
/// This recipe step sets general Facebook Login settings.
/// </summary>
public class FacebookLoginSettingsStep : IRecipeStepHandler
public sealed class FacebookLoginSettingsStep : IRecipeStepHandler
{
private readonly IFacebookLoginService _loginService;

Expand All @@ -36,7 +36,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class FacebookLoginSettingsStepModel
public sealed class FacebookLoginSettingsStepModel
{
public string CallbackPath { get; set; }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace OrchardCore.Facebook.Recipes
/// <summary>
/// This recipe step sets general Facebook Login settings.
/// </summary>
public class FacebookSettingsStep : IRecipeStepHandler
public sealed class FacebookSettingsStep : IRecipeStepHandler
{
private readonly IFacebookService _facebookService;

Expand Down Expand Up @@ -40,7 +40,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class FacebookCoreSettingsStepModel
public sealed class FacebookCoreSettingsStepModel
{
public string AppId { get; set; }
public string AppSecret { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ namespace OrchardCore.Features.Recipes.Executors
/// <summary>
/// This recipe step enables or disables a set of features.
/// </summary>
public class FeatureStep : IRecipeStepHandler
public sealed class FeatureStep : IRecipeStepHandler
{
private readonly IShellFeaturesManager _shellFeaturesManager;

public FeatureStep(
IShellFeaturesManager shellFeaturesManager)
public FeatureStep(IShellFeaturesManager shellFeaturesManager)
{
_shellFeaturesManager = shellFeaturesManager;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OrchardCore.GitHub.Recipes
/// <summary>
/// This recipe step sets GitHub Account settings.
/// </summary>
public class GitHubAuthenticationSettingsStep : IRecipeStepHandler
public sealed class GitHubAuthenticationSettingsStep : IRecipeStepHandler
{
private readonly IGitHubAuthenticationService _githubAuthenticationService;

Expand All @@ -26,6 +26,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
{
return;
}

var model = context.Step.ToObject<GitHubLoginSettingsStepModel>();
var settings = await _githubAuthenticationService.LoadSettingsAsync();

Expand All @@ -37,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class GitHubLoginSettingsStepModel
public sealed class GitHubLoginSettingsStepModel
{
public string ConsumerKey { get; set; }
public string ConsumerSecret { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ namespace OrchardCore.Layers.Recipes
/// <summary>
/// This recipe step creates or updates a layer.
/// </summary>
public class LayerStep : IRecipeStepHandler
public sealed class LayerStep : IRecipeStepHandler
{
private readonly ILayerService _layerService;
private readonly IConditionIdGenerator _conditionIdGenerator;
private readonly IEnumerable<IConditionFactory> _factories;
private readonly JsonSerializerOptions _serializationOptions;

protected readonly IStringLocalizer S;
internal readonly IStringLocalizer S;

public LayerStep(
ILayerService layerService,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OrchardCore.Media.Recipes
/// <summary>
/// This recipe step creates or updates a media profile.
/// </summary>
public class MediaProfileStep : IRecipeStepHandler
public sealed class MediaProfileStep : IRecipeStepHandler
{
private readonly MediaProfilesManager _mediaProfilesManager;

Expand All @@ -37,7 +37,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class MediaProfileStepModel
public sealed class MediaProfileStepModel
{
public Dictionary<string, MediaProfile> MediaProfiles { get; set; }
}
Expand Down
13 changes: 7 additions & 6 deletions src/OrchardCore.Modules/OrchardCore.Media/Recipes/MediaStep.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
using System.Text.Json.Nodes;
using System.Threading.Tasks;
using Microsoft.Extensions.FileProviders;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Localization;
using Microsoft.Extensions.Options;
using OrchardCore.Recipes.Models;
using OrchardCore.Recipes.Services;
Expand All @@ -16,23 +16,24 @@ namespace OrchardCore.Media.Recipes
/// <summary>
/// This recipe step creates a set of queries.
/// </summary>
public class MediaStep : IRecipeStepHandler
public sealed class MediaStep : IRecipeStepHandler
{
private readonly IMediaFileStore _mediaFileStore;
private readonly HashSet<string> _allowedFileExtensions;
private readonly IHttpClientFactory _httpClientFactory;
private readonly ILogger _logger;

internal readonly IStringLocalizer S;

public MediaStep(
IMediaFileStore mediaFileStore,
IOptions<MediaOptions> options,
IHttpClientFactory httpClientFactory,
ILogger<MediaStep> logger)
IStringLocalizer<MediaStep> stringLocalizer)
{
_mediaFileStore = mediaFileStore;
_allowedFileExtensions = options.Value.AllowedFileExtensions;
_httpClientFactory = httpClientFactory;
_logger = logger;
S = stringLocalizer;
}

public async Task ExecuteAsync(RecipeExecutionContext context)
Expand All @@ -48,7 +49,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
{
if (!_allowedFileExtensions.Contains(Path.GetExtension(file.TargetPath), StringComparer.OrdinalIgnoreCase))
{
_logger.LogWarning("File extension not allowed: '{Path}'", file.TargetPath);
context.Errors.Add(S["File extension not allowed: '{0}'", file.TargetPath]);

continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OrchardCore.Microsoft.Authentication.Recipes
/// <summary>
/// This recipe step sets general Microsoft Entra ID settings.
/// </summary>
public class AzureADSettingsStep : IRecipeStepHandler
public sealed class AzureADSettingsStep : IRecipeStepHandler
{
private readonly IAzureADService _azureADService;

Expand Down Expand Up @@ -39,7 +39,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class AzureADSettingsStepModel
public sealed class AzureADSettingsStepModel
{
public string DisplayName { get; set; }
public string AppId { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OrchardCore.Microsoft.Authentication.Recipes
/// <summary>
/// This recipe step sets Microsoft Account settings.
/// </summary>
public class MicrosoftAccountSettingsStep : IRecipeStepHandler
public sealed class MicrosoftAccountSettingsStep : IRecipeStepHandler
{
private readonly IMicrosoftAccountService _microsoftAccountService;

Expand All @@ -38,7 +38,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class MicrosoftAccountSettingsStepModel
public sealed class MicrosoftAccountSettingsStepModel
{
public string AppId { get; set; }
public string AppSecret { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.OpenId.Recipes
{
public class OpenIdApplicationStep : IRecipeStepHandler
public sealed class OpenIdApplicationStep : IRecipeStepHandler
{
private readonly IOpenIdApplicationManager _applicationManager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace OrchardCore.OpenId.Recipes
/// <summary>
/// This recipe step sets general OpenID Connect Client settings.
/// </summary>
public class OpenIdClientSettingsStep : IRecipeStepHandler
public sealed class OpenIdClientSettingsStep : IRecipeStepHandler
{
private readonly IOpenIdClientService _clientService;

Expand Down Expand Up @@ -47,7 +47,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
}
}

public class OpenIdClientSettingsStepModel
public sealed class OpenIdClientSettingsStepModel
{
public string DisplayName { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace OrchardCore.OpenId.Recipes
{
public class OpenIdScopeStep : IRecipeStepHandler
public sealed class OpenIdScopeStep : IRecipeStepHandler
{
private readonly IOpenIdScopeManager _scopeManager;

Expand Down Expand Up @@ -46,8 +46,7 @@ public async Task ExecuteAsync(RecipeExecutionContext context)
{
descriptor.Resources.Clear();
descriptor.Resources.UnionWith(
model.Resources
.Split(' ', StringSplitOptions.RemoveEmptyEntries));
model.Resources.Split(' ', StringSplitOptions.RemoveEmptyEntries));
}

if (isNew)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace OrchardCore.OpenId.Recipes
/// <summary>
/// This recipe step sets general OpenID Connect settings.
/// </summary>
public class OpenIdServerSettingsStep : IRecipeStepHandler
public sealed class OpenIdServerSettingsStep : IRecipeStepHandler
{
private readonly IOpenIdServerService _serverService;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ namespace OrchardCore.OpenId.Recipes
/// <summary>
/// This recipe step sets Token Validation OpenID Connect settings.
/// </summary>
public class OpenIdValidationSettingsStep : IRecipeStepHandler
public sealed class OpenIdValidationSettingsStep : IRecipeStepHandler
{
private readonly IOpenIdValidationService _validationService;

public OpenIdValidationSettingsStep(
IOpenIdValidationService validationService)
public OpenIdValidationSettingsStep(IOpenIdValidationService validationService)
{
_validationService = validationService;
}
Expand Down
Loading