Virtual Happy Hour this month, Jun 28, we'll be getting a sneak preview at our soon to launch SaaS CMS!

Try our conversational search powered by Generative AI!

Make system send notifications to admins in the CMS edit interface (the bell icon at the top right). Fetch users that have logged in with Azure AD

Vote:
 

Hi, I'm creating a scheduled job that notifies admins when a block has been deleted by the system, and where it has been used. For that to work we need to fetch users in the group WebAdmins that have logged in with Azure AD. How do we fetch users that have logged in with Azure AD, and is in the group WebAdmins? For sending user notifications, we are using the interface INotifier. An example:

_notifier.PostNotificationAsync(new NotificationMessage()
                {
                    ChannelName = "SlettingAvBlokk",
                    Content = content,
                    Subject = "Ansattblokk slettet",
                    Recipients = receivers,
                    Sender = sender,
                    TypeName = "PageChanged"

}).GetAwaiter().GetResult();

Where receivers should be user in the group WebAdmins that have logged in with Azure AD. We have created a group in Azure AD for WebAdmins, so the users should be synced to the CMS group WebAdmins. In the database table SynchronizedUsers, we see the users logged in with Azure AD.

#304495
Edited, Jul 03, 2023 7:13
Vote:
 

Have you tried using the SynchronizingRolesSecurityEntityProvider ?

#304599
Jul 04, 2023 10:04
Tam Duc Ha Vo - Jul 04, 2023 10:11
I have not. I'll try it and get back to you. Thank you!
Vote:
 

Alright, so the class you mentioned has a function FindUsersInRoleAsync, and it returns a Tuple<IEnumerable<string>, int>, where IEnumerable<string> is a list of usernames. 

_notifier.PostNotificationAsync(new NotificationMessage()
                {
                    ChannelName = "SlettingAvBlokk",
                    Content = content,
                    Subject = "Ansattblokk slettet",
                    Recipients = receivers,
                    Sender = sender,
                    TypeName = "PageChanged"

}).GetAwaiter().GetResult();

The method expects Recipients to be an IEnumerable<INotificationUser>. How can we get INotificationUser-objects from a list of usernames? Can we call the method FindAsync in the class QueryableNotificationUserService to retrieve INotificationUsers, or would that not work since users are logging in with Azure AD?

#304796
Jul 07, 2023 12:57
Vote:
 

Hi Tam

You can create the NotificationUser objects as follows, and pass to the PostNotificationAsync method

 var users = await _synchronizingRolesSecurityEntityProvider.FindUsersInRoleAsync("WebAdmins", null);
 var notificationRecipients = users.Select(u => new NotificationUser(u));

I believe the Notification Dispatcher Job will resolve the users when sending the emails. Give it a go 

#304975
Jul 11, 2023 7:13
Tam Duc Ha Vo - Jul 11, 2023 10:25
Hi, Ron

Ah, I see. So the scheduled job will be sending emails, and not sending it as a notification in the CMS (The bell icon on the top right corner)?
- Jul 12, 2023 0:00
Sorry I misunderstood. After posting the notification, it will be displayed instantly in the CMS UI. The method also puts it in a message queue for sending of email notifications by the NotificationDispatcher scheduled job.
If you need to verify, posted notifications are in the tblNotificationMessage table
Tam Duc Ha Vo - Jul 12, 2023 10:40
It works! Thank you!
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.