Skip to content

Commit 9602e0a

Browse files
authored
redirect to external privacy link (#9347)
* Redirect privacy to external Microsoft privacy
1 parent 83f98b7 commit 9602e0a

4 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/NuGetGallery/Controllers/PagesController.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,11 @@ public virtual async Task<ActionResult> Terms()
152152
[HttpGet]
153153
public virtual async Task<ActionResult> Privacy()
154154
{
155+
if (!String.IsNullOrEmpty(Url.ExternalPrivacyUrl()))
156+
{
157+
return Redirect(Url.ExternalPrivacyUrl());
158+
}
159+
155160
if (_contentService != null)
156161
{
157162
ViewBag.Content = await _contentService.GetContentItemAsync(

src/NuGetGallery/UrlHelperExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1412,6 +1412,11 @@ public static string Privacy(this UrlHelper url, bool relativeUrl = true)
14121412
return GetActionLink(url, "Privacy", "Pages", relativeUrl);
14131413
}
14141414

1415+
public static string ExternalPrivacyUrl(this UrlHelper url)
1416+
{
1417+
return _configuration.Current.ExternalPrivacyPolicyUrl;
1418+
}
1419+
14151420
public static string About(this UrlHelper url, bool relativeUrl = true)
14161421
{
14171422
if (!String.IsNullOrEmpty(_configuration.Current.ExternalAboutUrl))

tests/NuGetGallery.Facts/Controllers/PagesControllerFacts.cs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

4+
using System;
45
using System.Threading.Tasks;
56
using System.Web;
67
using Moq;
78
using NuGet.Services.Entities;
89
using NuGet.Services.Messaging.Email;
910
using NuGetGallery.Areas.Admin;
11+
using NuGetGallery.Configuration;
1012
using NuGetGallery.Framework;
1113
using NuGetGallery.Infrastructure.Mail.Messages;
1214
using NuGetGallery.ViewModels;
@@ -88,6 +90,41 @@ public async Task HtmlEncodesTheSupportRequest()
8890
It.IsAny<User>(),
8991
It.IsAny<Package>()));
9092
}
93+
94+
[Fact]
95+
public async Task WithExternalPrivacyUrlConfigured()
96+
{
97+
var externalPrivacyUrl = "https://privacy.microsoft.com";
98+
var configuration = GetConfigurationService();
99+
var pagesController = GetController<PagesController>();
100+
101+
configuration.Current.ExternalPrivacyPolicyUrl = externalPrivacyUrl;
102+
103+
var result = await pagesController.Privacy();
104+
105+
GetMock<IContentService>()
106+
.Verify(m => m.GetContentItemAsync(
107+
It.IsAny<string>(),
108+
It.IsAny<TimeSpan>()), Times.Never);
109+
110+
}
111+
112+
[Fact]
113+
public async Task WithoutExternalPrivacyUrlConfigured()
114+
{
115+
var externalPrivacyUrl = "";
116+
var configuration = GetConfigurationService();
117+
var pagesController = GetController<PagesController>();
118+
119+
configuration.Current.ExternalPrivacyPolicyUrl = externalPrivacyUrl;
120+
121+
var result = await pagesController.Privacy();
122+
123+
GetMock<IContentService>()
124+
.Verify(m => m.GetContentItemAsync(
125+
It.IsAny<string>(),
126+
It.IsAny<TimeSpan>()), Times.Once);
127+
}
91128
}
92129
}
93130
}

tests/NuGetGallery.Facts/UrlHelperExtensionsFacts.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,23 @@ public void UsesConfiguredSiteRootInAbsoluteUri(
276276
}
277277
}
278278

279+
public class GetExternalPrivacyUrlMethod : TestContainer
280+
{
281+
[Theory]
282+
[InlineData("")]
283+
[InlineData("https://privacy.microsoft.com")]
284+
public void VerifyExternalPrivacyUrlMethod(string expectedUrl) {
285+
var configurationService = GetConfigurationService();
286+
configurationService.Current.ExternalPrivacyPolicyUrl = expectedUrl;
287+
288+
var urlHelper = TestUtility.MockUrlHelper(expectedUrl);
289+
290+
var result = UrlHelperExtensions.ExternalPrivacyUrl(TestUtility.MockUrlHelper());
291+
292+
Assert.Equal(expectedUrl, result);
293+
}
294+
}
295+
279296
public class TheGetActionLinkMethod : TestContainer
280297
{
281298
public static IEnumerable<object[]> GeneratesTheCorrectActionLink_Data

0 commit comments

Comments
 (0)