Merge pull request #11064 from umbraco/v9/bugfix/10650-fix_issue_with_upgrading_while_in_backoffice

Add redirect to /umbraco if you are not in run state.
This commit is contained in:
Nikolaj Geisle
2021-09-10 10:50:41 +02:00
committed by GitHub
2 changed files with 11 additions and 3 deletions

View File

@@ -11,8 +11,10 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures;
using Microsoft.Extensions.Options;
using Moq;
using NUnit.Framework;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Configuration.Models;
using Umbraco.Cms.Core.Hosting;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Tests.UnitTests.AutoFixture;
using Umbraco.Cms.Web.BackOffice.Controllers;
using Umbraco.Cms.Web.BackOffice.Install;
@@ -76,11 +78,13 @@ namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common
[Frozen] IOptions<GlobalSettings> globalSettings,
[Frozen] IHostingEnvironment hostingEnvironment,
[Frozen] ITempDataDictionary tempDataDictionary,
[Frozen] IRuntimeState runtimeState,
BackOfficeController sut)
{
globalSettings.Value.UmbracoPath = "/";
Mock.Get(hostingEnvironment).Setup(x => x.ToAbsolute("/")).Returns("http://localhost/");
Mock.Get(hostingEnvironment).SetupGet(x => x.ApplicationVirtualPath).Returns("/");
Mock.Get(runtimeState).Setup(x => x.Level).Returns(RuntimeLevel.Run);
sut.TempData = tempDataDictionary;

View File

@@ -12,6 +12,7 @@ using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Cache;
using Umbraco.Cms.Core.Configuration.Grid;
using Umbraco.Cms.Core.Configuration.Models;
@@ -112,11 +113,14 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[AllowAnonymous]
public async Task<IActionResult> Default()
{
// TODO: It seems that if you login during an authorize upgrade and the upgrade fails, you can still
// access the back office. This should redirect to the installer in that case?
// Check if we not are in an run state, if so we need to redirect
if (_runtimeState.Level != RuntimeLevel.Run)
{
return Redirect("/");
}
// force authentication to occur since this is not an authorized endpoint
var result = await this.AuthenticateBackOfficeAsync();
AuthenticateResult result = await this.AuthenticateBackOfficeAsync();
var viewPath = Path.Combine(Constants.SystemDirectories.Umbraco, Constants.Web.Mvc.BackOfficeArea, nameof(Default) + ".cshtml")
.Replace("\\", "/"); // convert to forward slashes since it's a virtual path