Umbraco-CMS
Umbraco-CMS copied to clipboard
delete dialog stays open after cancel delete in contentservice event
I would like to prevent deleting a specific type by all users except for one. So I have implemented logic that catches the contentservice event trashing, trashed, deleting and deleted as shown in https://our.umbraco.com/documentation/Reference/Events/ContentService-Events
All goes well except for the layout, while the dialog for delete stays open, and the message is displayed behind this dialog.
Umbraco version
I am seeing this issue on Umbraco version: 8.9.1
Reproduction
Bug summary
The dialog remains open when cancelling a delete event, so the error message is partly hidden behind it. The user cannot see what happened, and is cluelessly waiting for the spinning button. The cancel is going well, but the dialog remains open.
Specifics
Tested in Chrome (Version 87.0.4280.88 (Official build) (64-bit)) and Edge (Version 87.0.664.66 (Official build) (64-bit)) have not checked other browsers.
Screenshot:

This is a part of my code:
public void Initialize()
{
ContentService.Trashing += ContentService_Trashing;
}
public void Terminate()
{
ContentService.Trashing -= ContentService_Trashing;
}
private void ContentService_Trashing(IContentService sender, MoveEventArgs<IContent> e)
{
IUser currentUser = GetCurrentUser();
foreach (var node in e.MoveInfoCollection)
{
if (node.Entity.ContentType.Alias.ToLower() == "supplier" && currentUser?.Email != "[email protected]")
{
e.CancelOperation(new EventMessage("Warning!", "not allowed to delete", EventMessageType.Error));
}
}
}
Steps to reproduce
Create an item in the documenttree that you are going to delete. Use the code from https://our.umbraco.com/documentation/Reference/Events/ContentService-Events but instead of publishing, using trashing, and cancel the delete and add a message. This can be done like the example (https://our.umbraco.com/documentation/Reference/Events/ContentService-Events) with e.Cancel = true, or with e.CancelOperation(new EventMessage("")). It gives the same result, while I tested both. Delete the item from the documenttree, and see that the errormessage is giving, however the dialog remains open, so the errormessage is partly hidden behind it.
Expected result
I expected that the dialog closed, so the error message was completely visible and the user would be hanging there.
Actual result
The dialog remains open when cancelling a delete event, so the error message is partly hidden behind it. The user cannot see what happened, and is cluelessly waiting for the spinning button.
This item has been added to our backlog AB#21093
Thanks @tanteemmie, we've had a chat about this and agree that this is not great UX right now. What would help for now is to make the notification sit on top instead of hiding behind the actions panel. It's not the best UX still to make it sit on top but at least it's better than what we have today. We'd love some help with that!
Hi @tanteemmie,
We're writing to let you know that we would love some help with this issue. We feel that this issue is ideal to flag for a community member to work on it. Once flagged here, folk looking for issues to work on will know to look at yours. Of course, please feel free work on this yourself ;-). If there are any changes to this status, we'll be sure to let you know.
For more information about issues and states, have a look at this blog post
Thanks muchly, from your friendly Umbraco GitHub bot :-)
Hiya @tanteemmie,
Just wanted to let you know that we noticed that this issue got a bit stale and might not be relevant any more.
We will close this issue for now but we're happy to open it up again if you think it's still relevant (for example: it's a feature request that's not yet implemented, or it's a bug that's not yet been fixed).
To open it this issue up again, you can write @umbrabot still relevant in a new comment as the first line. It would be super helpful for us if on the next line you could let us know why you think it's still relevant.
For example:
@umbrabot still relevant This bug can still be reproduced in version
x.y.z
This will reopen the issue in the next few hours.
Thanks, from your friendly Umbraco GitHub bot :robot: :slightly_smiling_face:
@umbrabot still relevant This bug can still be reproduced in version 8.17.2
Turns out this was already fixed in v8.17.0, just tested it and it definitely works in 8.18.5:
https://user-images.githubusercontent.com/304656/185390823-628d1c4a-43fa-4efc-a6ff-9c532f6076d7.mp4
Example code, can be dropped into App_Code:
using System;
using Umbraco.Core;
using Umbraco.Core.Composing;
using Umbraco.Core.Events;
using Umbraco.Core.Services.Implement;
namespace MyProjectName.Web.Components
{
public class TestTrashingComponent : IComponent
{
public void Initialize()
{
ContentService.Trashing += ContentService_Trashing;
}
private void ContentService_Trashing(Umbraco.Core.Services.IContentService sender,
MoveEventArgs<Umbraco.Core.Models.IContent> e)
{
e.CancelOperation(new EventMessage("Test", "Cancelled", EventMessageType.Error));
}
public void Terminate()
{ }
}
[RuntimeLevel(MinLevel = RuntimeLevel.Run)]
public class TestTrashingComposer : ComponentComposer<TestTrashingComponent>
{ }
}