Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Wayne 15 posts 72 karma points
    Jan 09, 2013 @ 08:08
    Wayne
    0

    Include role based protection data in Examine indexes

    I need to ensure Examine searches only include protected content that the current user has access to.

    So, this is possible two questions in one, how do you compile a search criteria using ExamineManager which is the equivalent of 

    .Where<DynamicNode>("Visible && ( !IsProtected || HasAccess )"))

    so far I only filter Visible using umbracoNaviHide like so;

    ExamineManager.Instance.Search(criteria.GroupedOr(new string[] {"nodeName", "bodyText"}, searchTerm).Not().Field("umbracoNaviHide", "1").Compile());

    and

    how would you get the public access data for protected nodes using IndexAttributeFields or IndexUserFields in ExamineIndex.config ?

    thanks in advance.

    W

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Jan 29, 2013 @ 23:40
    Peter Gregory
    0

    Hi Wayne

    I think you could do this one of 2 ways.  Either index everything and then on search result display check each result to see if the user has access to view and if they dont, leave it out of of the display.  However paging these results could be problematic.

    The way I would address it would be to do the following...  Please note this is entirely off the top of my head and I am not 100% sure it would work exactly as typeed but give it a go and let me know.

    The option would be to "stuff" the index with some of the public access information also, indexing which groups have access to your results.  To do this you need to look at the GatheringNodeData event.

     

    ExamineManager.Instance.IndexProviderCollection["YourIndexer"].GatheringNodeData += ExamineIndexingGatheringNodeData;

     

    Then in the event handler you want to use the Access class which has a method called GetAccessingMemberRoles

     

            private void ExamineIndexingGatheringNodeData(object sender, IndexingNodeDataEventArgs e)
           {
               if (e.IndexType != IndexTypes.Content) return;
                var n = e.Node;

               //index it

               var nodeId = Int32.Parse(e.Node.Attribute("id").Value);
    var nodePath = e.Node.Attribute("path").Value;

    //return a string array of the role
    var accessRoles = umbraco.cms.businesslogic.web.Access.GetaccessingMembershipRoles(nodeId, nodePath);

               e.Fields.Add("accessInfo", String.Join(",",accessInfo));
           }

    Then you should be able to access that info from your index and determine if it fits your access criteria.

    Hope this at least give you some clues.

  • Peter Gregory 408 posts 1614 karma points MVP 3x admin c-trib
    Jan 30, 2013 @ 00:17
    Peter Gregory
    0

    Just a thought if you cant get the path the way I have it here...  you might just need to load the node from umbraco.NodeFactory and then just get the Path property.

    Peter

Please Sign in or register to post replies

Write your reply to:

Draft