HXH
HXH
May 1, 2012
  5647
(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 Forms: You cannot submit this form because an administrator has turned off data storage.

Do not let this error message scare you, the solution is quite simple!

Tomas Hensrud Gulla | Oct 4, 2024 | Syndicated blog

Add your own tools to the Optimizely CMS 12 admin menu

The menus in Optimizely CMS can be extended using a MenuProvider, and using the path parameter you decide what menu you want to add additional menu...

Tomas Hensrud Gulla | Oct 3, 2024 | Syndicated blog

Integrating Optimizely DAM with Your Website

This article is the second in a series about integrating Optimizely DAM with websites. It discusses how to install the necessary package and code t...

Andrew Markham | Sep 28, 2024 | Syndicated blog

Opticon 2024 - highlights

I went to Opticon in Stockholm and here are my brief highlights based on the demos, presentations and roadmaps  Optimizely CMS SaaS will start to...

Daniel Ovaska | Sep 27, 2024

Required fields support in Optimizely Graph

It's been possible to have "required" properties (value must be entered) in the CMS for a long time. The required metadata haven't been reflected i...

Jonas Bergqvist | Sep 25, 2024

How to write a bespoke notification management system

Websites can be the perfect vehicle for notifying customers of important information quickly, whether it’s the latest offer, an operational message...

Nicole Drath | Sep 25, 2024