No longer shows success message if content moving is cancelled (#15051)

* Fix for issue https://github.com/umbraco/Umbraco-CMS/issues/13923
 - Added AttemptMove method to the ContentService
 - Updated ContentController PostMove method to return ValidationProblem whenever the node is not moved

* Align changes with V14 solution. Make it non breaking.

---------

Co-authored-by: Laura Neto <12862535+lauraneto@users.noreply.github.com>
This commit is contained in:
Miguel Pinto
2024-09-05 14:08:48 +02:00
committed by GitHub
parent bff293213d
commit 3e6116fcba
3 changed files with 35 additions and 8 deletions

View File

@@ -2448,22 +2448,26 @@ public class ContentService : RepositoryService, IContentService
/// <param name="content">The <see cref="IContent" /> to move</param>
/// <param name="parentId">Id of the Content's new Parent</param>
/// <param name="userId">Optional Id of the User moving the Content</param>
public void Move(IContent content, int parentId, int userId = Constants.Security.SuperUserId)
public void Move(IContent content, int parentId, int userId = Constants.Security.SuperUserId) =>
AttemptMove(content, parentId, userId);
/// <inheritdoc/>
[Obsolete("Adds return type to Move method. Will be removed in V14, as the original method will be adjusted.")]
public OperationResult AttemptMove(IContent content, int parentId, int userId = Constants.Security.SuperUserId)
{
EventMessages eventMessages = EventMessagesFactory.Get();
if (content.ParentId == parentId)
{
return;
return OperationResult.Succeed(eventMessages);
}
// if moving to the recycle bin then use the proper method
if (parentId == Constants.System.RecycleBinContent)
{
MoveToRecycleBin(content, userId);
return;
return MoveToRecycleBin(content, userId);
}
EventMessages eventMessages = EventMessagesFactory.Get();
var moves = new List<(IContent, string)>();
using (ICoreScope scope = ScopeProvider.CreateCoreScope())
@@ -2482,7 +2486,7 @@ public class ContentService : RepositoryService, IContentService
if (scope.Notifications.PublishCancelable(movingNotification))
{
scope.Complete();
return; // causes rollback
return OperationResult.Cancel(eventMessages);// causes rollback
}
// if content was trashed, and since we're not moving to the recycle bin,
@@ -2517,6 +2521,8 @@ public class ContentService : RepositoryService, IContentService
scope.Complete();
}
return OperationResult.Succeed(eventMessages);
}
// MUST be called from within WriteLock

View File

@@ -1,3 +1,4 @@
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Models.Membership;
using Umbraco.Cms.Core.Persistence.Querying;
@@ -315,6 +316,21 @@ public interface IContentService : IContentServiceBase<IContent>
/// </summary>
void Move(IContent content, int parentId, int userId = Constants.Security.SuperUserId);
/// <summary>
/// Attempts to move the <see cref="IContent"/> <paramref name="content"/> to under the node with id <paramref name="parentId"/>.
/// </summary>
/// <param name="content">The <see cref="IContent"/> that shall be moved.</param>
/// <param name="parentId">The id of the new parent node.</param>
/// <param name="userId">Id of the user attempting to move <paramref name="content"/>.</param>
/// <returns>Success if moving succeeded, otherwise Failed.</returns>
[Obsolete("Adds return type to Move method. Will be removed in V14, as the original method will be adjusted.")]
OperationResult
AttemptMove(IContent content, int parentId, int userId = Constants.Security.SuperUserId)
{
Move(content, parentId, userId);
return OperationResult.Succeed(new EventMessages());
}
/// <summary>
/// Copies a document.
/// </summary>

View File

@@ -2254,7 +2254,12 @@ public class ContentController : ContentControllerBase
return null;
}
_contentService.Move(toMove, move.ParentId, _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? -1);
OperationResult moveResult = _contentService.AttemptMove(toMove, move.ParentId, _backofficeSecurityAccessor.BackOfficeSecurity?.GetUserId().Result ?? -1);
if (!moveResult.Success)
{
return ValidationProblem();
}
return Content(toMove.Path, MediaTypeNames.Text.Plain, Encoding.UTF8);
}