Tuesday, April 29, 2008

Searching pending approval documents

If you have enabled the content approval in your document libraries and only the approvers of the items can access to the unpublished versions, you will have a problem with the search. When a user launches a search query, he will see listed in the search results the pending approval documents although he does not have permissions to access to an unpublished version of it. It will be able to read all the indexed data, but when he tries to access to the item it gets an unauthorized error.

This behavior is correct, because the security trimmer omits the permissions on the draft versions. The solution is to create your own security trimmer and register it for the corresponding crawl rule. If you follow the example in the msdn documentation you only need to add this line to determine if the current user has access to the item listed in the search for each crawlURL:

bool hasPermission = item.DoesUserHavePermissions(web.AllUsers[strUser], SPBasePermissions.ViewListItems);

From the crawl url you can get the GUIDs and ID item required to get an SPListItem (item in the code above).

Enjoy it!


Anonymous said...

I was going to put the same in my blog!!!

Pranabandhu said...

Share point is a set of product and technology which is used for creating sites easily.

Bradley Chetty said...

Hos do you get Guid and ID of the lkist from the crawlURLs

Àlex said...

What url are appearing in the search logs?

Anonymous said...

It is very interesting for me to read this blog. Thanx for it. I like such themes and anything that is connected to them. I would like to read more soon.

Anonymous said...

It is certainly interesting for me to read this post. Thank author for it. I like such themes and anything that is connected to this matter. I would like to read more soon.

Online Visitors