Loading

Document based workflow approvers

In this post I'm going to share with you my experience with overriding workflow approvers and make them configurable on the document level.

Recently I've got the request from one of my client to build assets management system with Kentico CMS. One of the main features of that system is workflow. There are sections of the site, those have to be approved by different approvers, which are nothing special, so I suggested them to build a workflow per section and assign appropriate approvers to it. Customer kindly rejected my suggestion, as they were planning to maintain thousands (if not hundreds of thousands) pages within the site, so there were too many section. Also sections were too small - sometimes that was single document.

The best solution in this scenario was to allow customer to setup approvers on the document level. 

Add fields for approvers to a page type

First thing I had to do was adding appropriate fields to the page type. In my case there were around 10 page types, but luckily, all they inherit the same base page type. Inheritance with page types is as much useful as it is with regular C# classes, so do not hesitate to use it whenever applicable.

In order to accomplish this task, navigate Page Types application, find appropriate page type and open edit scree for it. Go to Fields tab and add new field. Use following setting for your field:

 


Data type: text

Size: 200 or any other reasonable number in your particular case

Form control: Uni selector

Object type: cms.user

Return column name: username

Selection mode: Multiple

 

Feel free to configure the rest of the fields according to your needs.

There is one good reason to use object code name or GUID instead of object ID: if you're running synchronization using content staging, you don't have to implement object ID translation. You can find more details about translation here.

Add another field with the same settings, except object type - set it to cms.role.

Those two fields allow you to add users or roles, those should approve document, on the Form tab of particular document.

Override workflow permissions

Next step is to authorize those users to perform an action on a document. This requires overriding of workflow security. So now we need to implement custom WorkflowManager class and override CheckStepPermissionsInternal:

 


[assembly: RegisterCustomManager(typeof(CustomWorkflowManager))]
public class CustomWorkflowManager : WorkflowManager
{
    protected override bool CheckStepPermissionsInternal(TreeNode node, UserInfo user, WorkflowActionEnum action)
    {
        if (action == WorkflowActionEnum.Approve)
        {
            // get users allowed to approve from the document
            var users = node.GetStringValue(<usersField>, "").Split(';').ToList();
            approvers.AddRange(UserInfoProvider.GetUsers().Where(u => users.Contains(u.UserID.ToString())));
            if (approvers.Contains(user))
            {
                return true;
            }    
            
            // get roles allowed to approve document
            var roles = document.GetStringValue(<rolesField>, "").Split(';').ToList();            
            foreach (string role in roles)
            {
                if (user.IsInRole(role, currentSiteName))
                {
                    return true;
                }
            }
        }

        return base.CheckStepPermissionsInternal(node, user, action);
    }
}

 

As you can see, document, user and workflow actions are available in this method and this is all what you need in order to figure out whether current user is in approvers list or not. In my code I'm reading appropriate fields of the document in order to get approving users and roles and checking whether current user is in one of those lists. Pay attention to the last line of the method: if user is not in those lists of approvers, I'm running default check, so I'm not screwing up default Kentico permission check. Be sure to add validation to this method in case you are going to reuse it - code above is not final and was implemented only in demo purposes.

Conclusion

To summarize this article I want to admit that we went through using Uni Selector control, mentioned foreign key translation while staging and overridden default Kentico WorkflowManager class. All this allowed us to override the way Kentico handles workflow and gave us possibility to configure approvers for workflow on document level, which enables us to reuse the same workflow with different sets of approvers.

PLease feel free to share your experience with the related topic or ask your questions if any.


Comments
Seo training Hyderabad
Learn professional digital marketing course/training in Hyderabad and upgrade your career by taking SEO/SMM/SEM/Adwords certification training
7/21/2017 11:45:38 AM

Accounts Training Online
All courses are delivered only by top trainers, training institutes and professionals with decades of teaching experience, helping thousands of learners advance their career.
7/19/2017 7:25:37 AM

download psiphon
Internet has become the one stop solution for all our problems and needs. From news to entertainment, you can get it all on the internet. For every type of requirements, there’s an array of websites present. Social media websites are becoming popular at a tremendous rate. Y
7/19/2017 6:04:55 AM

download whatsapp plus
Download Whatsapp Plus Latest App / Apk for Android Phones No Root Needed.WhatsApp plus Apk download for non rooted android receivers
7/12/2017 9:45:56 AM

whatsapp for pc
These informing stages are outstanding to be proficient on your PCs, similar to this is the situation for WhatsApp for PC.
7/10/2017 11:57:25 AM

Car auto
It is best to concentrate on what you think you are better at , then outsource the rest. You get more benefits in the process
7/10/2017 5:58:47 AM

Essay typer
I enjoyed reading your posts. Thanks for constructing useful/quality pieces
7/8/2017 9:53:07 PM

