How to hide MyDesk tab in CMSDesk according to role

   —   
This article shows how to hide MyDesk tab in CMSDesk according to current user´s role.
In CMSDesk you can see 4 tabs in header. Content, MyDesk, Tools, Administration. Using our default permissions, it is possible to hide three of them: Content, Tools and Administration. It can be done in Administration -> Permission dialog.
If you want to hide MyDesk tab, you will need to modify appropriate page´s code-behind. To do so, please open your web project in Visual Studio and edit CMSDesk/header.aspx.cs file.

By default, you will see this code:

if (IsUserAuthorizedPerContent())
{
tabList.Add("content");
}

tabList.Add("mydesk");

if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.tools", "Open"))
{
tabList.Add("tools");
}

if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.administration", "Read"))
{
tabList.Add("administration");
}

As you can see, mydesk tab is added always, without permission check. You cannot use IsAutorizedPerResource() method, since this option (cms.mydesk) is not in permission matrix available. But you can use IsInRole() method and modify code following this example:

if (IsUserAuthorizedPerContent())
{
tabList.Add("content");
}


if (CMSContext.CurrentUser.IsInRole("CMSEditor", "CorporateSite"))
{
tabList.Remove("mydesk");
}
else
{
tabList.Add("mydesk");
}


if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.tools", "Open"))
{
tabList.Add("tools");
}

if (CMSContext.CurrentUser.IsAuthorizedPerResource("cms.administration", "Read"))
{
tabList.Add("administration");
}

The bold lines are modified. If the current user is in appropriate role (e.g. CMSEditor) for Corporate site, MyDesk tab will be hidden (removed). It stays visible for every other role.

Update:
Since Kentico CMS 5.0 it is possible to achieve above mentioned using UI personalization feature.

See also:

Applies to: Kentico CMS 4.0
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.