The content you're reading is getting on in years This post is on the older side and its content may be out of date. Be sure to visit our blogs homepage for our latest news, updates and information.
public
class
SearchResultsByPermissions : SearchResults
{
}
protected
override
void
InitializeControls(GenericContainer container)
Label resultsStats =
this
.ResultsStats;
//this is the original localized stats message. It shows all the results
var resultsStatsMessage = resultsStats.Text;
base
.InitializeControls(container);
if
(
string
.IsNullOrEmpty(
.Query))
.ResultsStats.Text =
.Empty;
return
;
int
numberOfAllResults = 0;
SearchResults.ISearcher searcher =
.GetSearcher();
//these are all the results (not filtered by permissions)
var allResults = searcher.Search(
.Query,
.IndexCatalogue, 0, 0,
out
numberOfAllResults);
(allResults ==
null
)
//here we will store only the results we have permissions to see
List<IDocument> securedResultSet =
new
List<IDocument>();
foreach
(var document
in
allResults)
var type = document.GetValue(
"ContentType"
);
var ID =
Guid(document.GetValue(
"OriginalItemId"
));
(TypeResolutionService.ResolveType(type) ==
typeof
(PageNode))
var manager = PageManager.GetManager();
//suppress the security checks so the code can be executed even if
//the current user doesn't have enough permissions
manager.Provider.SuppressSecurityChecks =
true
var page = manager.GetPageNode(ID);
(page !=
ISecuredObject securedObject = (ISecuredObject)page;
(SecurityExtensions.IsSecurityActionTypeGranted(securedObject, SecurityActionTypes.View))
securedResultSet.Add(document);
false
var numberOfSecuredSearchResults = securedResultSet.Count;
char
[] chrArray =
[] {
'\"'
};
str =
.Query.Trim(chrArray);
resultsStats.Text =
.Format(resultsStatsMessage, numberOfSecuredSearchResults, HttpUtility.HtmlEncode(str));
.ConfigurePager(numberOfSecuredSearchResults);
.ResultsList.DataSource =
itemsToSkip =
.GetItemsToSkip();
itemsToTake =
.GetItemsToTake();
ResultsList.DataSource = securedResultSet.Skip(itemsToSkip).Take(itemsToTake);
private
GetItemsToSkip()
.AllowPaging)
pageNumber =
.GetPageNumber(
.GetUrlEvaluationMode(),
.PageKey, 0,
"PageNumber"
(pageNumber > 0)
(pageNumber - 1) *
.ItemsPerPage;
0;
GetItemsToTake()
(!
View all posts from The Progress Team on the Progress blog. Connect with us about all things application development and deployment, data integration and digital business.
Subscribe to get all the news, info and tutorials you need to build better business apps and sites
Copyright © 2019 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
Progress, Telerik, and certain product names used herein are trademarks or registered trademarks of Progress Software Corporation and/or one of its subsidiaries or affiliates in the U.S. and/or other countries. See Trademarks for appropriate markings.