Display to roles macro

Justin Hugelen-Padin asked on November 13, 2014 02:54

I'm having difficulty displaying a list of pages depending on the roles of the user who is logged. I thought I could accomplish it by creating a macro in the "Display to roles" under the Visibility tab in my Repeater, but I'm confused on exactly how to do.

Here's an example. I have the following pages and their roles:

Page1 - cool_users Page2 - notcool_users Page3 - cool_users

So when a cool_users logs in I would like to display only those Pages which have the cool_users roles.

Does that make sense?

thanks, Justin

Recent Answers


Virgil Carroll answered on November 13, 2014 05:35

The method you are using would apply to the repeater control itself, not the items that are displays inside the control. To limit those by permission you are going to need to do Some kind of check in the item transformation to show or hide an item based on permissions.

There is not a real solid way to accomplish without writing your own custom macro to check a users permission while looping through the items. I have written many similar.

Another, less best practice method, would be to use one of the out of the box macros to check something on each page using the users permissions. If the user does not have access and the call fails, then don't show the overall page information. Very much a cheat, but could work.

You can learn more about those type of permission calls,with your macros here: http://devnet.kentico.com/articles/page-macro-expressions-security

0 votesVote for this answer Mark as a Correct answer

Tim Spring answered on November 13, 2014 14:29 (last edited on December 10, 2019 02:30)

Another kind of cheat you could using is a pages Form/Menu Group property.

Set all cool pages to menu group "top", and all non-cool pages to menu group "footer"

Then put something like this in your repeaters WHERE condition field: MenuItemGroup='{% if(IsInRole(CurrentUser, "cool_users")) {"top"} else {if(IsInRole(CurrentUser, "notcool_users")){"footer"}} |(identity)GlobalAdministrator%}'

0 votesVote for this answer Mark as a Correct answer

Justin Hugelen-Padin answered on November 14, 2014 16:03

Good answers, the only issue is that I'm trying to figure out how to check the roles that are assigned to the Document?

The structure that I have is: -Committees ---Committee Name ------Articles

So the idea is that when the user logs in then only the Committee Names show up on the Committees landing page which the user belongs to. Specific roles are applied to each Committee Name document. Any idea on the best way to display it? I think that check in the transformation, is right but I can't figure out the right syntax for that checking the Committee Name document's roles.

thanks!

0 votesVote for this answer Mark as a Correct answer

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