diff --git a/src/Umbraco.Web.BackOffice/ActionResults/UmbracoNotificationSuccessResponse.cs b/src/Umbraco.Web.BackOffice/ActionResults/UmbracoNotificationSuccessResponse.cs
deleted file mode 100644
index 37e4902626..0000000000
--- a/src/Umbraco.Web.BackOffice/ActionResults/UmbracoNotificationSuccessResponse.cs
+++ /dev/null
@@ -1,20 +0,0 @@
-using Microsoft.AspNetCore.Mvc;
-using Umbraco.Cms.Core.Models.ContentEditing;
-using Umbraco.Extensions;
-
-namespace Umbraco.Cms.Web.BackOffice.ActionResults
-{
- public class UmbracoNotificationSuccessResponse : OkObjectResult
- {
- public UmbracoNotificationSuccessResponse(string successMessage) : base(null)
- {
- var notificationModel = new SimpleNotificationModel
- {
- Message = successMessage
- };
- notificationModel.AddSuccessNotification(successMessage, string.Empty);
-
- Value = notificationModel;
- }
- }
-}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeNotificationsController.cs b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeNotificationsController.cs
index a9dc8461da..27be8ec263 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/BackOfficeNotificationsController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/BackOfficeNotificationsController.cs
@@ -1,5 +1,7 @@
using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Mvc.Infrastructure;
using Umbraco.Cms.Core.Models.ContentEditing;
+using Umbraco.Cms.Web.BackOffice.ActionResults;
using Umbraco.Cms.Web.BackOffice.Filters;
using Umbraco.Cms.Web.Common.ActionsResults;
using Umbraco.Extensions;
@@ -15,18 +17,43 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[AppendCurrentEventMessages]
public abstract class BackOfficeNotificationsController : UmbracoAuthorizedJsonController
{
+ ///
+ /// returns a 200 OK response with a notification message
+ ///
+ ///
+ ///
+ protected OkObjectResult Ok(string message)
+ {
+ var notificationModel = new SimpleNotificationModel
+ {
+ Message = message
+ };
+ notificationModel.AddSuccessNotification(message, string.Empty);
+
+ return new OkObjectResult(notificationModel);
+ }
+
///
/// Overridden to ensure that the error message is an error notification message
///
///
///
protected override ActionResult ValidationProblem(string errorMessage)
+ => ValidationProblem(errorMessage, string.Empty);
+
+ ///
+ /// Creates a notofication validation problem with a header and message
+ ///
+ ///
+ ///
+ ///
+ protected ActionResult ValidationProblem(string errorHeader, string errorMessage)
{
var notificationModel = new SimpleNotificationModel
{
Message = errorMessage
};
- notificationModel.AddErrorNotification(errorMessage, string.Empty);
+ notificationModel.AddErrorNotification(errorHeader, errorMessage);
return new ValidationErrorResult(notificationModel);
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
index c9a608204c..4f13b2146b 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
@@ -1550,7 +1550,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
{
_contentService.EmptyRecycleBin(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(Constants.Security.SuperUserId));
- return new UmbracoNotificationSuccessResponse(_localizedTextService.Localize("defaultdialogs/recycleBinIsEmpty"));
+ return Ok(_localizedTextService.Localize("defaultdialogs/recycleBinIsEmpty"));
}
///
@@ -2362,8 +2362,6 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
if (rollbackResult.Success)
return Ok();
- var notificationModel = new SimpleNotificationModel();
-
switch (rollbackResult.Result)
{
case OperationResultType.Failed:
@@ -2371,22 +2369,12 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
case OperationResultType.FailedExceptionThrown:
case OperationResultType.NoOperation:
default:
- notificationModel.AddErrorNotification(
- _localizedTextService.Localize("speechBubbles/operationFailedHeader"),
- null); // TODO: There is no specific failed to save error message AFAIK
- break;
+ return ValidationProblem(_localizedTextService.Localize("speechBubbles/operationFailedHeader"));
case OperationResultType.FailedCancelledByEvent:
- notificationModel.AddErrorNotification(
- _localizedTextService.Localize("speechBubbles/operationCancelledHeader"),
- _localizedTextService.Localize("speechBubbles/operationCancelledText"));
- break;
+ return ValidationProblem(
+ _localizedTextService.Localize("speechBubbles/operationCancelledHeader"),
+ _localizedTextService.Localize("speechBubbles/operationCancelledText"));
}
-
- return ValidationProblem(notificationModel);
}
-
-
-
-
}
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeControllerBase.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeControllerBase.cs
index d0f22b7f5e..ab7788e139 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeControllerBase.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeControllerBase.cs
@@ -25,7 +25,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
///
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
[PrefixlessBodyModelValidator]
- public abstract class ContentTypeControllerBase : UmbracoAuthorizedJsonController
+ public abstract class ContentTypeControllerBase : BackOfficeNotificationsController
where TContentType : class, IContentTypeComposition
{
private readonly EditorValidatorCollection _editorValidatorCollection;
@@ -417,9 +417,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
case MoveOperationStatusType.FailedCancelledByEvent:
return ValidationProblem();
case MoveOperationStatusType.FailedNotAllowedByPath:
- var notificationModel = new SimpleNotificationModel();
- notificationModel.AddErrorNotification(LocalizedTextService.Localize("moveOrCopy/notAllowedByPath"), "");
- return ValidationProblem(notificationModel);
+ return ValidationProblem(LocalizedTextService.Localize("moveOrCopy/notAllowedByPath"));
default:
throw new ArgumentOutOfRangeException();
}
@@ -455,10 +453,8 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
return NotFound();
case MoveOperationStatusType.FailedCancelledByEvent:
return ValidationProblem();
- case MoveOperationStatusType.FailedNotAllowedByPath:
- var notificationModel = new SimpleNotificationModel();
- notificationModel.AddErrorNotification(LocalizedTextService.Localize("moveOrCopy/notAllowedByPath"), "");
- return ValidationProblem(notificationModel);
+ case MoveOperationStatusType.FailedNotAllowedByPath:
+ return ValidationProblem(LocalizedTextService.Localize("moveOrCopy/notAllowedByPath"));
default:
throw new ArgumentOutOfRangeException();
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
index 4e160f0fed..a2f1fe36c3 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/MediaController.cs
@@ -616,7 +616,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
{
_mediaService.EmptyRecycleBin(_backofficeSecurityAccessor.BackOfficeSecurity.GetUserId().ResultOr(Constants.Security.SuperUserId));
- return new UmbracoNotificationSuccessResponse(_localizedTextService.Localize("defaultdialogs/recycleBinIsEmpty"));
+ return Ok(_localizedTextService.Localize("defaultdialogs/recycleBinIsEmpty"));
}
///
diff --git a/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs b/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs
index f5cdb94d37..971d7400de 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/UserGroupsController.cs
@@ -10,7 +10,6 @@ using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Strings;
-using Umbraco.Cms.Web.BackOffice.ActionResults;
using Umbraco.Cms.Web.BackOffice.Filters;
using Umbraco.Cms.Web.Common.Attributes;
using Umbraco.Cms.Web.Common.Authorization;
@@ -22,7 +21,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
[PluginController(Constants.Web.Mvc.BackOfficeApiArea)]
[Authorize(Policy = AuthorizationPolicies.SectionAccessUsers)]
[PrefixlessBodyModelValidator]
- public class UserGroupsController : UmbracoAuthorizedJsonController
+ public class UserGroupsController : BackOfficeNotificationsController
{
private readonly IUserService _userService;
private readonly IContentService _contentService;
@@ -202,10 +201,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
_userService.DeleteUserGroup(userGroup);
}
if (userGroups.Length > 1)
- return new UmbracoNotificationSuccessResponse(
- _localizedTextService.Localize("speechBubbles/deleteUserGroupsSuccess", new[] {userGroups.Length.ToString()}));
- return new UmbracoNotificationSuccessResponse(
- _localizedTextService.Localize("speechBubbles/deleteUserGroupSuccess", new[] {userGroups[0].Name}));
+ {
+ return Ok(_localizedTextService.Localize("speechBubbles/deleteUserGroupsSuccess", new[] {userGroups.Length.ToString()}));
+ }
+
+ return Ok(_localizedTextService.Localize("speechBubbles/deleteUserGroupSuccess", new[] {userGroups[0].Name}));
}
}
}
diff --git a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs
index 669ff6158f..ff2e087aa4 100644
--- a/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs
+++ b/src/Umbraco.Web.BackOffice/Controllers/UsersController.cs
@@ -733,12 +733,10 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
if (users.Length > 1)
{
- return new UmbracoNotificationSuccessResponse(
- _localizedTextService.Localize("speechBubbles/disableUsersSuccess", new[] {userIds.Length.ToString()}));
+ return Ok(_localizedTextService.Localize("speechBubbles/disableUsersSuccess", new[] {userIds.Length.ToString()}));
}
- return new UmbracoNotificationSuccessResponse(
- _localizedTextService.Localize("speechBubbles/disableUserSuccess", new[] { users[0].Name }));
+ return Ok(_localizedTextService.Localize("speechBubbles/disableUserSuccess", new[] { users[0].Name }));
}
///
@@ -757,11 +755,11 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
if (users.Length > 1)
{
- return new UmbracoNotificationSuccessResponse(
+ return Ok(
_localizedTextService.Localize("speechBubbles/enableUsersSuccess", new[] { userIds.Length.ToString() }));
}
- return new UmbracoNotificationSuccessResponse(
+ return Ok(
_localizedTextService.Localize("speechBubbles/enableUserSuccess", new[] { users[0].Name }));
}
@@ -793,12 +791,12 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
if (userIds.Length == 1)
{
- return new UmbracoNotificationSuccessResponse(
+ return Ok(
_localizedTextService.Localize("speechBubbles/unlockUserSuccess", new[] {user.Name}));
}
}
- return new UmbracoNotificationSuccessResponse(
+ return Ok(
_localizedTextService.Localize("speechBubbles/unlockUsersSuccess", new[] {(userIds.Length - notFound.Count).ToString()}));
}
@@ -816,7 +814,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
}
}
_userService.Save(users);
- return new UmbracoNotificationSuccessResponse(
+ return Ok(
_localizedTextService.Localize("speechBubbles/setUserGroupOnUsersSuccess"));
}
@@ -847,7 +845,7 @@ namespace Umbraco.Cms.Web.BackOffice.Controllers
var userName = user.Name;
_userService.Delete(user, true);
- return new UmbracoNotificationSuccessResponse(
+ return Ok(
_localizedTextService.Localize("speechBubbles/deleteUserSuccess", new[] { userName }));
}