From c3c2d82bfff9318a58c8381977cafa5c0c21332a Mon Sep 17 00:00:00 2001 From: hyzx86 Date: Sat, 6 Jan 2024 21:00:28 +0800 Subject: [PATCH 01/18] Add media filenames on MediaFieldType --- .../GraphQL/MediaFieldQueryObjectType.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 2f9b2cf328c..7fe0cce8dfb 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -27,6 +27,20 @@ public MediaFieldQueryObjectType() return x.Page(x.Source.Paths); }); + Field, IEnumerable>() + .Name("fileNames") + .Description("the media fileNames") + .PagingArguments() + .Resolve(x => + { + var fileNames = x.Page(x.Source.GetAttachedFileNames()); + if (fileNames is null) + { + return Array.Empty(); + } + return fileNames; + }); + Field, IEnumerable>() .Name("urls") .Description("the absolute urls of the media items") From 7fdfddd2182f3424db3370830cdd27ea582a8bfe Mon Sep 17 00:00:00 2001 From: hyzx86 Date: Sun, 7 Jan 2024 18:37:33 +0800 Subject: [PATCH 02/18] add MediaFileItemType --- .../GraphQL/MediaFieldQueryObjectType.cs | 50 ++++++++++++++++++- 1 file changed, 48 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 7fe0cce8dfb..7f8182c29e0 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -33,12 +33,12 @@ public MediaFieldQueryObjectType() .PagingArguments() .Resolve(x => { - var fileNames = x.Page(x.Source.GetAttachedFileNames()); + var fileNames = x.Source?.GetAttachedFileNames(); if (fileNames is null) { return Array.Empty(); } - return fileNames; + return x.Page(fileNames); }); Field, IEnumerable>() @@ -55,6 +55,52 @@ public MediaFieldQueryObjectType() var mediaFileStore = x.RequestServices.GetService(); return paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)); }); + + Field, IEnumerable>() + .Name("files") + .Description("the files of the media items") + .PagingArguments() + .Resolve(x => + { + if (x.Source?.Paths is null) + { + return Array.Empty(); + } + + var paths = x.Page(x.Source.Paths).ToArray(); + var mediaFileStore = x.RequestServices.GetService(); + var urls = paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)).ToArray(); + var fileNames = x.Page(x.Source?.GetAttachedFileNames()).ToArray(); + + var items = new List(); + for (int i = 0; i < paths.Length; i++) + { + items.Add(new MediaFileItem + { + Path = paths[i], + FileName = fileNames.Length > i ? fileNames[i] : string.Empty, + Url = urls.Length > i ? urls[i] : string.Empty + }); + } + + return items; + }); + } + } + + public class MediaFileItemType : ObjectGraphType + { + public MediaFileItemType() + { + Field("fileName", "the file name of the media file item", resolve: x => x.Source.FileName); + Field("path", "the path of the media file item", resolve: x => x.Source.Path); + Field("url", "the url name of the media file item", resolve: x => x.Source.Url); } } + public class MediaFileItem + { + public string FileName { get; set; } + public string Path { get; set; } + public string Url { get; set; } + } } From 78f1585bfccee94ff5994ed7e46cd91f103ae69b Mon Sep 17 00:00:00 2001 From: Tony Han Date: Sun, 7 Jan 2024 18:44:18 +0800 Subject: [PATCH 03/18] Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 7f8182c29e0..66effb384be 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -29,7 +29,7 @@ public MediaFieldQueryObjectType() Field, IEnumerable>() .Name("fileNames") - .Description("the media fileNames") + .Description("the media file names") .PagingArguments() .Resolve(x => { From b3c148433c6e4c17245a881523f80ede7e3acabb Mon Sep 17 00:00:00 2001 From: hyzx86 Date: Sun, 7 Jan 2024 18:45:14 +0800 Subject: [PATCH 04/18] fix code style --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 7f8182c29e0..7695e399215 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -24,6 +24,7 @@ public MediaFieldQueryObjectType() { return Array.Empty(); } + return x.Page(x.Source.Paths); }); @@ -38,6 +39,7 @@ public MediaFieldQueryObjectType() { return Array.Empty(); } + return x.Page(fileNames); }); @@ -53,6 +55,7 @@ public MediaFieldQueryObjectType() } var paths = x.Page(x.Source.Paths); var mediaFileStore = x.RequestServices.GetService(); + return paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)); }); @@ -97,6 +100,7 @@ public MediaFileItemType() Field("url", "the url name of the media file item", resolve: x => x.Source.Url); } } + public class MediaFileItem { public string FileName { get; set; } From 778a4724176d44274393e972892fac6ef714c65a Mon Sep 17 00:00:00 2001 From: Tony Han Date: Wed, 10 Jan 2024 10:59:45 +0800 Subject: [PATCH 05/18] Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs Co-authored-by: Hisham Bin Ateya --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index ed598611475..fe4a5e7522d 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -74,7 +74,6 @@ public MediaFieldQueryObjectType() var mediaFileStore = x.RequestServices.GetService(); var urls = paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)).ToArray(); var fileNames = x.Page(x.Source?.GetAttachedFileNames()).ToArray(); - var items = new List(); for (int i = 0; i < paths.Length; i++) { From f24484d9558c16dca6c0ce493c26606cc664490a Mon Sep 17 00:00:00 2001 From: hyzx86 Date: Sun, 18 Feb 2024 14:07:07 +0800 Subject: [PATCH 06/18] fix new graphql API --- .../GraphQL/MediaFieldQueryObjectType.cs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index b47f0205a3d..63156bee538 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -28,7 +28,7 @@ public MediaFieldQueryObjectType() }); Field, IEnumerable>("fileNames") - .Description("the media fileNames") + .Description("the media file names") .PagingArguments() .Resolve(x => { @@ -55,8 +55,7 @@ public MediaFieldQueryObjectType() return paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)); }); - Field, IEnumerable>() - .Name("files") + Field, IEnumerable>("files") .Description("the files of the media items") .PagingArguments() .Resolve(x => @@ -90,9 +89,9 @@ public class MediaFileItemType : ObjectGraphType { public MediaFileItemType() { - Field("fileName", "the file name of the media file item", resolve: x => x.Source.FileName); - Field("path", "the path of the media file item", resolve: x => x.Source.Path); - Field("url", "the url name of the media file item", resolve: x => x.Source.Url); + Field("fileName").Description("the file name of the media file item").Resolve(x => x.Source.FileName); + Field("path").Description("the path of the media file item").Resolve(x => x.Source.Path); + Field("url").Description("the url name of the media file item").Resolve(x => x.Source.Url); } } From 8c9c2b64f355547bf5a61ca58fe8a8b1473e8b7e Mon Sep 17 00:00:00 2001 From: hyzx86 Date: Tue, 2 Jul 2024 12:20:19 +0800 Subject: [PATCH 07/18] add MediaText --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 761d5cf935e..b68ca8fc769 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -70,18 +70,20 @@ public MediaFieldQueryObjectType() var urls = paths.Select(p => mediaFileStore.MapPathToPublicUrl(p)).ToArray(); var fileNames = x.Page(x.Source?.GetAttachedFileNames()).ToArray(); var items = new List(); + var mediaTexts = x.Source?.MediaTexts ?? []; for (int i = 0; i < paths.Length; i++) { items.Add(new MediaFileItem { Path = paths[i], FileName = fileNames.Length > i ? fileNames[i] : string.Empty, - Url = urls.Length > i ? urls[i] : string.Empty + Url = urls.Length > i ? urls[i] : string.Empty, + MediaText = mediaTexts.Length > i ? mediaTexts[i] : string.Empty, }); } return items; - }); + }); Field, IEnumerable>("mediatexts") .Description("the media texts") @@ -113,5 +115,6 @@ public class MediaFileItem public string FileName { get; set; } public string Path { get; set; } public string Url { get; set; } + public string MediaText { get; set; } } } From f14109a9f11a5242d04ca8ccecfef91e4350e7c5 Mon Sep 17 00:00:00 2001 From: hyzx86 Date: Tue, 2 Jul 2024 17:36:35 +0800 Subject: [PATCH 08/18] remove empty line --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index b68ca8fc769..b1e291ae361 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -95,7 +95,6 @@ public MediaFieldQueryObjectType() return Array.Empty(); } return x.Page(x.Source.MediaTexts); - }); } } From 4df84976cce0c38b2093148be8830969802c8a23 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 24 Jul 2024 13:36:42 -0700 Subject: [PATCH 09/18] Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index b1e291ae361..d01542776c4 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -62,7 +62,7 @@ public MediaFieldQueryObjectType() { if (x.Source?.Paths is null) { - return Array.Empty(); + return []; } var paths = x.Page(x.Source.Paths).ToArray(); From 528c6d837ecd9b1792314f9c1c6bd6f354d82612 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 24 Jul 2024 13:37:13 -0700 Subject: [PATCH 10/18] Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index d01542776c4..41712d46b10 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -99,7 +99,7 @@ public MediaFieldQueryObjectType() } } - public class MediaFileItemType : ObjectGraphType + public sealed class MediaFileItemType : ObjectGraphType { public MediaFileItemType() { From 868c1f78c4f4a49e4eaa40481b8df31607ebc02f Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Wed, 24 Jul 2024 13:37:28 -0700 Subject: [PATCH 11/18] Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 41712d46b10..0d38cd1cb41 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -109,7 +109,7 @@ public MediaFileItemType() } } - public class MediaFileItem + public sealed class MediaFileItem { public string FileName { get; set; } public string Path { get; set; } From a01632b49ac416c475899af9cf2747787f32cd8d Mon Sep 17 00:00:00 2001 From: Tony Han Date: Fri, 26 Jul 2024 00:18:15 +0800 Subject: [PATCH 12/18] Update MediaFieldQueryObjectType.cs --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index 0d38cd1cb41..a7c4a6971db 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -106,6 +106,7 @@ public MediaFileItemType() Field("fileName").Description("the file name of the media file item").Resolve(x => x.Source.FileName); Field("path").Description("the path of the media file item").Resolve(x => x.Source.Path); Field("url").Description("the url name of the media file item").Resolve(x => x.Source.Url); + Field("mediaText").Description("the media text of the file item").Resolve(x => x.Source.MediaText ); } } From 912616ccccbd133ecefce597c2428467a0ea35b9 Mon Sep 17 00:00:00 2001 From: Tony Han Date: Fri, 26 Jul 2024 00:24:22 +0800 Subject: [PATCH 13/18] Update src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs --- .../OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs index a7c4a6971db..93981a76b7c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/GraphQL/MediaFieldQueryObjectType.cs @@ -106,7 +106,7 @@ public MediaFileItemType() Field("fileName").Description("the file name of the media file item").Resolve(x => x.Source.FileName); Field("path").Description("the path of the media file item").Resolve(x => x.Source.Path); Field("url").Description("the url name of the media file item").Resolve(x => x.Source.Url); - Field("mediaText").Description("the media text of the file item").Resolve(x => x.Source.MediaText ); + Field("mediaText").Description("the media text of the file item").Resolve(x => x.Source.MediaText); } } From de11ba80b747dad6ebe561ed47f30ed8c9d2cf95 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 26 Jul 2024 10:28:25 -0700 Subject: [PATCH 14/18] Handle invalid recipe files from breaking the harvester (#16490) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --------- Co-authored-by: Zoltán Lehóczky --- .../Services/RecipeHarvester.cs | 9 +++++-- .../Services/RecipeMigrator.cs | 11 +++++++- .../Services/RecipeReader.cs | 27 ++++++++++++++++--- .../Apis/Context/TestRecipeHarvester.cs | 6 +++++ 4 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeHarvester.cs b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeHarvester.cs index f418ff2b5d6..3099fd3db77 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeHarvester.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeHarvester.cs @@ -32,7 +32,7 @@ public RecipeHarvester( /// public virtual Task> HarvestRecipesAsync() - => _extensionManager.GetExtensions().InvokeAsync(HarvestRecipes, _logger); + => _extensionManager.GetExtensions().InvokeAsync(GetRecipesAsync, _logger); /// /// Returns a list of recipes for a content path. @@ -50,13 +50,18 @@ protected async Task> HarvestRecipesAsync(string p { var recipeDescriptor = await _recipeReader.GetRecipeDescriptorAsync(path, recipeFile, _hostingEnvironment.ContentRootFileProvider); + if (recipeDescriptor == null) + { + continue; + } + recipeDescriptors.Add(recipeDescriptor); } return recipeDescriptors; } - private Task> HarvestRecipes(IExtensionInfo extension) + private Task> GetRecipesAsync(IExtensionInfo extension) { var folderSubPath = PathExtensions.Combine(extension.SubPath, RecipesConstants.RecipesFolderName); diff --git a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeMigrator.cs b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeMigrator.cs index 2ae164a9897..91215655429 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeMigrator.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeMigrator.cs @@ -45,14 +45,23 @@ public async Task ExecuteAsync(string recipeFileName, IDataMigration mig var recipeFilePath = Path.Combine(recipeBasePath, recipeFileName).Replace('\\', '/'); var recipeFileInfo = _hostingEnvironment.ContentRootFileProvider.GetFileInfo(recipeFilePath); var recipeDescriptor = await _recipeReader.GetRecipeDescriptorAsync(recipeBasePath, recipeFileInfo, _hostingEnvironment.ContentRootFileProvider); + + if (recipeDescriptor == null) + { + return null; + } + recipeDescriptor.RequireNewScope = false; var environment = new Dictionary(); - await _environmentProviders.OrderBy(x => x.Order).InvokeAsync((provider, env) => provider.PopulateEnvironmentAsync(env), environment, _logger); + await _environmentProviders.OrderBy(x => x.Order) + .InvokeAsync((provider, env) => provider.PopulateEnvironmentAsync(env), environment, _logger); var executionId = Guid.NewGuid().ToString("n"); + return await _recipeExecutor.ExecuteAsync(executionId, recipeDescriptor, environment, CancellationToken.None); } } } + diff --git a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeReader.cs b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeReader.cs index 5a718e854f2..a922d33b3e1 100644 --- a/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeReader.cs +++ b/src/OrchardCore/OrchardCore.Recipes.Core/Services/RecipeReader.cs @@ -1,22 +1,41 @@ +using System; using System.Text.Json; using System.Threading.Tasks; using Microsoft.Extensions.FileProviders; +using Microsoft.Extensions.Logging; using OrchardCore.Recipes.Models; namespace OrchardCore.Recipes.Services { public class RecipeReader : IRecipeReader { + private readonly ILogger _logger; + + public RecipeReader(ILogger logger) + { + _logger = logger; + } + public async Task GetRecipeDescriptorAsync(string recipeBasePath, IFileInfo recipeFileInfo, IFileProvider recipeFileProvider) { // TODO: Try to optimize by only reading the required metadata instead of the whole file. using var stream = recipeFileInfo.CreateReadStream(); - var recipeDescriptor = await JsonSerializer.DeserializeAsync(stream, JOptions.Default); + RecipeDescriptor recipeDescriptor = null; + + try + { + recipeDescriptor = await JsonSerializer.DeserializeAsync(stream, JOptions.Default); + + recipeDescriptor.FileProvider = recipeFileProvider; + recipeDescriptor.BasePath = recipeBasePath; + recipeDescriptor.RecipeFileInfo = recipeFileInfo; - recipeDescriptor.FileProvider = recipeFileProvider; - recipeDescriptor.BasePath = recipeBasePath; - recipeDescriptor.RecipeFileInfo = recipeFileInfo; + } + catch (Exception ex) + { + _logger.LogError(ex, "Unable to deserialize the recipe file: '{FileName}'.", recipeFileInfo.Name); + } return recipeDescriptor; } diff --git a/test/OrchardCore.Tests/Apis/Context/TestRecipeHarvester.cs b/test/OrchardCore.Tests/Apis/Context/TestRecipeHarvester.cs index 9f7803f376f..19bef681e49 100644 --- a/test/OrchardCore.Tests/Apis/Context/TestRecipeHarvester.cs +++ b/test/OrchardCore.Tests/Apis/Context/TestRecipeHarvester.cs @@ -37,6 +37,12 @@ private async Task> HarvestRecipesAsync(string[] p foreach (var fileInfo in fileInfos) { var descriptor = await _recipeReader.GetRecipeDescriptorAsync(fileInfo.PhysicalPath, fileInfo, testAssemblyFileProvider); + + if (descriptor == null) + { + continue; + } + recipeDescriptors.Add(descriptor); } From 9df8f0527385494c29ffd13abe5d940ef627deea Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 26 Jul 2024 16:17:49 -0700 Subject: [PATCH 15/18] Add RemovePart extension (#16491) --- .../Metadata/Builders/ContentTypeDefinitionBuilder.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentTypeDefinitionBuilder.cs b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentTypeDefinitionBuilder.cs index cc120828701..bb76ac8cda7 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentTypeDefinitionBuilder.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Abstractions/Metadata/Builders/ContentTypeDefinitionBuilder.cs @@ -102,6 +102,10 @@ public ContentTypeDefinitionBuilder WithSettings(T settings) return this; } + public ContentTypeDefinitionBuilder RemovePart() + where TPart : ContentPart + => RemovePart(typeof(TPart).Name); + public ContentTypeDefinitionBuilder RemovePart(string partName) { var existingPart = _parts.SingleOrDefault(x => string.Equals(x.Name, partName, StringComparison.OrdinalIgnoreCase)); From 8366a897a898252a332c10d30f0f800ccee1e28a Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Fri, 26 Jul 2024 16:28:18 -0700 Subject: [PATCH 16/18] Move Media Permissions to Media.Core (#16493) --- .../OrchardCore.Media/PermissionProvider.cs | 60 ++++++++++++++++ .../OrchardCore.Media/Permissions.cs | 68 ------------------- .../OrchardCore.Media/Startup.cs | 2 +- .../OrchardCore.Media.Core.csproj | 1 + .../OrchardCore.Media.Core/Permissions.cs | 20 ++++++ 5 files changed, 82 insertions(+), 69 deletions(-) create mode 100644 src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs delete mode 100644 src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs create mode 100644 src/OrchardCore/OrchardCore.Media.Core/Permissions.cs diff --git a/src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs b/src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs new file mode 100644 index 00000000000..df89cdeffe2 --- /dev/null +++ b/src/OrchardCore.Modules/OrchardCore.Media/PermissionProvider.cs @@ -0,0 +1,60 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using OrchardCore.Security.Permissions; + +namespace OrchardCore.Media; + +public sealed class PermissionProvider : IPermissionProvider +{ + private readonly IEnumerable _allPermissions = + [ + Permissions.ManageMedia, + Permissions.ManageMediaFolder, + Permissions.ManageOthersMedia, + Permissions.ManageOwnMedia, + Permissions.ManageAttachedMediaFieldsFolder, + Permissions.ManageMediaProfiles, + Permissions.ViewMediaOptions, + ]; + + private readonly IEnumerable _generalPermissions = + [ + Permissions.ManageOwnMedia, + ]; + + public Task> GetPermissionsAsync() + => Task.FromResult(_allPermissions); + + public IEnumerable GetDefaultStereotypes() => + [ + new PermissionStereotype + { + Name = OrchardCoreConstants.Roles.Administrator, + Permissions = + [ + Permissions.ManageMediaFolder, + Permissions.ManageMediaProfiles, + Permissions.ViewMediaOptions, + ], + }, + new PermissionStereotype + { + Name = OrchardCoreConstants.Roles.Editor, + Permissions = + [ + Permissions.ManageMedia, + Permissions.ManageOwnMedia, + ], + }, + new PermissionStereotype + { + Name = OrchardCoreConstants.Roles.Author, + Permissions = _generalPermissions, + }, + new PermissionStereotype + { + Name = OrchardCoreConstants.Roles.Contributor, + Permissions = _generalPermissions, + }, + ]; +} diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs b/src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs deleted file mode 100644 index 07189c033e7..00000000000 --- a/src/OrchardCore.Modules/OrchardCore.Media/Permissions.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.Collections.Generic; -using System.Threading.Tasks; -using OrchardCore.Security.Permissions; - -namespace OrchardCore.Media; - -public sealed class Permissions : IPermissionProvider -{ - public static readonly Permission ManageMediaFolder = new("ManageMediaFolder", "Manage All Media Folders"); - public static readonly Permission ManageOthersMedia = new("ManageOthersMediaContent", "Manage Media For Others", [ManageMediaFolder]); - public static readonly Permission ManageOwnMedia = new("ManageOwnMediaContent", "Manage Own Media", [ManageOthersMedia]); - public static readonly Permission ManageMedia = new("ManageMediaContent", "Manage Media", [ManageOwnMedia]); - public static readonly Permission ManageAttachedMediaFieldsFolder = new("ManageAttachedMediaFieldsFolder", "Manage Attached Media Fields Folder", [ManageMediaFolder]); - public static readonly Permission ManageMediaProfiles = new("ManageMediaProfiles", "Manage Media Profiles"); - public static readonly Permission ViewMediaOptions = new("ViewMediaOptions", "View Media Options"); - - private readonly IEnumerable _allPermissions = - [ - ManageMedia, - ManageMediaFolder, - ManageOthersMedia, - ManageOwnMedia, - ManageAttachedMediaFieldsFolder, - ManageMediaProfiles, - ViewMediaOptions, - ]; - - private readonly IEnumerable _generalPermissions = - [ - ManageOwnMedia, - ]; - - public Task> GetPermissionsAsync() - => Task.FromResult(_allPermissions); - - public IEnumerable GetDefaultStereotypes() => - [ - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Administrator, - Permissions = - [ - ManageMediaFolder, - ManageMediaProfiles, - ViewMediaOptions, - ], - }, - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Editor, - Permissions = - [ - ManageMedia, - ManageOwnMedia, - ], - }, - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Author, - Permissions = _generalPermissions, - }, - new PermissionStereotype - { - Name = OrchardCoreConstants.Roles.Contributor, - Permissions = _generalPermissions, - }, - ]; -} diff --git a/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs b/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs index 6e10cdd0447..7e71d267ffc 100644 --- a/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs +++ b/src/OrchardCore.Modules/OrchardCore.Media/Startup.cs @@ -137,7 +137,7 @@ public override void ConfigureServices(IServiceCollection services) return new DefaultMediaFileStore(fileStore, mediaUrlBase, mediaOptions.CdnBaseUrl, mediaEventHandlers, mediaCreatingEventHandlers, logger); }); - services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped(); diff --git a/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj b/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj index 7d26603eee8..907a06719de 100644 --- a/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj +++ b/src/OrchardCore/OrchardCore.Media.Core/OrchardCore.Media.Core.csproj @@ -15,6 +15,7 @@ + diff --git a/src/OrchardCore/OrchardCore.Media.Core/Permissions.cs b/src/OrchardCore/OrchardCore.Media.Core/Permissions.cs new file mode 100644 index 00000000000..e9b16efff45 --- /dev/null +++ b/src/OrchardCore/OrchardCore.Media.Core/Permissions.cs @@ -0,0 +1,20 @@ +using OrchardCore.Security.Permissions; + +namespace OrchardCore.Media; + +public static class Permissions +{ + public static readonly Permission ManageMediaFolder = new("ManageMediaFolder", "Manage All Media Folders"); + + public static readonly Permission ManageOthersMedia = new("ManageOthersMediaContent", "Manage Media For Others", [ManageMediaFolder]); + + public static readonly Permission ManageOwnMedia = new("ManageOwnMediaContent", "Manage Own Media", [ManageOthersMedia]); + + public static readonly Permission ManageMedia = new("ManageMediaContent", "Manage Media", [ManageOwnMedia]); + + public static readonly Permission ManageAttachedMediaFieldsFolder = new("ManageAttachedMediaFieldsFolder", "Manage Attached Media Fields Folder", [ManageMediaFolder]); + + public static readonly Permission ManageMediaProfiles = new("ManageMediaProfiles", "Manage Media Profiles"); + + public static readonly Permission ViewMediaOptions = new("ViewMediaOptions", "View Media Options"); +} From 3c997051fd3263e602b5959641372b0449fde091 Mon Sep 17 00:00:00 2001 From: lampersky Date: Sat, 27 Jul 2024 01:41:29 +0200 Subject: [PATCH 17/18] Fix that you can't add a content part when it's already added as a Named Part (#16495) --- .../OrchardCore.ContentTypes/Controllers/AdminController.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs index d1a690672b8..a76bc76d15d 100644 --- a/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs +++ b/src/OrchardCore.Modules/OrchardCore.ContentTypes/Controllers/AdminController.cs @@ -249,7 +249,7 @@ public async Task AddPartsTo(string id) return NotFound(); } - var typePartNames = new HashSet(typeViewModel.TypeDefinition.Parts.Select(p => p.PartDefinition.Name)); + var typePartNames = new HashSet(typeViewModel.TypeDefinition.Parts.Select(p => p.IsNamedPart() ? p.Name : p.PartDefinition.Name)); var viewModel = new AddPartsViewModel { From 6ea02dfa3c53e50a194d00b615c140d0c5a79eb1 Mon Sep 17 00:00:00 2001 From: Mike Alhayek Date: Sun, 28 Jul 2024 16:22:08 -0700 Subject: [PATCH 18/18] Add CanHandleModelAsync (#16501) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Zoltán Lehóczky --- .../ContentDisplay/ContentDisplayDriver.cs | 11 ++--- .../Handlers/DisplayDriver.cs | 44 +++++++++++++------ 2 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentDisplayDriver.cs b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentDisplayDriver.cs index 437296f58d3..cbd71cd0754 100644 --- a/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentDisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.ContentManagement.Display/ContentDisplay/ContentDisplayDriver.cs @@ -1,12 +1,7 @@ using OrchardCore.DisplayManagement.Handlers; -namespace OrchardCore.ContentManagement.Display.ContentDisplay +namespace OrchardCore.ContentManagement.Display.ContentDisplay; + +public abstract class ContentDisplayDriver : DisplayDriver, IContentDisplayDriver { - public abstract class ContentDisplayDriver : DisplayDriver, IContentDisplayDriver - { - public override bool CanHandleModel(ContentItem model) - { - return true; - } - } } diff --git a/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs b/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs index 3aadeb682e2..98f53ef93c1 100644 --- a/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs +++ b/src/OrchardCore/OrchardCore.DisplayManagement/Handlers/DisplayDriver.cs @@ -15,48 +15,59 @@ public abstract class DisplayDriver - /// Returns true if the model can be handle by the current driver. + /// Returns if the model can be handled by the current driver. /// - /// + /// + /// Override instead if your code is asynchronous. + /// public virtual bool CanHandleModel(TModel model) { return true; } - Task IDisplayDriver.BuildDisplayAsync(TModel model, TDisplayContext context) + /// + /// Returns if the model can be handled by the current driver. + /// + /// + /// Override instead if your code is synchronous. + /// + public virtual Task CanHandleModelAsync(TModel model) + => Task.FromResult(CanHandleModel(model)); + + async Task IDisplayDriver.BuildDisplayAsync(TModel model, TDisplayContext context) { - if (!CanHandleModel(model)) + if (!await CanHandleModelAsync(model)) { - return Task.FromResult(null); + return null; } BuildPrefix(model, context.HtmlFieldPrefix); - return DisplayAsync(model, context); + return await DisplayAsync(model, context); } - Task IDisplayDriver.BuildEditorAsync(TModel model, TEditorContext context) + async Task IDisplayDriver.BuildEditorAsync(TModel model, TEditorContext context) { - if (!CanHandleModel(model)) + if (!await CanHandleModelAsync(model)) { - return Task.FromResult(null); + return null; } BuildPrefix(model, context.HtmlFieldPrefix); - return EditAsync(model, context); + return await EditAsync(model, context); } - Task IDisplayDriver.UpdateEditorAsync(TModel model, TUpdateContext context) + async Task IDisplayDriver.UpdateEditorAsync(TModel model, TUpdateContext context) { - if (!CanHandleModel(model)) + if (!await CanHandleModelAsync(model)) { - return Task.FromResult(null); + return null; } BuildPrefix(model, context.HtmlFieldPrefix); - return UpdateAsync(model, context); + return await UpdateAsync(model, context); } public virtual Task DisplayAsync(TModel model, TDisplayContext context) @@ -94,6 +105,11 @@ public virtual IDisplayResult Edit(TModel model, IUpdateModel updater) return Edit(model); } + public virtual IDisplayResult Edit(TModel model, TEditorContext context) + { + return Edit(model, context.Updater); + } + public virtual IDisplayResult Edit(TModel model) { return NullShapeResult();