From 42dd11d5ff5c45e7b234f06f776ce169122ad8b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sat, 13 Jul 2024 21:49:32 +0200 Subject: [PATCH 1/3] Moving Recipe into the model --- .../OrchardCore.Tenants/Controllers/TenantApiController.cs | 6 +++--- .../OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs | 2 ++ 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs index 3dd94882e39..1f0dc5f8c0c 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs @@ -295,7 +295,7 @@ public async Task Remove(string tenantName) [HttpPost] [Route("setup")] - public async Task Setup(SetupApiViewModel model, [FromForm] IFormFile recipe = null) + public async Task Setup(SetupApiViewModel model) { if (!_currentShellSettings.IsDefaultShell()) { @@ -393,7 +393,7 @@ public async Task Setup(SetupApiViewModel model, [FromForm] IFormF if (string.IsNullOrEmpty(recipeName)) { - if (recipe == null) + if (model.Recipe == null) { return BadRequest(S["Either a 'recipe' file or 'RecipeName' is required."]); } @@ -402,7 +402,7 @@ public async Task Setup(SetupApiViewModel model, [FromForm] IFormF using (var fs = System.IO.File.Create(tempFilename)) { - await recipe.CopyToAsync(fs); + await model.Recipe.CopyToAsync(fs); } var fileProvider = new PhysicalFileProvider(Path.GetDirectoryName(tempFilename)); diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs index 7a7e8ecaf54..f71c8dd30ec 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs @@ -1,4 +1,5 @@ using System.ComponentModel.DataAnnotations; +using Microsoft.AspNetCore.Http; namespace OrchardCore.Tenants.ViewModels { @@ -26,6 +27,7 @@ public class SetupApiViewModel public string Password { get; set; } public string RecipeName { get; set; } + public IFormFile Recipe { get; set; } public string SiteTimeZone { get; set; } From c723382f2ef1022d83b7fc6bcc5434a75d157b70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sun, 14 Jul 2024 00:19:00 +0200 Subject: [PATCH 2/3] Making the recipe a simple string, not a file --- .../Controllers/TenantApiController.cs | 9 +++------ .../OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs | 2 -- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs index 1f0dc5f8c0c..cb5fe559b0b 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs @@ -295,7 +295,7 @@ public async Task Remove(string tenantName) [HttpPost] [Route("setup")] - public async Task Setup(SetupApiViewModel model) + public async Task Setup(SetupApiViewModel model, string recipe = null) { if (!_currentShellSettings.IsDefaultShell()) { @@ -393,17 +393,14 @@ public async Task Setup(SetupApiViewModel model) if (string.IsNullOrEmpty(recipeName)) { - if (model.Recipe == null) + if (recipe == null) { return BadRequest(S["Either a 'recipe' file or 'RecipeName' is required."]); } var tempFilename = Path.GetTempFileName(); - using (var fs = System.IO.File.Create(tempFilename)) - { - await model.Recipe.CopyToAsync(fs); - } + await System.IO.File.WriteAllTextAsync(tempFilename, recipe); var fileProvider = new PhysicalFileProvider(Path.GetDirectoryName(tempFilename)); diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs index f71c8dd30ec..7a7e8ecaf54 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs @@ -1,5 +1,4 @@ using System.ComponentModel.DataAnnotations; -using Microsoft.AspNetCore.Http; namespace OrchardCore.Tenants.ViewModels { @@ -27,7 +26,6 @@ public class SetupApiViewModel public string Password { get; set; } public string RecipeName { get; set; } - public IFormFile Recipe { get; set; } public string SiteTimeZone { get; set; } From 617e6cac23aa48729926d10313b060e252712e5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zolt=C3=A1n=20Leh=C3=B3czky?= Date: Sun, 14 Jul 2024 00:26:20 +0200 Subject: [PATCH 3/3] Moving the recipe to the viewmodel --- .../Controllers/TenantApiController.cs | 6 +++--- .../OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs index cb5fe559b0b..599b24f5597 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/Controllers/TenantApiController.cs @@ -295,7 +295,7 @@ public async Task Remove(string tenantName) [HttpPost] [Route("setup")] - public async Task Setup(SetupApiViewModel model, string recipe = null) + public async Task Setup(SetupApiViewModel model) { if (!_currentShellSettings.IsDefaultShell()) { @@ -393,14 +393,14 @@ public async Task Setup(SetupApiViewModel model, string recipe = n if (string.IsNullOrEmpty(recipeName)) { - if (recipe == null) + if (model.Recipe == null) { return BadRequest(S["Either a 'recipe' file or 'RecipeName' is required."]); } var tempFilename = Path.GetTempFileName(); - await System.IO.File.WriteAllTextAsync(tempFilename, recipe); + await System.IO.File.WriteAllTextAsync(tempFilename, model.Recipe); var fileProvider = new PhysicalFileProvider(Path.GetDirectoryName(tempFilename)); diff --git a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs index 7a7e8ecaf54..6f92cb165aa 100644 --- a/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs +++ b/src/OrchardCore.Modules/OrchardCore.Tenants/ViewModels/SetupApiViewModel.cs @@ -25,8 +25,16 @@ public class SetupApiViewModel [DataType(DataType.Password)] public string Password { get; set; } + /// + /// The name of a recipe available in the app. + /// public string RecipeName { get; set; } + /// + /// A JSON string representing a custom recipe. + /// + public string Recipe { get; set; } + public string SiteTimeZone { get; set; } public string Schema { get; set; }