From d218cb4599b510a5fee83055b9577f02a80c269c Mon Sep 17 00:00:00 2001 From: Shannon Date: Mon, 26 Jul 2021 16:55:41 -0600 Subject: [PATCH] Fixes migration and redirect --- .../V_9_0_0/ExternalLoginTableIndexesFixup.cs | 44 +++++++++++++------ .../Controllers/BackOfficeController.cs | 7 ++- 2 files changed, 36 insertions(+), 15 deletions(-) diff --git a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs index 0046d612d5..5efb914eb7 100644 --- a/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs +++ b/src/Umbraco.Infrastructure/Migrations/Upgrade/V_9_0_0/ExternalLoginTableIndexesFixup.cs @@ -1,4 +1,4 @@ -using Umbraco.Cms.Infrastructure.Persistence.Dtos; +using Umbraco.Cms.Infrastructure.Persistence.Dtos; namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0 { @@ -15,27 +15,45 @@ namespace Umbraco.Cms.Infrastructure.Migrations.Upgrade.V_9_0_0 protected override void Migrate() { var indexName1 = "IX_" + ExternalLoginDto.TableName + "_LoginProvider"; + var indexName2 = "IX_" + ExternalLoginDto.TableName + "_ProviderKey"; if (IndexExists(indexName1)) { - // drop it since the previous migration index was wrong + // drop it since the previous migration index was wrong, and we + // need to modify a column that belons to it Delete.Index(indexName1).OnTable(ExternalLoginDto.TableName).Do(); + } - // create it with the correct definition - Create - .Index(indexName1) - .OnTable(ExternalLoginDto.TableName) - .OnColumn("loginProvider").Ascending() - .OnColumn("userId").Ascending() - .WithOptions() - .Unique() - .WithOptions() - .NonClustered() - .Do(); + if (IndexExists(indexName2)) + { + // drop since it's using a column we're about to modify + Delete.Index(indexName2).OnTable(ExternalLoginDto.TableName).Do(); } // then fixup the length of the loginProvider column AlterColumn(ExternalLoginDto.TableName, "loginProvider"); + + // create it with the correct definition + Create + .Index(indexName1) + .OnTable(ExternalLoginDto.TableName) + .OnColumn("loginProvider").Ascending() + .OnColumn("userId").Ascending() + .WithOptions() + .Unique() + .WithOptions() + .NonClustered() + .Do(); + + // re-create the original + Create + .Index(indexName2) + .OnTable(ExternalLoginDto.TableName) + .OnColumn("loginProvider").Ascending() + .OnColumn("providerKey").Ascending() + .WithOptions() + .NonClustered() + .Do(); } } } diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs index 34d86893fb..92e34992a5 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeController.cs @@ -113,6 +113,9 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers [AllowAnonymous] public async Task 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? + // force authentication to occur since this is not an authorized endpoint var result = await this.AuthenticateBackOfficeAsync(); @@ -455,8 +458,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers // Check if we are in an upgrade state, if so we need to redirect if (_runtimeState.Level == Core.RuntimeLevel.Upgrade) { - // redirect to the authorize upgrade endpoint which redirect to the installer - return RedirectToAction(nameof(AuthorizeUpgrade)); + // redirect to the the installer + return Redirect("/"); } } else if (result == SignInResult.TwoFactorRequired)