Comment Notification Based on ApprovalStatus

Comment Notification Based on ApprovalStatus

Posted on September 12, 2014 0 Comments

The content you're reading is getting on in years
This post is on the older side and its content may be out of date.
Be sure to visit our blogs homepage for our latest news, updates and information.

This article extends the sample given in our documentation. The article depicts how all comments send their notifications while the comment is waiting to be approved. This however poses a problem - why do frontend users need to be notified that a comment has been posted while they are unable to see it before it is approved and published. Therefore this sample will extend the functionality such that Administrator users get notified then the commend is send for approval and all other users get a notification once the comment has been published.

 Continuing from where the article leaves us we will need to only modify the implementation of the ICommentNotificationStrategy interface. First off we will need to modify the GetSubscriptionListKeys such that it returns an empty list of subscriber keys when the comment's status is marked as Waiting for Approval:

protected override IEnumerable<string> GetSubscriptionListKeys(ICommentEvent @event)
       {
           
           if ( @event.Item.Status == StatusConstants.WaitingForApproval)
           {
               return new List<string>();
           }
           else
           {
               return base.GetSubscriptionListKeys(@event);
           }
           
       

Next we need to create a new list and populate it with admin users. This list will help us construct a new ISubscriberRequest list which will include all the comment subscribers for this notification. Since we want the comments to go to administrators only we filter the users based on their role and create a new SubscriberRequest for each user. All of this needs to be done in the GetDynamicSubscribers method.

protected override IEnumerable<ISubscriberRequest> GetDynamicSubscribers(ICommentEvent @event)
        {
            if (@event.Item.Status == StatusConstants.WaitingForApproval)
            {
                var Admins = new List<ISubscriberRequest>();
                List<User> users = new List<User>();
                RoleManager roleMan = RoleManager.GetManager(SecurityManager.ApplicationRolesProviderName);
                users = roleMan.GetUsersInRole("Administrators").ToList();
 
            
                foreach (var item in users)
                {
                    var subscriberRequest = new SubscriberRequestProxy();
                    subscriberRequest.Email = item.Email;
                    subscriberRequest.FirstName = item.FirstName;
                    subscriberRequest.LastName = item.LastName;
                    subscriberRequest.ResolveKey = item.Id.ToString();
                    subscriberRequest.Disabled = false;
 
                    Admins.Add(subscriberRequest);
 
                }
                return Admins;
            }
            else
            {
                return null;
            }

At this point you are all set. You can find the complete code sample here.

Ivan D.Dimitrov

View all posts from Ivan D.Dimitrov on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.

Comments

Comments are disabled in preview mode.
Topics

Sitefinity Training and Certification Now Available.

Let our experts teach you how to use Sitefinity's best-in-class features to deliver compelling digital experiences.

Learn More
Latest Stories
in Your Inbox

Subscribe to get all the news, info and tutorials you need to build better business apps and sites

Loading animation