HXH
HXH
May 1, 2012
  5698
(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
How I Fixed DLL Conflicts During EPiServer CMS Upgrade to .NET Framework 4.8.1

We had a CMS solution of EPiServer 11.26.0, which was built on .NET Framework 4.7.1. We needed to update the target framework from .NET Framework...

calimat | Dec 12, 2024

Custom form element view in Optimizely CMS 12

Do you want full control over the form element markup? Create your own views!

Tomas Hensrud Gulla | Dec 11, 2024 | Syndicated blog

How to Elevate Your Experimentation - Opticon workshop experience

As a non-expert in the field of experimentation, I’d like to share my feedback on the recent Opticon San Antonio workshop session titled "How to...

David Ortiz | Dec 11, 2024

Persisting a Strawberry Shake GraphQL Client for Optimizely's Content Graph

A recent CMS project used Strawberry Shake to generate an up-to-date C# GraphQL client at each build. But what happens to the build if the GraphQL...

Nicholas Sideras | Dec 11, 2024 | Syndicated blog

Opti ID with Secure Cookies And Third Party AddOns

Opti ID has revolutionised access to the Optimizely One suite and is now the preferred authentication method on all PAAS CMS websites that I build....

Mark Stott | Dec 9, 2024

AsyncHelper can be considered harmful

.NET developers have been in the transition to move from synchronous APIs to asynchronous API. That was boosted a lot by await/async keyword of C#...

Quan Mai | Dec 4, 2024 | Syndicated blog