Umbraco 13 – Double popup (Saved + Warning) when canceling operation in UserGroupSavingNotification

Hi Team,

I am facing an issue in Umbraco 13 while restricting users from being added to a specific group (“ImportAdmin”).

I have implemented a UserGroupSavingNotification handler to block non-authorized users from assigning users to the ImportAdmin group.

:white_check_mark: Backend logic is working correctly (users are restricted)

:cross_mark: Issue:
In the backoffice UI, when a restricted user tries to save: -
I am seeing TWO popups:

  1. “Saved” (green success message)
  2. “Permission denied” (warning message)

Expected behavior: Only the warning message should be displayed, and the “Saved” popup should not appear.

Code:

Path: \src\MastiffUmbraco.Core\Notifications\PreventImportAdminAssignment.cs

public void Handle(UserGroupSavingNotification notification)
{
var currentUser = _userService.GetByUsername(_backofficeUserAccessor?.BackofficeUser?.Name) ??
_userService.GetByEmail(_backofficeUserAccessor?.BackofficeUser.GetEmail());
var hasImportAdminAccess = currentUser.Groups != null && currentUser.Groups.Any(g => g.Alias == “importAdmin”);
foreach (var group in notification.SavedEntities)
{
if (group.Alias.Equals(“importAdmin”, StringComparison.OrdinalIgnoreCase))
{
if (!hasImportAdminAccess)
{

            notification.CancelOperation(
                                new EventMessage(
                                    "Permission denied",
                                    "Adding users to ImportAdmin group is restricted.",
                                    EventMessageType.Warning
                                )
                            );
            return;
        }
    }
}

}

Hi @Masood-h11p

Welcome to the forum!

The double popup is happening because of the EventMessageType you’re using. Warning (and Info/Success) don’t actually cancel the save - only EventMessageType.Error does. So with a Warning, your CancelOperation call adds the message but the save still completes, which is why you get both the green “Saved” toast and your “Permission denied” warning.

Switch it to Error:

notification.CancelOperation(
    new EventMessage(
        "Permission denied",
        "Adding users to ImportAdmin group is restricted.",
        EventMessageType.Error
    )
);

That will suppress the “Saved” popup and show only your denial message.

Justin

Hi @justin-nevitech ,
Thank you for response,
I tried with EventMessageType.Error
In this cases also double popup was showing with Red color.

Hi @Masood-h11p

Then it would appear it is a variation of this issue were some event notifications don’t honour the cancellation:

If that’s the case, then there’s not much you can do. I don’t know if this has been fixed in v17.

Justin

Hi @justin-nevitech ,

We are using Umbraco version 13.13.1

Hi @Masood-h11p

That issues applies to v13 so you may have to live with it I’m afraid - there won’t be anymore fixes to v13 unless they are security fixes.

Justin