whatsapp plus download
Obviously you caught wind of WhatsApp Plus, I won't drag out you clarify, WhatsApp Plus is an adjusted form of WhatsApp have an excessive number of superb components, and non-existent in WhatsApp,
7/7/2017 4:35:37 AM

mobogenie pc
In this fast-paced world, it is necessary for you to keep up to date with the newest, fastest technological advancements.
7/5/2017 8:53:32 AM

mobogenie pc
In this fast-paced world, it is necessary for you to keep up to date with the newest, fastest technological advancements.
7/5/2017 8:53:31 AM

kingroot apk download
It seems to Root your device has become more important because when you take your phone out of the box, while there are plenty of settings you can adjust and you can only alter what the manufacturer allows you to do.
6/29/2017 10:03:32 AM

videoder apk download
Videoder App is a video downloading application that gets the videos to download in different pixels which include 1080, 720p, 480p, 360p, 240p, 144p, mp4 and mp3, more.
6/24/2017 9:32:38 AM

cheap pandora
Great Article it its really informative and innovative keep us posted with new updates. its was reallyvaluable. thanks a lot.<a href="http://www.buycharms.cn/">Cheap Pandora Sale</a> very good.
6/12/2017 9:02:07 AM

replica watch
[url=http://www.replicasrelojes.cn/]Replicas De Relojes[/url]
6/2/2017 3:27:30 AM

kopi rolex
Det finns ett brett utbud av [url=http://www.kopiurevip.com/]kopi rolex[/url]
5/31/2017 3:11:58 AM

kopi rolex
asdaafasas
5/26/2017 8:35:17 AM

kopi rolex
Det finns ett brett utbud av [url=http://www.kopiurevip.com/]kopi rolex[/url]
<a href="http://www.kopiurevip.com/">kopi rolex</a>
5/26/2017 2:32:18 AM

online
RSS puns feeds cialis pills for sale and intrusive sucidial thoughts.
5/22/2017 1:04:32 PM

hot sale replica watches
Out of work, party, you may need a watch to reflect your temperament and vision, to show you different from the general taste and vision. Here to meet your needs. thank.
5/16/2017 1:59:34 AM

hot sale replica watches
Out of work, party, you may need a watch to reflect your temperament and vision, to show you different from the general taste and vision. Here to meet your needs. thank.
5/12/2017 8:34:38 AM

nike shoes
Great Article it its really informative and innovative keep us posted with new updates. its was

reallyvaluable. thanks a lot.
5/8/2017 8:42:06 AM

hot sale replica watches
Both cheap and gorgeous fine imitation watches;<a href="http://www.uamoevent.com/">imitatie rolex horloges</a> filling your success style!
5/8/2017 7:20:27 AM

nike air max
Ultra-cool Nike running shoes[url=http://www.homesgb.co.uk/]air max 1[/url]
Have this running shoes you can go to the peak of life
Your fate is destined to need such a running shoes
5/8/2017 3:30:38 AM

nike air max
Ultra-cool Nike running shoes<a href="http://www.homesgb.co.uk/">air max 1</a>
Have this running shoes you can go to the peak of life
Your fate is destined to need such a running shoes
5/8/2017 3:27:33 AM

nike air max
Ultra-cool Nike running shoes[url=http://www.homesgb.co.uk/]nike air max 1[/url]
Have this running shoes you can go to the peak of life
Your fate is destined to need such a running shoes
5/6/2017 8:18:57 AM

nike air max
Ultra-cool Nike running shoes<a href="http://www.homesgb.co.uk/">nike air force 1</a>
Have this running shoes you can go to the peak of life
Your fate is destined to need such a running shoes
5/6/2017 8:17:09 AM

essaychief.com
Actually my current assignment have some important questions related to overriding workflow and now i got the answers of these questions with the help of this article. I would like to say Thanks for this impressive effort which done by the author of this article. I'm happy to come this site to have good piece of information.
5/2/2017 1:35:17 PM

Pharmg839
Very nice site! <a href="http://ypxoiea.com/ovyvorv/1.html">cheap viagra</a>
3/22/2017 4:21:11 PM

Pharma575
Hello! edkfbak interesting edkfbak site! I'm really like it! Very, very edkfbak good!
3/22/2017 4:20:49 PM

Joseph
Id forever want to be update on new articles on this internet site, bookmarked ! .
1/25/2017 9:14:37 AM

James
Hey very nice site!! Man .. Beautiful .. Amazing .. I will bookmark your blog and take the feeds alsoI am happy to find a lot of useful info here in the post, we need work out more techniques in this regard, thanks for sharing. . . . . .
12/2/2016 12:00:13 PM

Daniel
Enjoyed studying this, very good stuff, regards . A man may learn wisdom even from a foe. by Aristophanes.
10/26/2016 7:32:19 AM

David
Very neat article post.Much thanks again. Much obliged.
9/21/2016 5:17:24 PM

 Security code