Hiding Menu Items

Mark Kornhauser asked on August 20, 2020 06:05

I have created a couple of page types that I am using for a dynamic menu system within K12SP, and everything has been working well until I have tried to implement security against menus built on those page types. I need to hide various items if the user in unauthenticated or if they do not belong to a specific role. I'm pretty sure that I have set things up correctly but when I include .GetPermissions() in my DocumentHelper.GetDocuments method call I am not getting any data returned at all.

Does anybody have any idea what I might be doing wrong?

public IEnumerable<MainMenuItemViewModel> GetMenuItems()
{
    return DocumentHelper.GetDocuments<MainMenuItem>()
             .AddColumns("DisplayText", "Link")
             .CheckPermissions()
             .Select(x => new MainMenuItemViewModel()
              {
                  DisplayText = x.DisplayText,
                  Link = x.Link,
                  SubItems = GetSubItems(x)
              });
}

This is what it looks like in the Pages application. I require that the Partner page is only visible to authenticated users who belong to the Sage Solution Provider role.

Image Text

Correct Answer

Mark Kornhauser answered on August 21, 2020 03:08

Thanks for all your responses. In the end I have found that it is the CheckPermissions method call that is causing the problems. As soon as you are authenticated then you lose access to Public Anonymous User pages as soon as you login in, therefore you must be assigned to a new role (e.g. Registered User) that has the same rights as the Public Anonymous User. I just need to make sure that a new user is automatically added to that role as soon as they register.

I have followed Arjan's advice, but am still not entirely happy with this solution. Someone please tell me if there is a better way to make all items/pages etc available to everyone (authenticated or not), unless a particular item has broken page permission inheritance and stipulated specific access for named users and/or roles.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Brenden Kehren answered on August 20, 2020 06:54

First off, you're running a vanilla version of Kentico, v12.0. If you upgraded your nuget package in the MVC app and didn't apply the update to the CMS app and the database then this could be part of your problem.

I'd suggest getting the MVC app and the Kentico app on the same version and see if this resolved your problem. If not, report back.

1 votesVote for this answer Mark as a Correct answer

Arjan van Hugten answered on August 20, 2020 09:49 (last edited on August 20, 2020 09:49)

Hi,

You must also make sure that all the other pages have anonymous (Public anonymous user) access. Also make sure that other roles also have read access on all the other pages.

2 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on August 20, 2020 10:53

Hi,

Maybe you can try filtering the pages using a CMSActionContext and passing the current user into the context wrapped around the query?

See this documentation page for some sample code: https://docs.kentico.com/api12/content-management/page-security#Pagesecurity-Filteringloadedpagesaccordingtopermissions

0 votesVote for this answer Mark as a Correct answer

Liam Goldfinch answered on August 21, 2020 10:00 (last edited on August 21, 2020 10:04)

Hi Mark

I suggest you read this page on how to correctly set permissions on pages in the tree, https://docs.kentico.com/k12/managing-users/configuring-permissions/configuring-page-permissions/page-level-permissions-acls/restricting-pages-based-on-permissions - read the sections Assigning page-level permissions and Hiding selected child pages

The key bit here is that you need to add all roles to the master page and provide read permissions, then on the item you want to hide, break inheritance and set the correct permissions for the roles required. E.g remove/deny permissions for public anonymous user and only provide permissions for your registered role

0 votesVote for this answer Mark as a Correct answer

Mika Hawkins answered on August 29, 2020 14:15

Hi mark, I think ou should check out link text

Hope this helps you... Regards, Mika Hawkins

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.