So am I right in thinking that it is smart enough to look at the user that is logged in, determine which roles they have and only return content that they have persmission to view?
As far as I am aware no. However what you can do is implement GatheringNodeData event and inject into a field (e.g field called GroupAccess) member groups that are allowed to view that content. Then as part of your search filter you can apply that currently logged in users group membership and filter on that. That way you can only show those results he/she has access to. For non protected content you will need to put in some value (e.g public in to GroupAccess field) and use that as part of query.
In umbraco.library there are some methods you can use eg
umbraco.library.IsProtected(10,path);
umbraco.library.AllowedGroups(10,path)
Replace 10 with actual id of node this you can get in gatheringnode node data from the IndexingNodeDataEventArgs e object. The path is either from node or document object you will need to instantiate one or the other and that has path property.
Yes you have to set supportProtected to true so that the content is in the index. Also as part of the indexing process inject in the allowed groups for that content then you can use examine to filter those results. So as you build your query get the logged in user and the group he/she belongs to then include that as part of filter i.e query.And().Fields("groups",currentMemberGroup)
You implement gatheringnodedata event and use the two methods
umbraco.library.IsProtected(10,path);
umbraco.library.AllowedGroups(10,path)
If current document you are indexing is protected then get the allowed groups and inject those in. See here for some sample gatheringnode data code it does not have member stuff but you can use and put the member stuff in.
My Examine adventures continue! I'm trying to implement this exact idea. However, I've run into a problem. When I call umbraco.library.IsProtected in my GatheringNodeData method, I get an exception:
Value cannot be null. Parameter name: umbracoContext
So it looks like you need an umbraco context which doesn't exist when my GatheringNodeData runs. Any ideas on how to get around this? Am I missing something? My code is basic:
private void indexer_GatheringNodeData(object sender, IndexingNodeDataEventArgs e) { //Log.Add(LogTypes.Debug, 1, String.Format("Gathering Node Data: {0}", e.Fields["nodeName"])); var n = new Node(e.NodeId); if (umbraco.library.IsProtected(n.Id, n.Path))// EXCEPTION THROWN HERE! { var groups = umbraco.library.AllowedGroups(n.Id, n.Path); } }
Examine Indexer setting - supportProtected
When configuring an Examine Indexer you can set the value of the supportProtected attribute.
The only documentation I can find about this setting is:
"Set to true if you want protected content indexed"
From this I'm assuming that it is referring to content that has been protected by membership restrictions.
Is that right?
Regards,
Matt
Matt,
It is. Out of the box protected content will not be indexed.
Regards
Ismail
Thanks Ismail,
So am I right in thinking that it is smart enough to look at the user that is logged in, determine which roles they have and only return content that they have persmission to view?
Cheers,
Matt
Matt,
As far as I am aware no. However what you can do is implement GatheringNodeData event and inject into a field (e.g field called GroupAccess) member groups that are allowed to view that content. Then as part of your search filter you can apply that currently logged in users group membership and filter on that. That way you can only show those results he/she has access to. For non protected content you will need to put in some value (e.g public in to GroupAccess field) and use that as part of query.
Regards
Ismail
Ismail do you have a coded example of how to implement the GatheringNodeDate event to inject the member groups in to the index?
Mike,
In umbraco.library there are some methods you can use eg
umbraco.library.IsProtected(10,path);
umbraco.library.AllowedGroups(10,path)
Replace 10 with actual id of node this you can get in gatheringnode node data from the IndexingNodeDataEventArgs e object. The path is either from node or document object you will need to instantiate one or the other and that has path property.
Regards
Ismail
So you mean set the extenal indexer to supportProtected="true" and then filter the result set from examine.. result by result.
Thought you were injecting into the actually examine index so you could query it at the index level to exclude results I shouldn't see.
Mike,
Yes you have to set supportProtected to true so that the content is in the index. Also as part of the indexing process inject in the allowed groups for that content then you can use examine to filter those results. So as you build your query get the logged in user and the group he/she belongs to then include that as part of filter i.e query.And().Fields("groups",currentMemberGroup)
Regards
Ismail
so the bit I am missing... is how do i add the "groups" field to the default externalindex that ships with 4.11.5???
You implement gatheringnodedata event and use the two methods
umbraco.library.IsProtected(10,path);
umbraco.library.AllowedGroups(10,path)
If current document you are indexing is protected then get the allowed groups and inject those in. See here for some sample gatheringnode data code it does not have member stuff but you can use and put the member stuff in.
Regards
Ismail
Hi Ismail,
My Examine adventures continue! I'm trying to implement this exact idea. However, I've run into a problem. When I call umbraco.library.IsProtected in my GatheringNodeData method, I get an exception:
So it looks like you need an umbraco context which doesn't exist when my GatheringNodeData runs. Any ideas on how to get around this? Am I missing something? My code is basic:
Cheers!
David
I found this post: Umbraco Examine protected pages which says to use
instead. You'll need to ensure you have a reference to cms.dll in your project.
David,
Awesome. Totally forgot about that one.
Regards
Ismail
is working on a reply...