Fixes routing for installer to use an area, fixes URL generation
This commit is contained in:
@@ -49,6 +49,11 @@
|
||||
/// The default authentication type used for remembering that 2FA is not needed on next login
|
||||
/// </summary>
|
||||
public const string TwoFactorRememberBrowserCookie = "TwoFactorRememberBrowser";
|
||||
|
||||
public static class Mvc
|
||||
{
|
||||
public const string InstallArea = "UmbracoInstall";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ using Umbraco.Core;
|
||||
using Umbraco.Web.Common.Controllers;
|
||||
using Umbraco.Extensions;
|
||||
using Umbraco.Web.WebApi;
|
||||
using Microsoft.AspNetCore.Mvc.Routing;
|
||||
|
||||
namespace Umbraco.Extensions
|
||||
{
|
||||
@@ -101,30 +102,26 @@ namespace Umbraco.Extensions
|
||||
if (controllerName == null) throw new ArgumentNullException(nameof(controllerName));
|
||||
if (string.IsNullOrWhiteSpace(controllerName)) throw new ArgumentException("Value can't be empty or consist only of white-space characters.", nameof(controllerName));
|
||||
|
||||
string routeName;
|
||||
if (area.IsNullOrWhiteSpace())
|
||||
{
|
||||
routeName = string.Format("umbraco-{0}-{1}", "api", controllerName);
|
||||
if (id == null)
|
||||
{
|
||||
|
||||
return url.RouteUrl(routeName, new { controller = controllerName, action = actionName, httproute = "" });
|
||||
return url.Action(actionName, controllerName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return url.RouteUrl(routeName, new { controller = controllerName, action = actionName, id = id, httproute = "" });
|
||||
return url.Action(actionName, controllerName, new { id = id });
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
routeName = string.Format("umbraco-{0}-{1}-{2}", "api", area, controllerName);
|
||||
if (id == null)
|
||||
{
|
||||
return url.RouteUrl(routeName, new { controller = controllerName, action = actionName, httproute = "" });
|
||||
return url.Action(actionName, controllerName, new { area = area });
|
||||
}
|
||||
else
|
||||
{
|
||||
return url.RouteUrl(routeName, new { controller = controllerName, action = actionName, id = id, httproute = "" });
|
||||
return url.Action(actionName, controllerName, new { area = area, id = id });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,11 +27,19 @@ namespace Umbraco.Extensions
|
||||
case RuntimeLevel.Install:
|
||||
case RuntimeLevel.Upgrade:
|
||||
|
||||
// TODO: Fix this routing with an area
|
||||
endpoints.MapControllerRoute("Install", "/install/{controller}/{Action}", defaults: new { Area = "Install" });
|
||||
var installPath = uriUtility.ToAbsolute(Constants.SystemDirectories.Install).EnsureEndsWith('/');
|
||||
|
||||
// TODO register routing correct: Name must be like this
|
||||
endpoints.MapControllerRoute("umbraco-api-UmbracoInstall-InstallApi", "/install/api/{Action}", defaults: new { Area = "Install", Controller = "InstallApi" });
|
||||
endpoints.MapAreaControllerRoute(
|
||||
"umbraco-install-api",
|
||||
Umbraco.Core.Constants.Web.Mvc.InstallArea,
|
||||
$"{installPath}api/{{Action}}",
|
||||
new { controller = "InstallApi" });
|
||||
|
||||
endpoints.MapAreaControllerRoute(
|
||||
"umbraco-install",
|
||||
Umbraco.Core.Constants.Web.Mvc.InstallArea,
|
||||
$"{installPath}{{controller}}/{{Action}}",
|
||||
new { controller = "Install", action = "Index" });
|
||||
|
||||
// TODO: Potentially switch this to dynamic routing so we can essentially disable/overwrite the back office routes to redirect to install,
|
||||
// example https://www.strathweb.com/2019/08/dynamic-controller-routing-in-asp-net-core-3-0/
|
||||
@@ -42,8 +50,8 @@ namespace Umbraco.Extensions
|
||||
var uri = context.Request.GetEncodedUrl();
|
||||
// redirect to install
|
||||
ReportRuntime(logger, runtime.Level, "Umbraco must install or upgrade.");
|
||||
var installPath = uriUtility.ToAbsolute(Constants.SystemDirectories.Install);
|
||||
var installUrl = $"{installPath}/?redir=true&url={uri}";
|
||||
|
||||
var installUrl = $"{installPath}?redir=true&url={uri}";
|
||||
context.Response.Redirect(installUrl, true);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace Umbraco.Web.Common.Install
|
||||
[TypeFilter(typeof(HttpResponseExceptionFilter))]
|
||||
[TypeFilter(typeof(AngularJsonOnlyConfigurationAttribute))]
|
||||
[HttpInstallAuthorize]
|
||||
[Area("Install")]
|
||||
[Area(Umbraco.Core.Constants.Web.Mvc.InstallArea)]
|
||||
public class InstallApiController : ControllerBase
|
||||
{
|
||||
private readonly DatabaseBuilder _databaseBuilder;
|
||||
|
||||
@@ -14,12 +14,10 @@ namespace Umbraco.Web.Common.Install
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// The MVC Installation controller
|
||||
/// The Installation controller
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// NOTE: All views must have their full paths as we do not have a custom view engine for the installation views!
|
||||
/// </remarks>
|
||||
[InstallAuthorize]
|
||||
[Area(Umbraco.Core.Constants.Web.Mvc.InstallArea)]
|
||||
public class InstallController : Controller
|
||||
{
|
||||
private readonly IUmbracoContextAccessor _umbracoContextAccessor;
|
||||
@@ -72,7 +70,7 @@ namespace Umbraco.Web.Common.Install
|
||||
}
|
||||
|
||||
// gen the install base urlAddUmbracoCore
|
||||
ViewData.SetInstallApiBaseUrl(Url.GetUmbracoApiService("GetSetup", "InstallApi", "UmbracoInstall").TrimEnd("GetSetup"));
|
||||
ViewData.SetInstallApiBaseUrl(Url.GetUmbracoApiService("GetSetup", "InstallApi", Umbraco.Core.Constants.Web.Mvc.InstallArea).TrimEnd("GetSetup"));
|
||||
|
||||
// get the base umbraco folder
|
||||
ViewData.SetUmbracoBaseFolder(_hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath));
|
||||
@@ -81,7 +79,6 @@ namespace Umbraco.Web.Common.Install
|
||||
|
||||
await _installHelper.InstallStatus(false, "");
|
||||
|
||||
// always ensure full path (see NOTE in the class remarks)
|
||||
return View();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
// For more information on enabling MVC for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860
|
||||
|
||||
namespace Umbraco.Web.UI.BackOffice
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
// GET: /<controller>/
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,6 +13,7 @@
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Views\" />
|
||||
<Folder Include="wwwroot\Media" />
|
||||
<Folder Include="wwwroot\Umbraco\views\install" />
|
||||
</ItemGroup>
|
||||
@@ -40,7 +41,7 @@
|
||||
<Content Remove="wwwroot\Umbraco\views\install\continueinstall.html" />
|
||||
<Content Remove="wwwroot\Umbraco\views\install\database.html" />
|
||||
<Content Remove="wwwroot\Umbraco\views\install\error.html" />
|
||||
<Content Update="Views\Install\Index.cshtml">
|
||||
<Content Update="Areas\UmbracoInstall\Views\Install\Index.cshtml">
|
||||
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
|
||||
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
|
||||
</Content>
|
||||
|
||||
Reference in New Issue
Block a user