From d47638df984550c4d3a69b4bbc323f3eb3e229b4 Mon Sep 17 00:00:00 2001 From: Kenn Jacobsen Date: Thu, 11 Apr 2024 09:08:56 +0200 Subject: [PATCH] Remove remnants of the Angular implementation (#16026) --- .../ConfigureBackOfficeCookieOptions.cs | 2 +- src/Umbraco.Core/Constants-Web.cs | 10 ---- .../PropertyEditors/DataValueEditor.cs | 2 +- .../IPublishedSnapshotStatus.cs | 5 -- .../PostMigrations/ClearCsrfCookieHandler.cs | 1 - .../PublishedSnapshotStatus.cs | 3 -- .../ActionsResults/UmbracoProblemResult.cs | 11 ---- .../ActionsResults/ValidationErrorResult.cs | 53 ------------------- .../Controllers/UmbExternalLoginController.cs | 3 +- .../Controllers/UmbLoginController.cs | 5 +- 10 files changed, 4 insertions(+), 91 deletions(-) delete mode 100644 src/Umbraco.Web.Common/ActionsResults/UmbracoProblemResult.cs delete mode 100644 src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs diff --git a/src/Umbraco.Cms.Api.Management/Configuration/ConfigureBackOfficeCookieOptions.cs b/src/Umbraco.Cms.Api.Management/Configuration/ConfigureBackOfficeCookieOptions.cs index f5af3a62b795..88a39d046a0c 100644 --- a/src/Umbraco.Cms.Api.Management/Configuration/ConfigureBackOfficeCookieOptions.cs +++ b/src/Umbraco.Cms.Api.Management/Configuration/ConfigureBackOfficeCookieOptions.cs @@ -211,7 +211,7 @@ public void Configure(CookieAuthenticationOptions options) { _securitySettings.AuthCookieName, Constants.Web.PreviewCookieName, Constants.Security.BackOfficeExternalCookieName, - Constants.Web.AngularCookieName, Constants.Web.CsrfValidationCookieName + Constants.Web.CsrfValidationCookieName }; foreach (var cookie in cookies) { diff --git a/src/Umbraco.Core/Constants-Web.cs b/src/Umbraco.Core/Constants-Web.cs index 36749cbb2b78..acd1bb50efc3 100644 --- a/src/Umbraco.Core/Constants-Web.cs +++ b/src/Umbraco.Core/Constants-Web.cs @@ -24,16 +24,6 @@ public static class Web /// public const string CsrfValidationCookieName = "UMB-XSRF-V"; - /// - /// The cookie name that is set for angular to use to pass in to the header value for "X-UMB-XSRF-TOKEN" - /// - public const string AngularCookieName = "UMB-XSRF-TOKEN"; - - /// - /// The header name that angular uses to pass in the token to validate the cookie - /// - public const string AngularHeadername = "X-UMB-XSRF-TOKEN"; - /// /// The route name of the page shown when Umbraco has no published content. /// diff --git a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs index a32af502ab79..5faa60507ac0 100644 --- a/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs +++ b/src/Umbraco.Core/PropertyEditors/DataValueEditor.cs @@ -211,7 +211,7 @@ public IEnumerable Validate(object? value, bool required, stri case ValueStorageType.Ntext: case ValueStorageType.Nvarchar: // If it is a string type, we will attempt to see if it is JSON stored data, if it is we'll try to convert - // to a real JSON object so we can pass the true JSON object directly to Angular! + // to a real JSON object so we can pass the true JSON object directly to the client var stringValue = value as string ?? value.ToString(); if (stringValue!.DetectIsJson()) { diff --git a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotStatus.cs b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotStatus.cs index 1eb09c8144f4..1ae08cc42d4a 100644 --- a/src/Umbraco.Core/PublishedCache/IPublishedSnapshotStatus.cs +++ b/src/Umbraco.Core/PublishedCache/IPublishedSnapshotStatus.cs @@ -5,11 +5,6 @@ namespace Umbraco.Cms.Core.PublishedCache; /// public interface IPublishedSnapshotStatus { - /// - /// Gets the URL used to retreive the status - /// - string StatusUrl { get; } - /// /// Gets the status report as a string /// diff --git a/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookieHandler.cs b/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookieHandler.cs index fc796d66b807..85bee9136499 100644 --- a/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookieHandler.cs +++ b/src/Umbraco.Infrastructure/Migrations/PostMigrations/ClearCsrfCookieHandler.cs @@ -22,7 +22,6 @@ public void Handle(UmbracoPlanExecutedNotification notification) return; } - _cookieManager.ExpireCookie(Constants.Web.AngularCookieName); _cookieManager.ExpireCookie(Constants.Web.CsrfValidationCookieName); } } diff --git a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs index c706e35ca6f4..ea24c5bc1c67 100644 --- a/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs +++ b/src/Umbraco.PublishedCache.NuCache/PublishedSnapshotStatus.cs @@ -17,9 +17,6 @@ public PublishedSnapshotStatus(IPublishedSnapshotService? service, INuCacheConte _publishedContentService = publishedContentService; } - /// - public virtual string StatusUrl => "views/dashboard/settings/publishedsnapshotcache.html"; - /// public string GetStatus() { diff --git a/src/Umbraco.Web.Common/ActionsResults/UmbracoProblemResult.cs b/src/Umbraco.Web.Common/ActionsResults/UmbracoProblemResult.cs deleted file mode 100644 index 8aa5188c3fc4..000000000000 --- a/src/Umbraco.Web.Common/ActionsResults/UmbracoProblemResult.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Net; -using Microsoft.AspNetCore.Mvc; - -namespace Umbraco.Cms.Web.Common.ActionsResults; - -// TODO: What is the purpose of this? Doesn't seem to add any benefit -public class UmbracoProblemResult : ObjectResult -{ - public UmbracoProblemResult(string message, HttpStatusCode httpStatusCode = HttpStatusCode.InternalServerError) - : base(new { Message = message }) => StatusCode = (int)httpStatusCode; -} diff --git a/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs b/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs deleted file mode 100644 index 00eda14ab10b..000000000000 --- a/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs +++ /dev/null @@ -1,53 +0,0 @@ -using Microsoft.AspNetCore.Http; -using Microsoft.AspNetCore.Mvc; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Web.Common.ActionsResults; - -// TODO: This should probably follow the same conventions as in aspnet core and use ProblemDetails -// and ProblemDetails factory. See https://github.com/dotnet/aspnetcore/blob/main/src/Mvc/Mvc.Core/src/ControllerBase.cs#L1977 -// ProblemDetails is explicitly checked for in the application model. -// In our base class UmbracoAuthorizedApiController the logic is there to create a ProblemDetails. -// However, to do this will require changing how angular deals with errors since the response will -// probably be different. Would just be better to follow the aspnet patterns. - -/// -/// Custom result to return a validation error message with required headers -/// -/// -/// The default status code is a 400 http response -/// -public class ValidationErrorResult : ObjectResult -{ - public ValidationErrorResult(ModelStateDictionary modelState) - : this(new SimpleValidationModel(modelState.ToErrorDictionary())) - { - } - - public ValidationErrorResult(object? value, int statusCode) - : base(value) => StatusCode = statusCode; - - public ValidationErrorResult(object? value) - : this(value, StatusCodes.Status400BadRequest) - { - } - - // TODO: Like here, shouldn't we use ProblemDetails? - public ValidationErrorResult(string errorMessage, int statusCode) - : base(new { Message = errorMessage }) => - StatusCode = statusCode; - - public ValidationErrorResult(string errorMessage) - : this(errorMessage, StatusCodes.Status400BadRequest) - { - } - - public override void OnFormatting(ActionContext context) - { - base.OnFormatting(context); - context.HttpContext.Response.Headers["X-Status-Reason"] = "Validation failed"; - } -} diff --git a/src/Umbraco.Web.Website/Controllers/UmbExternalLoginController.cs b/src/Umbraco.Web.Website/Controllers/UmbExternalLoginController.cs index 432761a1971d..27d39324f180 100644 --- a/src/Umbraco.Web.Website/Controllers/UmbExternalLoginController.cs +++ b/src/Umbraco.Web.Website/Controllers/UmbExternalLoginController.cs @@ -115,8 +115,7 @@ public async Task ExternalLoginCallback(string returnUrl) await _memberManager.FindByLoginAsync(loginInfo.LoginProvider, loginInfo.ProviderKey); if (attemptedUser == null!) { - return new ValidationErrorResult( - $"No local user found for the login provider {loginInfo.LoginProvider} - {loginInfo.ProviderKey}"); + return BadRequest($"No local user found for the login provider {loginInfo.LoginProvider} - {loginInfo.ProviderKey}"); } IEnumerable providerNames = diff --git a/src/Umbraco.Web.Website/Controllers/UmbLoginController.cs b/src/Umbraco.Web.Website/Controllers/UmbLoginController.cs index 2ed0babf3d4d..f102cca4099d 100644 --- a/src/Umbraco.Web.Website/Controllers/UmbLoginController.cs +++ b/src/Umbraco.Web.Website/Controllers/UmbLoginController.cs @@ -1,14 +1,12 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Routing; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Web; using Umbraco.Cms.Infrastructure.Persistence; -using Umbraco.Cms.Web.Common.ActionsResults; using Umbraco.Cms.Web.Common.Filters; using Umbraco.Cms.Web.Common.Models; using Umbraco.Cms.Web.Common.Security; @@ -84,8 +82,7 @@ public async Task HandleLogin([Bind(Prefix = "loginModel")] Login MemberIdentityUser? attemptedUser = await _memberManager.FindByNameAsync(model.Username); if (attemptedUser == null!) { - return new ValidationErrorResult( - $"No local member found for username {model.Username}"); + return BadRequest($"No local member found for username {model.Username}"); } IEnumerable providerNames =