Base solution for your next web application
Open Closed

notifications seem to be unreliable #7210


User avatar
0
alexanderpilhar created

6.9.1, Angular, .NET Framework

I'm trying to implement notifications similar to NewTenantRegisteredAsync(...) of AppNotifier.cs to inform host users about entities being created by tenant users. But none of the notifications ever seem to show up. So I tried with NewTenantRegisteredAsync(...) as my implementation is very similar and I only got one notification out of 4 test runs ... Also, the one notification that I received took a couple of minutes to show up ... In database there also is only the one notification.

Other notifications seem to work fine (e.g. WelcomeToTheApplicationAsync(..) and GdprDataPrepared(...)).


7 Answer(s)
  • User Avatar
    0
    alper created
    Support Team

    show what you've done. some important key points are

    • https://github.com/aspnetzero/aspnet-zero-core/blob/baef4039e577e344d00f8e8b1bc59f2383307fb6/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Core/Notifications/AppNotifier.cs#L45
    • https://github.com/aspnetzero/aspnet-zero-core/blob/baef4039e577e344d00f8e8b1bc59f2383307fb6/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/wwwroot/Common/Scripts/appUserNotificationHelper.js#L26
    • https://github.com/aspnetzero/aspnet-zero-core/blob/29212eb9058eeef8380e83ac1d216a747d3d06d6/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Application/MultiTenancy/TenantRegistrationAppService.cs#L114
    • https://github.com/aspnetzero/aspnet-zero-core/blob/baef4039e577e344d00f8e8b1bc59f2383307fb6/aspnet-core/src/MyCompanyName.AbpZeroTemplate.Web.Mvc/wwwroot/Common/Scripts/appUserNotificationHelper.js
  • User Avatar
    0
    alexanderpilhar created

    Hi @alper!

    I didn't change any of the code for notifications that ship with ASPNETZERO.

    I just implemented some classes:

    • ProjectNameNotificationNames (similar to AppNotificationNames)
    • ProjectNameNotificationProvider (similar to AppNotificationProvider; added to notification providers in ProjectNameCoreModule.cs)
    • IProjectNameNotifier (similar to IAppNotifier)
    • ProjectNameNotifier (similar to AppNotifier)

    I already triple-checked them for typos and similar mistakes.

    Anyway, I'm more confused about why I don't receive a new notification for each NewTenantRegisteredAsync(...) ... To me it seems like a problem with NotificationPublisher.PublishAsync(...).

    Maybe there is something unexpected happening when there is neither any tenantIds nor any userIds passed on to PublishAsync()? Like AbpSession.TenantId might have a value other than null but notifications cannot be sent or received since tenant users don't have permission to do so (refering to permissionDependecy in NotificationProvider)? Just guessing as I don't know how to test this.

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @alexanderpilhar

    Is the logged in user registered to this notification and receiving the notifications enabled for this user ? You can click open notification settings page to see it:

  • User Avatar
    0
    alexanderpilhar created

    Hi @ismcagdas! Yes, notification settings are correct.

    I think I found what was causing the problem with not receiving further notifications for NewTenantRegisteredAsync(...): After registering a new tenant I used the browser's back-button to go back to registering the next new tenant - in this case no further notification is sent (note that the newly registered tenant is selected automatically after registration). But if I just delete the /account/register-tenant-result-part from the browser's address-bar to get back to login page and start a fresh registration from there (first switch from new tenant back to host) everything works as expected. So, I think the fact that after a successful registration, the new tenant was selected automatically for login was causing the problem (as AbpSession.TenantId for sure was something other than null). I guess, this is not something that would happen in reality - so, there is no issue here (and sorry for stealing your time).

    Next, I will try to make my custom notifications work - but I might start a new questions if I still face problems!

  • User Avatar
    0
    alexanderpilhar created

    I'm reopening this because I now know why my custom notifications don't work - and the reason is similar to what I explained in my comment above.

    The situation is the following: If a tenant user creates or edits an entity, a notification will be sent to host users and the entity will be temporarely locked to be reviewed by a host user with a sepecific permission. Since I want any host user (given the specific permission) to be able to receive the notification, I don't pass any tenantIds or userIds to NotificationPublisher.PublishAsync(...). But this doesn't lead to the correct result because if no tenantIds and no userIds are passed on, then the tenantIds will be set to an array containing AbpSession.TenantId which is the current tenant as we can see here. This means I cannot trigger a notification by a tenant user and send it to all host users. At least not this way.

    Is there any easy solution to what I want to achieve? Right now I can only think of retrieving all host users and add them to userIds - any better ideas?

  • User Avatar
    0
    alper created
    Support Team

    you can send the message to online clients https://aspnetboilerplate.com/Pages/Documents/SignalR-Integration#online-clients

  • User Avatar
    0
    alexanderpilhar created

    Thank you for your reply @alper!

    I chose to do it by making use of UserManager:

    [UnitOfWork]
    private async Task<UserIdentifier[]> GetHostUserIds()
    {
        using (CurrentUnitOfWork.DisableFilter(AbpDataFilters.MayHaveTenant))
        {
            var hostUsers = await _userManager.Users.Where(e => e.TenantId == null).ToListAsync();
    
            var hostUserIds = new UserIdentifier[hostUsers.Count];
    
            for (var i = 0; i < hostUsers.Count; i++)
            {
                hostUserIds[i] = hostUsers[i].ToUserIdentifier();
            }
    
            return hostUserIds;
        }
    }
    

    Works nicely!