Umbraco-CMS icon indicating copy to clipboard operation
Umbraco-CMS copied to clipboard

Backoffice UI errors when cancelling creating/saving/deleting notifications

Open ronaldbarendse opened this issue 2 years ago • 1 comments

Which exact Umbraco version are you using? For example: 9.0.1 - don't just write v9

10.0.0

Bug summary

The backoffice UI contains UI errors when the creating, saving or deleting notifications are cancelled for:

  • Document types
    • Showing both success and error message when saving: Document types saving
    • No message when deleting, item removed from tree, but refreshing the tree shows it again
  • Media types (showing both success and error)
    • Showing both success and error message when saving: Media types saving
    • No message when deleting, item removed from tree, but refreshing the tree shows it again
  • Member types
    • Showing both success and error message when saving: Member types saving
    • No message when deleting, item removed from tree, but refreshing the tree shows it again
  • Data types
    • Showing both success and error message when saving: Data types saving
    • No message when deleting, item removed from tree, but refreshing the tree shows it again
  • Templates
    • Showing only success message when saving (even though it's not saving changes): Templates saving
    • No message when deleting, item removed from tree, but refreshing the tree shows it again
  • Partial views
    • Showing both success and error messages (including additional ones for trying to create the physical file and fetching the file contents) when creating: Partial views creating
    • Showing both success and error messages (including an additional one for trying to save the physical file) when saving: Partial views saving
    • 404 error when deleting. broken dialog: Partial views dialog deleting Partial views deleting

Specifics

No response

Steps to reproduce

These errors can be easily reproduced by adding the following code into your Umbraco project that cancels all above mentioned notifications:

using Umbraco.Cms.Core.Composing;
using Umbraco.Cms.Core.Events;
using Umbraco.Cms.Core.Notifications;

public class ApplicationComposer : IComposer
{
    public void Compose(IUmbracoBuilder builder)
    {
        builder.AddNotificationHandler<ContentTypeSavingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<ContentTypeDeletingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<MediaTypeSavingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<MediaTypeDeletingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<MemberTypeSavingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<MemberTypeDeletingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<DataTypeSavingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<DataTypeDeletingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<TemplateSavingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<TemplateDeletingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<PartialViewCreatingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<PartialViewSavingNotification, ApplicationNotificationHandler>();
        builder.AddNotificationHandler<PartialViewDeletingNotification, ApplicationNotificationHandler>();
    }

    private class ApplicationNotificationHandler :
        INotificationHandler<ContentTypeSavingNotification>,
        INotificationHandler<ContentTypeDeletingNotification>,
        INotificationHandler<MediaTypeSavingNotification>,
        INotificationHandler<MediaTypeDeletingNotification>,
        INotificationHandler<MemberTypeSavingNotification>,
        INotificationHandler<MemberTypeDeletingNotification>,
        INotificationHandler<DataTypeSavingNotification>,
        INotificationHandler<DataTypeDeletingNotification>,
        INotificationHandler<TemplateSavingNotification>,
        INotificationHandler<TemplateDeletingNotification>,
        INotificationHandler<PartialViewCreatingNotification>,
        INotificationHandler<PartialViewSavingNotification>,
        INotificationHandler<PartialViewDeletingNotification>
    {
        private readonly EventMessage _cancelEventMessage = new EventMessage(
            "This operation has been cancelled",
            "You should only see this error message.",
            EventMessageType.Error);

        public void Handle(ContentTypeSavingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(ContentTypeDeletingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(MediaTypeSavingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(MediaTypeDeletingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(MemberTypeSavingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(MemberTypeDeletingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(DataTypeSavingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(DataTypeDeletingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(TemplateSavingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(TemplateDeletingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(PartialViewCreatingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(PartialViewSavingNotification notification) => notification.CancelOperation(_cancelEventMessage);
        public void Handle(PartialViewDeletingNotification notification) => notification.CancelOperation(_cancelEventMessage);
    }
}

Expected result / actual result

I would expect to only see the single error message from the notification handler when trying to create, save or delete the different items and in addition to that:

  • Show a cross in the save button, instead of a checkmark (indicating the operation did not succeed);
  • Keep the item in the tree;
  • Close the delete dialog.

ronaldbarendse avatar Jun 29 '22 08:06 ronaldbarendse

I'm seeing a similar issue in 10.0.1 when trying to cancel a Notification. I have code similar to this:

public class OnContentUnpublishing : INotificationHandler<ContentUnpublishingNotification>
    {
        public void Handle(ContentUnpublishingNotification notification)
        {
            foreach (var node in notification.UnpublishedEntities)
            {
                if (NotificationSettings.ShouldNotBeDeleted(node))
                {
                    notification.CancelOperation(new EventMessage("Warning!", $"The page '{node.Name}' ({node.Id}) has been set so it cannot be unpublished.", EventMessageType.Error));
                    notification.Cancel = true;
                }
            }
        }
    }

When I try and unpublish a page where the Notification is set to be cancelled then it runs, but only after the normal "this page has been published" has already run. So it displays the "success" notification, then it shows my "cancel" notification - and the page isn't prevented from being unpublished.

image

I expect and want the publication to be stopped and it only show my error message.

DanDiplo avatar Jul 29 '22 19:07 DanDiplo

I can indeed reproduce this, and agree, no success message should be shown if cancelled 🤔 Marking this up for grabs as we'd love some help with this! 💪

Zeegaan avatar Dec 28 '22 09:12 Zeegaan

Hi @Zeegaan I found this issue as well and was going to take a look. The problem stems from ContentTypeController.cs:469 whereby a success notification is always added to the response.

At this stage there is no way to know if a notification handler has caused a "cancel" since the underlying save event returns void. The easiest way to resolve this would be to check if a message has been added of type Error display.Notifications.Any(x => x.NotificationType == NotificationStyle.Error) and then not adding the success notification in that case.

Or perhaps checking if the number of user defined messages is more than 1?

Either way, this will result in a change of behaviour which is going to have to be decided by someone, and with the work that is being done for v13/14 making large changes to do it "properly" is likely not worthwhile.

Thanks, Matthew

matthewcare avatar Sep 05 '23 17:09 matthewcare

and with the work that is being done for v13/14 making large changes to do it "properly" is likely not worthwhile.

Where can i find more information about what's happening with this in v13/14?

jdpnielsen avatar Sep 06 '23 07:09 jdpnielsen

@jdpnielsen There are a few places where discussion is taking place, but for the most part following along with the roadmap will keep you mostly up to date. https://umbraco.com/products/knowledge-center/roadmap/ For specifics about the new backoffice though, there is this blog post https://umbraco.com/blog/bellissima-preview-releases-of-the-new-backoffice/

matthewcare avatar Sep 06 '23 09:09 matthewcare

@jdpnielsen Ah, just in general regarding Bellissima. Thought there were ongoing discussions regarding publishing/notifications specifically.

jdpnielsen avatar Sep 06 '23 12:09 jdpnielsen

Hi @Zeegaan

I see a few other issues being opened with this same problem. Did you have any suggestions from my findings?

Thanks, Matthew

matthewcare avatar Oct 15 '23 20:10 matthewcare

@matthewcare As it is potato holiday this week 🥔 I will bring this up with the team on Monday and discuss how to go about it 😁

Zeegaan avatar Oct 16 '23 07:10 Zeegaan

@Zeegaan Have all of the potatoes been eaten?

matthewcare avatar Nov 06 '23 09:11 matthewcare

@matthewcare It will be looked at for v14 behavior👍 I think your suggestion could be done for V13, so if you're up for making a PR for v13 that would be great 😁

And sorry for the late response!

Zeegaan avatar Nov 06 '23 09:11 Zeegaan

There's a bunch of other places this occurs as well. For example, if you cancel a member save, you get a success and a cancel message. If you you cancel a member delete, you just get a success message, the custom message you set never gets shown to the user.

Attackmonkey avatar Nov 07 '23 14:11 Attackmonkey

For v14 it might be nice to look into moving this from a long running post request to using websockets/signals or similar to stream notifications/messages to the ui.

jdpnielsen avatar Nov 08 '23 12:11 jdpnielsen

Just tried this on 13.2.0

Cancelling an Unpublishing Notification

image

I got the Cancelled by Third Party and my custom message without the errant success notification, all good... but

The unpublishing dialog stayed stuck on the screen once the notifications disappeared...

image

marcemarc avatar Mar 11 '24 17:03 marcemarc

Having a similar issue when cancelling a ContentCopyingNotification or a ContentMovingNotification.

For ContentCopyingNotification, the UI freezes up due to a JS error: image image The POST: PostCopy returns null

For ContentMovingNotification, the UI shows a success message even though the operation was cancelled. Looking at the BO content, no content was moved despite the success message in the UI.

rmnaderdev avatar Mar 11 '24 21:03 rmnaderdev