November Happy Hour will be moved to Thursday December 5th.

Access rights

Vote:
 

Is there a way to filter a search result based on a specific user's access rights?

I have found this which filters based on 1 group:

.Filter(x => x.RolesWithReadAccess().Match("Everyone"))

What I need is to filter on multiple groups (all groups that the current users has) like:

.Filter(x => x.RolesWithReadAccess().MatchAny( new string[] { "Everyone", "Usergroup1", "Usergroup2" } ))

#63954
Dec 05, 2012 13:32
Vote:
 

I found the solution:

var pageAccessFilter = EPiServer.Find.SearchClient.Instance.BuildFilter<PageType>();
List<string> userRoles = Roles.GetRolesForUser().ToList();
userRoles.Add( "Everyone" );

foreach( string role in userRoles )
      pageAccessFilter = pageAccessFilter.Or( x => x.RolesWithReadAccess().Match( role ) );

.Filter( pageAccessFilter )

#63965
Dec 05, 2012 15:33
Vote:
 

Hi,

Looks good. I just want to add for future reference that the CMS 7 integration has quite a lot of functionality built in for filtering by publication status and access rights. Most significantly the FilterForVisitor methods.

#64045
Dec 08, 2012 11:06
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.