Hi,
In the AccountController.cs code I noticed the following:
await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(user.ToUserIdentifier());
When defining Notifications, where do we specify notifications that is available for users? What is meant by the code above?
So far I noticed there are only 2 notifications defined. So how does Notification work in this case?
context.Manager.Add(
new NotificationDefinition(
AppNotificationNames.NewUserRegistered,
displayName: L("NewUserRegisteredNotificationDefinition"),
permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Administration_Users)
)
);
context.Manager.Add(
new NotificationDefinition(
AppNotificationNames.NewTenantRegistered,
displayName: L("NewTenantRegisteredNotificationDefinition"),
permissionDependency: new SimplePermissionDependency(AppPermissions.Pages_Tenants)
)
);
Thanks
8 Answer(s)
-
0
Hi,
When you are defining notifications, you can specify permissions. This method ensures that only users has permisison can subscribe to notification.
-
0
So, if I define a new Notification Type NN with a Permission X, then if I add the Permission X to Group Users, then any member of this group would receive notifications of type NN?
One more thing, when subscribing to notification types, is this information stored in the database? So, if the application publishes several notifications, then when the user logins with appropriate permissions, he/she will be able to see all collected notifications?
For instance,
//Notifications await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(user.ToUserIdentifier());
This means that somewhere in the DB, the newly registered user, is now subscribed to all notifications that this uer's role/group has permission for?
Also, in this code:
public async Task WelcomeToTheApplicationAsync(User user) { await _notificationPublisher.PublishAsync( AppNotificationNames.WelcomeToTheApplication, new MessageNotificationData(L("WelcomeToTheApplicationNotificationMessage")), severity: NotificationSeverity.Success, userIds: new[] { user.ToUserIdentifier() } ); }
The Notification Type "WelcomeTpTheApplication" is published and targeting specific users, correct? So, given the first call above, this means, the user is now subscribed to receive this notification correct?
Also, I read somewhere in the documentation, a notification type should be registered before it is being used. In this case, I don't see anywhere in the code where this specific notification type is registered?
Also, since the code subscribes a newly registered user to all notifications that users have permission on, so my custom code can simply publish notifications and I don't need to worry about how to pass the notifications to users, this is done automatically by the framework given of course this line of code:
//Notifications await _notificationSubscriptionManager.SubscribeToAllAvailableNotificationsAsync(user.ToUserIdentifier());
Finally, are notifications stored in the DB? When he/she logs in, then all notifications that were published before, would now load for the user to see?
Many thanks
-
0
Hi,
Yes notifications are stored in DB. When user logs in, it is showed to user.
Users can also list the notifications send to them. Each user can select which notifications to receive via notification settings window.
-
0
How come one of the notifications the "welcome" is not defined before used? Can we do this? If a notification type is not defined then when publishing we can limit it for a tenant(s) or user(s)?
also, if the application sends a notification while user is logged in, it will popup? Or how?
thanks
-
0
Hi,
If you add a new NotificationDefinition just like we do in AppNotificationProvider, then users can choose to receive it or not. If you don't define it just like Welcome notificataion, it will not appear on notification settings dialog. But if user chooses to close "Receive Notifications" option, user will not get any notifications.
See this doc for how notifications are displayed to user <a class="postlink" href="https://aspnetzero.com/Documents/Development-Guide-Core#notifications">https://aspnetzero.com/Documents/Develo ... ifications</a>
-
0
Thank you.
So basically defining a Notification Type helps in many things: 1- Users can unsubscribe to notification types 2- Permission can be given for the notification type, who can see this notification or not
Regards Bilal
-
0
Yes, this is a better and shorter explanation :). Thanks.
-
0
Thanks, you rock :)