Skip to content

Commit

Permalink
No longer shows success message if content moving is cancelled (#15051)
Browse files Browse the repository at this point in the history
* Fix for issue #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 <[email protected]>
  • Loading branch information
miguelcrpinto and lauraneto authored Sep 5, 2024
1 parent bff2932 commit 3e6116f
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 8 deletions.
20 changes: 13 additions & 7 deletions src/Umbraco.Core/Services/ContentService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2448,22 +2448,26 @@ public OperationResult MoveToRecycleBin(IContent content, int userId = Constants
/// <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())
Expand All @@ -2482,7 +2486,7 @@ public void Move(IContent content, int parentId, int userId = Constants.Security
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,
Expand Down Expand Up @@ -2517,6 +2521,8 @@ public void Move(IContent content, int parentId, int userId = Constants.Security

scope.Complete();
}

return OperationResult.Succeed(eventMessages);
}

// MUST be called from within WriteLock
Expand Down
16 changes: 16 additions & 0 deletions src/Umbraco.Core/Services/IContentService.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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>
Expand Down
7 changes: 6 additions & 1 deletion src/Umbraco.Web.BackOffice/Controllers/ContentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,12 @@ public async Task<IActionResult> PostSort(ContentSortOrder sorted)
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);
}
Expand Down

0 comments on commit 3e6116f

Please sign in to comment.