Skip to content

Commit 7fc9436

Browse files
committed
Merge branch 'feature/Sitemap-IsPrivateBranch' into develop
The new `IsPrivateBranch` attribute allows entire branches of the topic tree to be excluded from the `SitemapController`. As the name suggests, this is intended for private branches that aren't otherwise crawlable by search engines, and thus should be excluded in order to avoid crawling errors and, potentially, exposure of private information. This can be used, for instance, for `Configuration` (which is internal infrastructure) and `Administration` (which is exposed as a web page, but requires authorization). This is intended as a replacement for the recursive `NoIndex`, which excludes an entire branch if applied to `Container`, but only the current topic if applied to any other content type; this inconsistency is confusing, and the name is unintuitive. The name `IsPrivateBranch` is much more explicit about the scope and intent, and will better distinguish it from the `NoIndex` attribute on `Page`, which will continue to be used to request that publicly available pages not be indexed by either search engines (via the `noindex` metatag) or the `SitemapController`. This resolves #72.
2 parents 9b710d2 + e4a90a0 commit 7fc9436

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

OnTopic.AspNetCore.Mvc.Tests/TestDoubles/TestTopicRepository.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ private static Topic CreateFakeData() {
6868
_ = new Topic("NoIndexChild", "Page", noIndexPage);
6969
var noIndexContainer = new Topic("NoIndexContainer", "Container", webTopic);
7070
_ = new Topic("NoIndexContainerChild", "Page", noIndexContainer);
71+
var privateBranch = new Topic("PrivateBranch", "Page", webTopic);
72+
_ = new Topic("PrivateBranchChild", "Page", privateBranch);
7173
var disabledPage = new Topic("Disabled", "Page", webTopic);
7274
var pageGroup = new Topic("PageGroup", "PageGroup", rootTopic);
7375
_ = new Topic("PageGroupChild", "Page", pageGroup);
@@ -97,6 +99,7 @@ private static Topic CreateFakeData() {
9799

98100
//Excluded descendants
99101
noIndexContainer.Attributes.SetBoolean("NoIndex", true);
102+
privateBranch.Attributes.SetBoolean("IsPrivateBranch", true);
100103

101104
/*------------------------------------------------------------------------------------------------------------------------
102105
| Return data

OnTopic.AspNetCore.Mvc.Tests/TopicControllerTest.cs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -207,11 +207,11 @@ public void SitemapController_Index_ExcludesContentTypes() {
207207
[Fact]
208208
public void SitemapController_Index_ExcludesContainerDescendants() {
209209

210-
var controller = new SitemapController(_topicRepository) {
211-
ControllerContext = new(_context)
210+
var controller = new SitemapController(_topicRepository) {
211+
ControllerContext = new(_context)
212212
};
213-
var result = controller.Extended(true) as ContentResult;
214-
var model = result?.Content as string;
213+
var result = controller.Extended(true) as ContentResult;
214+
var model = result?.Content as string;
215215

216216
controller.Dispose();
217217

@@ -221,6 +221,29 @@ public void SitemapController_Index_ExcludesContainerDescendants() {
221221

222222
}
223223

224+
/*==========================================================================================================================
225+
| TEST: SITEMAP CONTROLLER: INDEX: EXCLUDES PRIVATE BRANCHES
226+
\-------------------------------------------------------------------------------------------------------------------------*/
227+
/// <summary>
228+
/// Triggers the index action of the <see cref="SitemapController.Index(Boolean, Boolean)" /> action and verifies that it
229+
/// properly excludes the topics that are marked as <c>IsPrivateBranch</c>, including their descendants.
230+
/// </summary>
231+
[Fact]
232+
public void SitemapController_Index_ExcludesPrivateBranches() {
233+
234+
var controller = new SitemapController(_topicRepository) {
235+
ControllerContext = new(_context)
236+
};
237+
var result = controller.Extended(true) as ContentResult;
238+
var model = result?.Content as string;
239+
240+
controller.Dispose();
241+
242+
Assert.NotNull(model);
243+
Assert.False(model!.Contains("PrivateBranch/</loc>", StringComparison.Ordinal));
244+
Assert.False(model!.Contains("PrivateBranchChild/</loc>", StringComparison.Ordinal));
245+
246+
}
224247

225248
/*==========================================================================================================================
226249
| TEST: SITEMAP CONTROLLER: EXTENDED: INCLUDES ATTRIBUTES

OnTopic.AspNetCore.Mvc/Controllers/SitemapController.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ private IEnumerable<XElement> AddTopic(Topic topic, bool includeMetadata = false
198198
| Validate topic
199199
\-----------------------------------------------------------------------------------------------------------------------*/
200200
if (
201+
topic.Attributes.GetBoolean("IsPrivateBranch") ||
201202
topic.ContentType.Equals("Container", StringComparison.OrdinalIgnoreCase) &&
202203
topic.Attributes.GetBoolean("NoIndex")
203204
) return topics;

0 commit comments

Comments
 (0)