Permissions and workflow
Is it possible to have multiple workflows for pages enabled at the same time? One workflow for "Business Section" and another for "Human Resources" section? The would be independent of each other. I'm wondering if this scenario is possible. I'm finding that there is very little documentation on extending workflows.
Also, is it possible to "break inheritance" on a localized version of a page? Or all all language versions considered the same?
Hello David,
This would require the creation of a custom workflow. You can read more about custom workflows here:
www.sitefinity.com/.../custom-workflow
We have actually started developing a sample for a workflow that sets different approvers on different parts of the SiteMap. The class is still not finished, but you can used it as an example:
protected
override
void
Execute(CodeActivityContext context)
if
(ClaimsManager.IsUnrestricted())
return
;
var workflowDefinition = (WorkflowDefinition)context.DataContext.GetProperties()[
"workflowDefinition"
].GetValue(context.DataContext);
//gets the permissions
//var permissions = WorkflowPermissions.Split(new string[] "," , StringSplitOptions.RemoveEmptyEntries);
bool
userHasWorkflowPermission =
false
;
//gets currently approved pageNode
var item = context.DataContext.GetProperties()[
"workflowItem"
];
var page = item.GetValue(context.DataContext)
as
ISecuredObject;
var pageManager = PageManager.GetManager();
var node = pageManager.GetPageNode(page.Id);
//gets current user
var userID = SecurityManager.GetCurrentUserId();
var roleManager = RoleManager.GetManager();
var role = roleManager.GetRoles().Where(r => r.Name ==
"HomePageApprover"
).FirstOrDefault();
bool
isUserInRole = roleManager.IsUserInRole(userID, role.Id);
if
(node.Title ==
"homepage"
)
if
(isUserInRole)
userHasWorkflowPermission =
true
;
else
throw
new
WorkflowSecurityException(String.Format(
"User should be in role 0"
,
"TestRole"
));
else
if
(isUserInRole)
throw
new
WorkflowSecurityException(String.Format(
"User should not be in role 0"
,
"TestRole"
));
else
userHasWorkflowPermission =
true
;
If the page that I'm working with is multilingual, how would I get the ApprovalWorkflowState of each language?
This is what I've done so far, but its only getting the current page's state.
01.
//gets currently approved pageNode
02.
var item = context.DataContext.GetProperties()[
"workflowItem"
];
03.
04.
var page = item.GetValue(context.DataContext)
as
ISecuredObject;
05.
var pageManager = PageManager.GetManager();
06.
var node = pageManager.GetPageNode(page.Id);
07.
var pageProperties = pageManager.GetProperties();
08.
09.
Telerik.Sitefinity.Pages.Model.PageData pageData = pageManager.GetPageData(node.PageId);
10.
11.
12.
//gets current user
13.
var userID = SecurityManager.GetCurrentUserId();
14.
var roleManager = RoleManager.GetManager();
15.
var role = roleManager.GetRoles().Where(r => r.Name ==
"HomepageApprover"
).FirstOrDefault();
16.
17.
bool
isUserInRole = roleManager.IsUserInRole(userID, role.Id);
18.
string
emailString =
""
;
19.
string
vmNotes =
""
;
20.
string
sState=
""
;
21.
string
sTitle =
""
;
22.
23.
foreach
(var curLang
in
node.AvailableLanguages)
24.
25.
sTitle = node.Title;
26.
sState = node.ApprovalWorkflowState;
27.
GetUsersOfLanguage(curLang.ToString());
28.
This will get the info you want:
var childNodes = App.WorkWith().Pages().LocatedIn(PageLocation.Frontend).Where(p => p.Parent.Id == parentId).Get().ToList();
int
AwaitingPublishingChildNodes = childNodes.Where(cnt => cnt.ApprovalWorkflowState ==
"AwaitingPublishing"
).Count();
David,
After working with Matt on this for quite some time -- we found out there are two ways to get the status of Localized pages.
1) Synced Pages
If your pages are synced -- you can get all information from your current node properties -- just
use the culture desired as a filter -- see this post for more help: http://bit.ly/170jqrZ
//gets currently approved pageNode
var item = context.DataContext.GetProperties()[
"workflowItem"
];
var page = item.GetValue(context.DataContext)
as
ISecuredObject;
var pageManager = PageManager.GetManager();
var node = pageManager.GetPageNode(page.Id);
var currentLanguage = node.Page.UiCulture.ToString();
//Get Page Permissions
var pagePermissions = page.GetActivePermissions();
List<System.Globalization.CultureInfo> pageCultures =
new
List<System.Globalization.CultureInfo>(node.AvailableCultures);
int
AwaitingPublishingCount = 0;
bool
EnglishAwaitingApproval =
false
;
List<
string
> PagesAwaitingApproval =
new
List<
string
>();
int
localizedPagesCount = 0;
if
(node.Page.LocalizationStrategy == Telerik.Sitefinity.Localization.LocalizationStrategy.Synced)
//Pages are synced -- get all localized statuses from the current node
localizedPagesCount = pageCultures.Count();
foreach
(var pc
in
pageCultures)
if
(node.ApprovalWorkflowState[pc.Name] ==
"AwaitingPublishing"
)
AwaitingPublishingCount++;
if
(pc.Name ==
"en"
)
EnglishAwaitingApproval =
true
;
//gets currently approved pageNode
var item = context.DataContext.GetProperties()[
"workflowItem"
];
var page = item.GetValue(context.DataContext)
as
ISecuredObject;
var pageManager = PageManager.GetManager();
var node = pageManager.GetPageNode(page.Id);
var currentLanguage = node.Page.UiCulture.ToString();
//Get Page Permissions
var pagePermissions = page.GetActivePermissions();
List<System.Globalization.CultureInfo> pageCultures =
new
List<System.Globalization.CultureInfo>(node.AvailableCultures);
int
AwaitingPublishingCount = 0;
bool
EnglishAwaitingApproval =
false
;
List<
string
> PagesAwaitingApproval =
new
List<
string
>();
int
localizedPagesCount = 0;
if
(node.Page.PageLanguageLink !=
null
)
//Pages are separate
List<PageData> localizedPages = node.Page.PageLanguageLink.LanguageLinks.ToList();
localizedPagesCount = localizedPages.Count();
foreach
(var lp
in
localizedPages)
if
(lp.NavigationNode.ApprovalWorkflowState ==
"AwaitingPublishing"
)
AwaitingPublishingCount++;
if
(lp.UiCulture ==
"en"
)
EnglishAwaitingApproval =
true
;