private void CheckAvailability(List<SearchResultItem> results) { if (results.Count == 0) { return; } if (!cmsConfiguration.Security.AccessControlEnabled) { // If security is not enabled, all content is available return; } // Create query var principal = securityService.GetCurrentPrincipal(); var urls = results.Select(r => r.Link).ToArray(); var query = repository.AsQueryable<Page>(p => urls.Contains(p.PageUrl)); var pages = query .SelectMany(c => c.AccessRules, (page, accessRule) => new { PageUrl = page.PageUrl, AccessRule = accessRule }) .ToList(); foreach (var pageUrl in pages.Select(p => p.PageUrl).Distinct()) { var page = pages.First(p => p.PageUrl == pageUrl); IList<IAccessRule> accessRules = pages.Where(p => p.PageUrl == pageUrl).Select(p => p.AccessRule).Cast<IAccessRule>().ToList(); var level = accessControlService.GetAccessLevel(accessRules, principal); if (level < AccessLevel.Read) { results.Where(r => r.Link == page.PageUrl).ToList().ForEach(r => r.IsDenied = true); } } results.ForEach(p => { if (p.IsDenied) { p.Link = string.Empty; p.FormattedUrl = LuceneGlobalization.SearchResults_Secured_LinkTitle; p.Title = LuceneGlobalization.SearchResults_Secured_Title; p.Snippet = LuceneGlobalization.SearchResults_Secured_Snippet; } }); }