Try our conversational search powered by Generative AI!

HXH
HXH
May 1, 2012
  5467
(0 votes)

EPiServer Workflow Replacement : Step 6 - Hooking the Ready to Publish Event

This is the last in a series of posts about how my company built a replacement workflow platform for EPiServer. Why we chose to do this is explained here: http://world.episerver.com/Blogs/Hans/Dates/2012/4/EPiServer-Workflow-Replacement--Step-1Explanation-and-Disabling-Edit-Tab/

I’ve covered why we had to build our own workflow. I’ve gone into how to disable the base Workflow tab and replace it with your own GuiPlugin named Workflow. I’ve explained from the top down how this all works from a user/admin perspective, I’ve shown what database fields need to be updated to reject pages – and I’ve given you a workaround to disable that pesky Save and Publish button.

The only other critical component to this entire process is the ability  to notify approvers whenever a page is marked “Ready to Publish”. To do this, we create a new class and hook into the DataFactory.Instance.CheckingInPage event like so:

First – I create a new class : I named mine CustomPageActionControl.cs. I then designate it as a [PagePlugIn] and set up the Initialize method..this is where we hook CheckingInPage – in this instance by calling an additional class called NotifyApprovers.

    [PagePlugIn]
    public class CustomPageActionControl
    {
        public static void Initialize(int bitflags)
        {
            DataFactory.Instance.CheckingInPage += NotifyApprovers;
        }
    }
 

(As a side note, this is really handy for doing all sorts of other things..most of our sites also hook DataFactory.Instance.SavedPage, PublishedPage, DeletingPage, MovingPage, etc – there are all sorts of things you can hook into: http://sdk.episerver.com/library/cms5/html/AllMembers_T_EPiServer_DataFactory.htm )

 

Anyway..our NotifyApprovers method performs thusly:

  1. We get a working version of the page information that we want to send on – PageVersionURL, Approver User Names, etc..
  2. We iterate through an array of all access control entities, check their roles (in this instance they have to have LANGUAGE_EN-US or the correct locale access – so we don’t send our European users information about approving US Locale specific information) and getting a list of all users who can approve
  3. We email out all approvers with information about the page (as seen in step #3)

 

The below should be cleaned up and made more DRY (i.e. take advantage of LINQ), but you get the idea..

 

 private static void NotifyApprovers(object sender, PageEventArgs e)
        {
            String ApproverUserNames = "";
            List<String> EmailList = new List<String>();
            String PageVersionUrl = ConfigurationManager.AppSettings["BaseUrl"] + e.Page.LinkURL;
            PageVersionUrl = PageVersionUrl.Replace("&epslanguage", "_" + e.Page.WorkPageID + "&idkeep=True&epslanguage");

            foreach (EPiServer.Security.RawACE Ace in e.Page.ACL.ToRawACEArray()) // Get array of all access control entries
            {
                EPiServer.Security.AccessControlEntry EAC = new EPiServer.Security.AccessControlEntry(Ace);
                if ((Ace.Access & EPiServer.Security.AccessLevel.Publish) == EPiServer.Security.AccessLevel.Publish) //Only look at users who have access to publish page
                {
                    foreach (System.Web.Security.MembershipUser AllUsers in Membership.GetAllUsers())
                    {
                        if (Roles.IsUserInRole(AllUsers.UserName, "LANGUAGE_" + (Convert.ToString(e.Page.LanguageID)).ToUpper())) // User has locale access
                        {
                            if (Roles.IsUserInRole(AllUsers.UserName, Ace.Name))
                            { //user has publish access for this page
                                if (!EmailList.Contains(AllUsers.Email.ToString())) //only add users once
                                {
                                    ApproverUserNames += UserProfileTools.GetFullName(AllUsers.UserName.ToString()) + "; ";
                                    EmailList.Add(AllUsers.Email.ToString());
                                }
                            }
                        }
                    }

                }
            }

            String EmailBody = "<h2>EPiServer Approval Requested: Page Ready to Publish</h2><table style=\"font-family: Arial; font-size: 12px; \"><tr><td><b>Title:</b></td><td>" + e.Page.PageName + "</td></tr><tr><td><b>Submitter:</b></td><td>" + UserProfileTools.GetFullName(e.Page.ChangedBy) + "</td></tr><tr><td><b>Version URL:</b></td><td>" + PageVersionUrl + "</td></tr><tr><td><b>Published URL:</b></td><td>" + ConfigurationManager.AppSettings["BaseUrl"] + e.Page.LinkURL + "</td></tr><tr><td><b>Necessary Action:</b></td><td>This page is ready for your approval. Please log into EPiServer and visit the <i>Ready to Publish URL</i> specified above. For your reference, the current published page version is also available by visiting the <i>Published Version URL</i>." + "</td></tr><tr><td><b>Content Approvers:</b></td><td>" + ApproverUserNames + "</td></tr></table>";
            if (EmailList.Count() > 0)
               EmailTools.SendTemplatedEmail("EPiServer Page Approval Request – www.mysite.com", EmailBody, EmailList, "EPiServer@episerver.com", "EPiServer");

        }

 

And that’s it! When an editor hits “Ready to Publish”, all of the approvers are automatically notified that they need to go in and check out the content.

That sums up our custom workflow application. If you found it at all useful in any respect (or if you feel like pointing out my errors in logic and/or code) I’d love to hear from you in the comments below.

May 01, 2012

Comments

Aug 22, 2017 09:20 PM

17track.net

misor aliya
misor aliya Jun 1, 2018 10:15 AM

https://www.zillows.xyz/

nick010
nick010 Jul 11, 2018 09:16 PM

Jawaharlal Nehru Technological University, Kakinada is a public university, in Kakinada, East Godavari district, north of the Indian state of Andhra Pradesh. It is one of India's leading universities focusing on engineering for more JNTUK

Please login to comment.
Latest blogs
Optimizely and the never-ending story of the missing globe!

I've worked with Optimizely CMS for 14 years, and there are two things I'm obsessed with: Link validation and the globe that keeps disappearing on...

Tomas Hensrud Gulla | Apr 18, 2024 | Syndicated blog

Visitor Groups Usage Report For Optimizely CMS 12

This add-on offers detailed information on how visitor groups are used and how effective they are within Optimizely CMS. Editors can monitor and...

Adnan Zameer | Apr 18, 2024 | Syndicated blog

Azure AI Language – Abstractive Summarisation in Optimizely CMS

In this article, I show how the abstraction summarisation feature provided by the Azure AI Language platform, can be used within Optimizely CMS to...

Anil Patel | Apr 18, 2024 | Syndicated blog

Fix your Search & Navigation (Find) indexing job, please

Once upon a time, a colleague asked me to look into a customer database with weird spikes in database log usage. (You might start to wonder why I a...

Quan Mai | Apr 17, 2024 | Syndicated blog