Portal Engine Questions on portal engine and web parts.
Version 5.x > Portal Engine > Alternative Forms by User Role on Document Type Form Tab View modes: 
User avatar
Certified Developer v7
Certified  Developer v7
EMAR - 6/23/2011 3:16:34 PM
   
Alternative Forms by User Role on Document Type Form Tab
Is it possible to change the form that appears on CMS Desk -> Content -> [Node] -> Form Tab by the role assigned to a user?

The idea being that certain users can only modify selected fields for a given document type.

Thanks,
EMAR

User avatar
Member
Member
kentico_michal - 6/24/2011 1:14:36 AM
   
RE:Alternative Forms by User Role on Document Type Form Tab
Hello Emar,

You will need to create different alternative forms according to your needs. Let’s assume that I have two roles (RoleA and RoleB) and CMS.News document type. So, I can create two alternative forms in Site Manager -> Development -> Document types -> edit CMS.News -> Alternative forms. The first alternative form will be used for users of role RoleA, so I will call it insertRoleA, the second one will be used when editor of role RoleB creates document of type CMS.News, so I will call it insertRoleB.

Now, you need to modify ~\CMSModules\Content\CMSDesk\Edit\Edit.aspx.cs file and change the AlternativeFormFullName property of the CMSForm control dynamically depending on the role of the current user. So please go to OnInit method and add following code marked as CUSTOM CODE:


formElem.FormMode = FormModeEnum.Insert;
string newClassName = ci.ClassName;
formElem.FormName = newClassName + ".default";

//////////////CUSTOM CODE////////////////
if (newClassName.Equals("CMS.News"))
{
if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("RoleA", CMS.CMSHelper.CMSContext.CurrentSiteName))
{
formElem.AlternativeFormFullName = newClassName + ".insertRoleA";
}
else if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("RoleB", CMS.CMSHelper.CMSContext.CurrentSiteName))
{
formElem.AlternativeFormFullName = newClassName + ".insertRoleB";
}
}
////////////////////////////////////////
}
else if (newculture)



You could do the same for updating alternative forms, for example updateRoleA and updateRoleB alternative forms.

In this case the following code needs to be used:


else
{
formElem.FormMode = FormModeEnum.Update;
ci = DataClassInfoProvider.GetDataClass(node.NodeClassName);

//////////////CUSTOM CODE////////////////
string newClassName = ci.ClassName;
if (newClassName.Equals("CMS.News"))
{
if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("RoleA", CMS.CMSHelper.CMSContext.CurrentSiteName))
{
formElem.AlternativeFormFullName = newClassName + ".updateRoleA";
}
else if (CMS.CMSHelper.CMSContext.CurrentUser.IsInRole("RoleB", CMS.CMSHelper.CMSContext.CurrentSiteName))
{
formElem.AlternativeFormFullName = newClassName + ".updateRoleB";
}
}
////////////////////////////////////////

}
formElem.Visible = true;



I hope this will help you.

Best regards,
Michal Legen

User avatar
Certified Developer v7
Certified  Developer v7
EMAR - 6/24/2011 9:34:58 AM
   
RE:Alternative Forms by User Role on Document Type Form Tab
Thanks Michal. That did the trick.