{"action":"created","comment":{"url":"https://api.github.com/repos/coveo/source.coveo.com/pulls/comments/91615703","pull_request_review_id":12124391,"id":91615703,"diff_hunk":"@@ -0,0 +1,166 @@\n+---\n+layout: post\n+\n+title: \"Creating Previews of Your Secured Sitecore Content\"\n+\n+tags: [Sitecore, Secured Content, Coveo for Sitecore]\n+\n+author:\n+  name: Laurent Mandrile\n+  bio: Intern, Coveo for Sitecore\n+  image: lmandrile.jpg\n+---\n+\n+You may have secured items in your content tree that you would like to present to anonymous users without the items' content being revealed. The following blogpost introduces a method that will allow you to do just that. Stripped down values of secured items are created at indexing time and are made searchable by anonymous users while being filtered out at query time for connected users, who will see the secured content as usual. The `ItemLimitedViewProcessor` described below will give you a way of implementing this.\n+\n+<!-- more -->\n+\n+#ItemLimitedViewProcessor\n+\n+This feat is accomplished by creating a copy of items as they go through the Coveo pipelines and running them through our custom processor before they are indexed. The processor strips the content and access rules of these copies while still linking to the original page. This way, if you redirect an anonymous user trying to access secure content to a login page, he will be redirected to the same login page when clicking on the new hollow item. You may also specify a preview field for an item that will be used as a Quick View, hide fields that you wouldn't want an anonymous user to access and inject the original secured content in a hidden field so it may still be relevant.\n+\n+To achieve the same relevancy as the original items, the content of the item’s body is added to a new field (in our case, `HiddenContent`) which is free-text searchable, but not displayed.\n+\n+Two fields are created in Sitecore items that will be used by the processor. The first to indicate the item has to be stripped, and the second potentially containing a preview text to show anonymous users. (In our case, Sitecore fields whose ID's are referenced in the `LimitedAccessFieldId` and `PreviewFieldId` fields described below)\n+\n+##Code\n+The processor added to the `CoveoItemPostProcessingPipeline` does a shallow copy of an item if it finds it marked for copying. It also adds two fields to the new item: `IsLimitedAccessDocument`, a field marking an item as a stripped down duplicate, and `HiddenContent`, a hidden field containing the original item’s body. Furthermore, a new `Unique ID` must be created for the item and its copy to be considered two different elements.\n+\n+{% highlight c# %}\n+[...]\n+public void Process(CoveoPostItemProcessingPipelineArgs p_Args)\n+{\n+    s_Logger.TraceEntering();\n+\n+    Precondition.NotNull(p_Args, () => () => p_Args);\n+\n+    ID limitedAccessFieldId = new ID(LimitedAccessFieldId);\n+    ID fieldToHideId = new ID(FieldToHideId);\n+    ID previewFieldId = new ID(PreviewFieldId);\n+\n+    CoveoIndexableItem coveoIndexableItem = p_Args.CoveoItem;\n+    SitecoreIndexableItem sitecoreIndexableItem = p_Args.Item as SitecoreIndexableItem;\n+    if (coveoIndexableItem != null &&\n+        sitecoreIndexableItem != null &&\n+        !sitecoreIndexableItem.Item.Paths.IsMediaItem &&\n+        sitecoreIndexableItem.Item[limitedAccessFieldId] == LIMITED_ACCESS_VALUE) {\n+\n+        // Check if a preview text has been specified.\n+        IIndexableDataField previewField = sitecoreIndexableItem.Fields.FirstOrDefault(arg => (ID) arg.Id == previewFieldId);\n+        byte[] encodedPreview = null;\n+        if (previewField != null) {\n+            string previewText = previewField.Value.ToString();\n+            if (!String.IsNullOrEmpty(previewText)) {\n+                encodedPreview = Encoding.UTF8.GetBytes(previewText);\n+            }\n+        }\n+\n+        // Duplicates metadata.\n+        Dictionary<string, object> newMetadata = new Dictionary<string, object>(coveoIndexableItem.Metadata) {\n+            { LIMITED_ACCESS_METADATA_FIELDNAME, true }\n+        };\n+\n+        // Add a hidden field containing the original binary data for relevance\n+        if (coveoIndexableItem.BinaryData != null) {\n+            newMetadata.Add(HIDDEN_CONTENT_METADATA_FIELDNAME, Encoding.UTF8.GetString(coveoIndexableItem.BinaryData));\n+        }\n+\n+        if (!String.IsNullOrEmpty(FieldToHideId)) {\n+            IIndexableDataField fieldToHide = sitecoreIndexableItem.Fields.FirstOrDefault(arg => (ID) arg.Id == fieldToHideId);\n+            if (fieldToHide != null) {\n+                newMetadata.Remove(fieldToHide.Name);\n+            }\n+        }\n+\n+        string newUniqueId = coveoIndexableItem.UniqueId + LIMITED_ACCESS_ITEM_SUFFIX;\n+\n+        CoveoIndexableItem strippedItem = new CoveoIndexableItem {\n+            // Custom fields.\n+            // Replace the data with the preview text. This way, the preview will be used for the new item's quickview.\n+            BinaryData = encodedPreview,\n+            UniqueId = newUniqueId,\n+            Metadata = newMetadata,\n+            // Fields that are inherited from the parent item.\n+            BinaryDataMimeType = coveoIndexableItem.BinaryDataMimeType,\n+            BinaryDataPath = coveoIndexableItem.BinaryDataPath,\n+            ClickableUri = coveoIndexableItem.ClickableUri,\n+            FileName = coveoIndexableItem.FileName,\n+            HasSubItems = coveoIndexableItem.HasSubItems,\n+            Id = coveoIndexableItem.Id,\n+            IsDeletedItem = coveoIndexableItem.IsDeletedItem,\n+            ModifiedDate = coveoIndexableItem.ModifiedDate,\n+            Parent = coveoIndexableItem.Parent,\n+            ParentId = coveoIndexableItem.ParentId,\n+            Path = coveoIndexableItem.Path,\n+            Permissions = CreateAnonymousAccessRule(),\n+            PrintablePath = coveoIndexableItem.PrintablePath,\n+            Title = coveoIndexableItem.Title\n+        };\n+        p_Args.OutputCoveoItems.Add(strippedItem);\n+    }\n+    s_Logger.TraceExiting();\n+}\n+{% endhighlight %}\n+\n+##Configurations\n+\n+The next step is patching the Coveo configuration files in your Sitecore repository. To do this, you may either create a new .config file (as long as it's loaded after 'Coveo.SearchProvider.Custom.Config') or patch the `Coveo.SearchProvider.Custom.Config` directly.","path":"_posts/2016-12-1-creating-previews-of-secured-content-in-sitecore.md","position":107,"original_position":107,"commit_id":"a6c7b663b4af91503121a252c3d56870d4729035","original_commit_id":"a6c7b663b4af91503121a252c3d56870d4729035","user":{"login":"amoreauCoveo","id":21081141,"avatar_url":"https://avatars.githubusercontent.com/u/21081141?v=3","gravatar_id":"","url":"https://api.github.com/users/amoreauCoveo","html_url":"https://github.com/amoreauCoveo","followers_url":"https://api.github.com/users/amoreauCoveo/followers","following_url":"https://api.github.com/users/amoreauCoveo/following{/other_user}","gists_url":"https://api.github.com/users/amoreauCoveo/gists{/gist_id}","starred_url":"https://api.github.com/users/amoreauCoveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amoreauCoveo/subscriptions","organizations_url":"https://api.github.com/users/amoreauCoveo/orgs","repos_url":"https://api.github.com/users/amoreauCoveo/repos","events_url":"https://api.github.com/users/amoreauCoveo/events{/privacy}","received_events_url":"https://api.github.com/users/amoreauCoveo/received_events","type":"User","site_admin":false},"body":"I don't understand why you give the option. The recommended method is doing it through the Custom.config","created_at":"2016-12-08T21:55:24Z","updated_at":"2016-12-08T22:01:49Z","html_url":"https://github.com/coveo/source.coveo.com/pull/99#discussion_r91615703","pull_request_url":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99","_links":{"self":{"href":"https://api.github.com/repos/coveo/source.coveo.com/pulls/comments/91615703"},"html":{"href":"https://github.com/coveo/source.coveo.com/pull/99#discussion_r91615703"},"pull_request":{"href":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99"}}},"pull_request":{"url":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99","id":96595930,"html_url":"https://github.com/coveo/source.coveo.com/pull/99","diff_url":"https://github.com/coveo/source.coveo.com/pull/99.diff","patch_url":"https://github.com/coveo/source.coveo.com/pull/99.patch","issue_url":"https://api.github.com/repos/coveo/source.coveo.com/issues/99","number":99,"state":"open","locked":false,"title":"Sitecore Secured Item Previews Blog Post","user":{"login":"lmandrile","id":17532690,"avatar_url":"https://avatars.githubusercontent.com/u/17532690?v=3","gravatar_id":"","url":"https://api.github.com/users/lmandrile","html_url":"https://github.com/lmandrile","followers_url":"https://api.github.com/users/lmandrile/followers","following_url":"https://api.github.com/users/lmandrile/following{/other_user}","gists_url":"https://api.github.com/users/lmandrile/gists{/gist_id}","starred_url":"https://api.github.com/users/lmandrile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmandrile/subscriptions","organizations_url":"https://api.github.com/users/lmandrile/orgs","repos_url":"https://api.github.com/users/lmandrile/repos","events_url":"https://api.github.com/users/lmandrile/events{/privacy}","received_events_url":"https://api.github.com/users/lmandrile/received_events","type":"User","site_admin":false},"body":"","created_at":"2016-12-05T19:44:59Z","updated_at":"2016-12-08T22:01:49Z","closed_at":null,"merged_at":null,"merge_commit_sha":"5a2e4267eb4708064f55951c0545a9ef46b9be7c","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99/commits","review_comments_url":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99/comments","review_comment_url":"https://api.github.com/repos/coveo/source.coveo.com/pulls/comments{/number}","comments_url":"https://api.github.com/repos/coveo/source.coveo.com/issues/99/comments","statuses_url":"https://api.github.com/repos/coveo/source.coveo.com/statuses/a6c7b663b4af91503121a252c3d56870d4729035","head":{"label":"lmandrile:gh-pages","ref":"gh-pages","sha":"a6c7b663b4af91503121a252c3d56870d4729035","user":{"login":"lmandrile","id":17532690,"avatar_url":"https://avatars.githubusercontent.com/u/17532690?v=3","gravatar_id":"","url":"https://api.github.com/users/lmandrile","html_url":"https://github.com/lmandrile","followers_url":"https://api.github.com/users/lmandrile/followers","following_url":"https://api.github.com/users/lmandrile/following{/other_user}","gists_url":"https://api.github.com/users/lmandrile/gists{/gist_id}","starred_url":"https://api.github.com/users/lmandrile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmandrile/subscriptions","organizations_url":"https://api.github.com/users/lmandrile/orgs","repos_url":"https://api.github.com/users/lmandrile/repos","events_url":"https://api.github.com/users/lmandrile/events{/privacy}","received_events_url":"https://api.github.com/users/lmandrile/received_events","type":"User","site_admin":false},"repo":{"id":75326746,"name":"source.coveo.com","full_name":"lmandrile/source.coveo.com","owner":{"login":"lmandrile","id":17532690,"avatar_url":"https://avatars.githubusercontent.com/u/17532690?v=3","gravatar_id":"","url":"https://api.github.com/users/lmandrile","html_url":"https://github.com/lmandrile","followers_url":"https://api.github.com/users/lmandrile/followers","following_url":"https://api.github.com/users/lmandrile/following{/other_user}","gists_url":"https://api.github.com/users/lmandrile/gists{/gist_id}","starred_url":"https://api.github.com/users/lmandrile/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lmandrile/subscriptions","organizations_url":"https://api.github.com/users/lmandrile/orgs","repos_url":"https://api.github.com/users/lmandrile/repos","events_url":"https://api.github.com/users/lmandrile/events{/privacy}","received_events_url":"https://api.github.com/users/lmandrile/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/lmandrile/source.coveo.com","description":"Our technical blog.","fork":true,"url":"https://api.github.com/repos/lmandrile/source.coveo.com","forks_url":"https://api.github.com/repos/lmandrile/source.coveo.com/forks","keys_url":"https://api.github.com/repos/lmandrile/source.coveo.com/keys{/key_id}","collaborators_url":"https://api.github.com/repos/lmandrile/source.coveo.com/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/lmandrile/source.coveo.com/teams","hooks_url":"https://api.github.com/repos/lmandrile/source.coveo.com/hooks","issue_events_url":"https://api.github.com/repos/lmandrile/source.coveo.com/issues/events{/number}","events_url":"https://api.github.com/repos/lmandrile/source.coveo.com/events","assignees_url":"https://api.github.com/repos/lmandrile/source.coveo.com/assignees{/user}","branches_url":"https://api.github.com/repos/lmandrile/source.coveo.com/branches{/branch}","tags_url":"https://api.github.com/repos/lmandrile/source.coveo.com/tags","blobs_url":"https://api.github.com/repos/lmandrile/source.coveo.com/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/lmandrile/source.coveo.com/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/lmandrile/source.coveo.com/git/refs{/sha}","trees_url":"https://api.github.com/repos/lmandrile/source.coveo.com/git/trees{/sha}","statuses_url":"https://api.github.com/repos/lmandrile/source.coveo.com/statuses/{sha}","languages_url":"https://api.github.com/repos/lmandrile/source.coveo.com/languages","stargazers_url":"https://api.github.com/repos/lmandrile/source.coveo.com/stargazers","contributors_url":"https://api.github.com/repos/lmandrile/source.coveo.com/contributors","subscribers_url":"https://api.github.com/repos/lmandrile/source.coveo.com/subscribers","subscription_url":"https://api.github.com/repos/lmandrile/source.coveo.com/subscription","commits_url":"https://api.github.com/repos/lmandrile/source.coveo.com/commits{/sha}","git_commits_url":"https://api.github.com/repos/lmandrile/source.coveo.com/git/commits{/sha}","comments_url":"https://api.github.com/repos/lmandrile/source.coveo.com/comments{/number}","issue_comment_url":"https://api.github.com/repos/lmandrile/source.coveo.com/issues/comments{/number}","contents_url":"https://api.github.com/repos/lmandrile/source.coveo.com/contents/{+path}","compare_url":"https://api.github.com/repos/lmandrile/source.coveo.com/compare/{base}...{head}","merges_url":"https://api.github.com/repos/lmandrile/source.coveo.com/merges","archive_url":"https://api.github.com/repos/lmandrile/source.coveo.com/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/lmandrile/source.coveo.com/downloads","issues_url":"https://api.github.com/repos/lmandrile/source.coveo.com/issues{/number}","pulls_url":"https://api.github.com/repos/lmandrile/source.coveo.com/pulls{/number}","milestones_url":"https://api.github.com/repos/lmandrile/source.coveo.com/milestones{/number}","notifications_url":"https://api.github.com/repos/lmandrile/source.coveo.com/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/lmandrile/source.coveo.com/labels{/name}","releases_url":"https://api.github.com/repos/lmandrile/source.coveo.com/releases{/id}","deployments_url":"https://api.github.com/repos/lmandrile/source.coveo.com/deployments","created_at":"2016-12-01T19:45:31Z","updated_at":"2016-12-01T19:45:33Z","pushed_at":"2016-12-08T19:09:57Z","git_url":"git://github.com/lmandrile/source.coveo.com.git","ssh_url":"git@github.com:lmandrile/source.coveo.com.git","clone_url":"https://github.com/lmandrile/source.coveo.com.git","svn_url":"https://github.com/lmandrile/source.coveo.com","homepage":"source.coveo.com","size":25525,"stargazers_count":0,"watchers_count":0,"language":"CSS","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"gh-pages"}},"base":{"label":"coveo:gh-pages","ref":"gh-pages","sha":"4bfb47cb1e86759b71b59b80fb5f046d72c20feb","user":{"login":"coveo","id":8632328,"avatar_url":"https://avatars.githubusercontent.com/u/8632328?v=3","gravatar_id":"","url":"https://api.github.com/users/coveo","html_url":"https://github.com/coveo","followers_url":"https://api.github.com/users/coveo/followers","following_url":"https://api.github.com/users/coveo/following{/other_user}","gists_url":"https://api.github.com/users/coveo/gists{/gist_id}","starred_url":"https://api.github.com/users/coveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveo/subscriptions","organizations_url":"https://api.github.com/users/coveo/orgs","repos_url":"https://api.github.com/users/coveo/repos","events_url":"https://api.github.com/users/coveo/events{/privacy}","received_events_url":"https://api.github.com/users/coveo/received_events","type":"Organization","site_admin":false},"repo":{"id":23815317,"name":"source.coveo.com","full_name":"coveo/source.coveo.com","owner":{"login":"coveo","id":8632328,"avatar_url":"https://avatars.githubusercontent.com/u/8632328?v=3","gravatar_id":"","url":"https://api.github.com/users/coveo","html_url":"https://github.com/coveo","followers_url":"https://api.github.com/users/coveo/followers","following_url":"https://api.github.com/users/coveo/following{/other_user}","gists_url":"https://api.github.com/users/coveo/gists{/gist_id}","starred_url":"https://api.github.com/users/coveo/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coveo/subscriptions","organizations_url":"https://api.github.com/users/coveo/orgs","repos_url":"https://api.github.com/users/coveo/repos","events_url":"https://api.github.com/users/coveo/events{/privacy}","received_events_url":"https://api.github.com/users/coveo/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coveo/source.coveo.com","description":"Our technical blog.","fork":false,"url":"https://api.github.com/repos/coveo/source.coveo.com","forks_url":"https://api.github.com/repos/coveo/source.coveo.com/forks","keys_url":"https://api.github.com/repos/coveo/source.coveo.com/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coveo/source.coveo.com/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coveo/source.coveo.com/teams","hooks_url":"https://api.github.com/repos/coveo/source.coveo.com/hooks","issue_events_url":"https://api.github.com/repos/coveo/source.coveo.com/issues/events{/number}","events_url":"https://api.github.com/repos/coveo/source.coveo.com/events","assignees_url":"https://api.github.com/repos/coveo/source.coveo.com/assignees{/user}","branches_url":"https://api.github.com/repos/coveo/source.coveo.com/branches{/branch}","tags_url":"https://api.github.com/repos/coveo/source.coveo.com/tags","blobs_url":"https://api.github.com/repos/coveo/source.coveo.com/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coveo/source.coveo.com/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coveo/source.coveo.com/git/refs{/sha}","trees_url":"https://api.github.com/repos/coveo/source.coveo.com/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coveo/source.coveo.com/statuses/{sha}","languages_url":"https://api.github.com/repos/coveo/source.coveo.com/languages","stargazers_url":"https://api.github.com/repos/coveo/source.coveo.com/stargazers","contributors_url":"https://api.github.com/repos/coveo/source.coveo.com/contributors","subscribers_url":"https://api.github.com/repos/coveo/source.coveo.com/subscribers","subscription_url":"https://api.github.com/repos/coveo/source.coveo.com/subscription","commits_url":"https://api.github.com/repos/coveo/source.coveo.com/commits{/sha}","git_commits_url":"https://api.github.com/repos/coveo/source.coveo.com/git/commits{/sha}","comments_url":"https://api.github.com/repos/coveo/source.coveo.com/comments{/number}","issue_comment_url":"https://api.github.com/repos/coveo/source.coveo.com/issues/comments{/number}","contents_url":"https://api.github.com/repos/coveo/source.coveo.com/contents/{+path}","compare_url":"https://api.github.com/repos/coveo/source.coveo.com/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coveo/source.coveo.com/merges","archive_url":"https://api.github.com/repos/coveo/source.coveo.com/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coveo/source.coveo.com/downloads","issues_url":"https://api.github.com/repos/coveo/source.coveo.com/issues{/number}","pulls_url":"https://api.github.com/repos/coveo/source.coveo.com/pulls{/number}","milestones_url":"https://api.github.com/repos/coveo/source.coveo.com/milestones{/number}","notifications_url":"https://api.github.com/repos/coveo/source.coveo.com/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coveo/source.coveo.com/labels{/name}","releases_url":"https://api.github.com/repos/coveo/source.coveo.com/releases{/id}","deployments_url":"https://api.github.com/repos/coveo/source.coveo.com/deployments","created_at":"2014-09-09T01:43:19Z","updated_at":"2016-11-19T01:09:53Z","pushed_at":"2016-12-08T19:09:57Z","git_url":"git://github.com/coveo/source.coveo.com.git","ssh_url":"git@github.com:coveo/source.coveo.com.git","clone_url":"https://github.com/coveo/source.coveo.com.git","svn_url":"https://github.com/coveo/source.coveo.com","homepage":"source.coveo.com","size":28574,"stargazers_count":7,"watchers_count":7,"language":"CSS","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":true,"forks_count":40,"mirror_url":null,"open_issues_count":4,"forks":40,"open_issues":4,"watchers":7,"default_branch":"gh-pages"}},"_links":{"self":{"href":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99"},"html":{"href":"https://github.com/coveo/source.coveo.com/pull/99"},"issue":{"href":"https://api.github.com/repos/coveo/source.coveo.com/issues/99"},"comments":{"href":"https://api.github.com/repos/coveo/source.coveo.com/issues/99/comments"},"review_comments":{"href":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99/comments"},"review_comment":{"href":"https://api.github.com/repos/coveo/source.coveo.com/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/coveo/source.coveo.com/pulls/99/commits"},"statuses":{"href":"https://api.github.com/repos/coveo/source.coveo.com/statuses/a6c7b663b4af91503121a252c3d56870d4729035"}}}}
{"actor":{"display_login":"amoreauCoveo"}}