Skip to content

Commit 387363d

Browse files
authored
Fix Support link (#9276)
* fix broken support link
1 parent 0e42bd0 commit 387363d

21 files changed

Lines changed: 225 additions & 93 deletions

src/AccountDeleter/Configuration/GalleryConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,5 +115,6 @@ public string SiteRoot
115115
public int? MaxIoThreads { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
116116
public string InternalMicrosoftTenantKey { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
117117
public string AdminSenderUser { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
118+
public string SupportEmailSiteRoot { get => throw new NotImplementedException(); set => throw new NotImplementedException(); }
118119
}
119120
}

src/AccountDeleter/Providers/AccountDeleteUrlHelper.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ namespace NuGetGallery.AccountDeleter
77
{
88
public class AccountDeleteUrlHelper : IUrlHelper
99
{
10-
public string ConfirmPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl)
10+
public string ConfirmPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl, bool supportEmail)
1111
{
1212
throw new NotImplementedException();
1313
}
@@ -17,12 +17,12 @@ public string ManagePackageOwnership(string id, bool relativeUrl)
1717
throw new NotImplementedException();
1818
}
1919

20-
public string Package(string id, string version, bool relativeUrl)
20+
public string Package(string id, string version, bool relativeUrl, bool supportEmail)
2121
{
2222
throw new NotImplementedException();
2323
}
2424

25-
public string RejectPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl)
25+
public string RejectPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl, bool supportEmail)
2626
{
2727
throw new NotImplementedException();
2828
}

src/GalleryTools/App.config

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
<!-- Used for testing locally. -->
2727
<add key="Gallery.SiteRoot" value="http://localhost"/>
28+
<add key="Gallery.SupportEmailSiteRoot" value="http://localhost"/>
2829
<add key="Gallery.FileStorageDirectory" value="..\..\..\NuGetGallery\App_Data\Files"/>
2930
<add key="Gallery.LuceneIndexLocation" value="Temp"/>
3031
<add key="Gallery.IsHosted" value="false"/>

src/NuGetGallery.Services/Configuration/AppConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,11 @@ public class AppConfiguration : IAppConfiguration
210210
/// </summary>
211211
public string SiteRoot { get; set; }
212212

213+
/// <summary>
214+
/// Gets the protocol-independent support email site root
215+
/// </summary>
216+
public string SupportEmailSiteRoot { get; set; }
217+
213218
/// <summary>
214219
/// Private key for verifying recaptcha user response.
215220
/// </summary>

src/NuGetGallery.Services/Configuration/ConfigurationService.cs

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ public class ConfigurationService : IGalleryConfigurationService, IConfiguration
2626

2727
private readonly Lazy<string> _httpSiteRootThunk;
2828
private readonly Lazy<string> _httpsSiteRootThunk;
29+
private readonly Lazy<string> _httpsEmailSupportSiteRootThunk;
2930
private readonly Lazy<IAppConfiguration> _lazyAppConfiguration;
3031
private readonly Lazy<FeatureConfiguration> _lazyFeatureConfiguration;
3132
private readonly Lazy<IServiceBusConfiguration> _lazyServiceBusConfiguration;
@@ -59,6 +60,7 @@ public ConfigurationService()
5960
{
6061
_httpSiteRootThunk = new Lazy<string>(GetHttpSiteRoot);
6162
_httpsSiteRootThunk = new Lazy<string>(GetHttpsSiteRoot);
63+
_httpsEmailSupportSiteRootThunk = new Lazy<string>(GetHttpsSupportEmailSiteRoot);
6264

6365
_lazyAppConfiguration = new Lazy<IAppConfiguration>(() => ResolveSettings().Result);
6466
_lazyFeatureConfiguration = new Lazy<FeatureConfiguration>(() => ResolveFeatures().Result);
@@ -89,6 +91,15 @@ public string GetSiteRoot(bool useHttps)
8991
return useHttps ? _httpsSiteRootThunk.Value : _httpSiteRootThunk.Value;
9092
}
9193

94+
/// <summary>
95+
/// Gets the support email site root using the specified protocol
96+
/// </summary>
97+
/// <returns></returns>
98+
public string GetSupportEmailSiteRoot()
99+
{
100+
return _httpsEmailSupportSiteRootThunk.Value;
101+
}
102+
92103
public Task<T> Get<T>() where T : NuGet.Services.Configuration.Configuration, new()
93104
{
94105
// Get the prefix specified by the ConfigurationKeyPrefixAttribute on the class if it exists.
@@ -209,19 +220,7 @@ private string GetHttpSiteRoot()
209220
{
210221
var siteRoot = Current.SiteRoot;
211222

212-
if (siteRoot == null)
213-
{
214-
// No SiteRoot configured in settings.
215-
// Fallback to detected site root.
216-
var request = GetCurrentRequest();
217-
siteRoot = request.Url.GetLeftPart(UriPartial.Authority) + '/';
218-
}
219-
220-
if (!siteRoot.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
221-
&& !siteRoot.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
222-
{
223-
throw new InvalidOperationException("The configured site root must start with either http:// or https://.");
224-
}
223+
CheckValidSiteRoot(siteRoot);
225224

226225
if (siteRoot.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
227226
{
@@ -242,5 +241,36 @@ private string GetHttpsSiteRoot()
242241

243242
return "https://" + siteRoot.Substring(7);
244243
}
244+
245+
private string GetHttpsSupportEmailSiteRoot()
246+
{
247+
var siteRoot = Current.SupportEmailSiteRoot;
248+
249+
CheckValidSiteRoot(siteRoot);
250+
251+
if (siteRoot.StartsWith("http://", StringComparison.OrdinalIgnoreCase))
252+
{
253+
siteRoot = "https://" + siteRoot.Substring(7);
254+
}
255+
256+
return siteRoot;
257+
}
258+
259+
private void CheckValidSiteRoot(string siteRoot)
260+
{
261+
if (siteRoot == null)
262+
{
263+
// No SiteRoot configured in settings.
264+
// Fallback to detected site root.
265+
var request = GetCurrentRequest();
266+
siteRoot = request.Url.GetLeftPart(UriPartial.Authority) + '/';
267+
}
268+
269+
if (!siteRoot.StartsWith("http://", StringComparison.OrdinalIgnoreCase)
270+
&& !siteRoot.StartsWith("https://", StringComparison.OrdinalIgnoreCase))
271+
{
272+
throw new InvalidOperationException("The configured site root must start with either http:// or https://.");
273+
}
274+
}
245275
}
246276
}

src/NuGetGallery.Services/Configuration/IAppConfiguration.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,11 @@ public interface IAppConfiguration : IMessageServiceConfiguration
231231
/// </summary>
232232
string SiteRoot { get; set; }
233233

234+
/// <summary>
235+
/// Gets the protocol-independent support email site root
236+
/// </summary>
237+
string SupportEmailSiteRoot { get; set; }
238+
234239
/// <summary>
235240
/// Private key for verifying recaptcha user response.
236241
/// </summary>

src/NuGetGallery.Services/Configuration/IGalleryConfigurationService.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ public interface IGalleryConfigurationService
1717
/// <param name="useHttps">If true, the root will be returned in HTTPS form, otherwise, HTTP.</param>
1818
string GetSiteRoot(bool useHttps);
1919

20+
/// <summary>
21+
/// Gets the support email site root using the specified protocol
22+
/// </summary>
23+
string GetSupportEmailSiteRoot();
24+
2025
/// <summary>
2126
/// Populate the properties of <param name="instance"></param> from configuration.
2227
/// </summary>

src/NuGetGallery.Services/PackageManagement/PackageOwnershipManagementService.cs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public async Task AddPackageOwnerWithMessagesAsync(PackageRegistration packageRe
4949
{
5050
await AddPackageOwnerAsync(packageRegistration, user, commitChanges: true);
5151

52-
var packageUrl = _urlHelper.Package(packageRegistration.Id, version: null, relativeUrl: false);
52+
var packageUrl = _urlHelper.Package(packageRegistration.Id, version: null, relativeUrl: false, supportEmail: true);
5353

5454
// Accumulate the tasks so that they are sent in parallel and as many messages as possible are sent even if
5555
// one fails (i.e. throws an exception).
@@ -155,7 +155,7 @@ public async Task<PackageOwnerRequest> AddPackageOwnershipRequestWithMessagesAsy
155155

156156
var encodedMessage = HttpUtility.HtmlEncode(message ?? string.Empty);
157157

158-
var packageUrl = _urlHelper.Package(packageRegistration.Id, version: null, relativeUrl: false);
158+
var packageUrl = _urlHelper.Package(packageRegistration.Id, version: null, relativeUrl: false, supportEmail: true);
159159

160160
var ownerRequest = await AddPackageOwnershipRequestAsync(
161161
packageRegistration, requestingOwner, newOwner);
@@ -164,13 +164,15 @@ public async Task<PackageOwnerRequest> AddPackageOwnershipRequestWithMessagesAsy
164164
packageRegistration.Id,
165165
newOwner.Username,
166166
ownerRequest.ConfirmationCode,
167-
relativeUrl: false);
167+
relativeUrl: false,
168+
supportEmail: true);
168169

169170
var rejectionUrl = _urlHelper.RejectPendingOwnershipRequest(
170171
packageRegistration.Id,
171172
newOwner.Username,
172173
ownerRequest.ConfirmationCode,
173-
relativeUrl: false);
174+
relativeUrl: false,
175+
supportEmail: true);
174176

175177
var manageUrl = _urlHelper.ManagePackageOwnership(
176178
packageRegistration.Id,

src/NuGetGallery.Services/Providers/IUrlHelper.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public interface IUrlHelper
1717
/// <param name="id">The package ID to link to.</param>
1818
/// <param name="version">The specific package version to link to. Can be null.</param>
1919
/// <param name="relativeUrl">True to return a relative URL, false to return an absolute URL.</param>
20+
/// <param name="supportEmail">True to return a supportEmail root site URL, false to return an root site URL.</param>
2021
/// <returns>The relative or absolute URL as a string.</returns>
21-
string Package(string id, string version, bool relativeUrl);
22+
string Package(string id, string version, bool relativeUrl, bool supportEmail);
2223

2324
/// <summary>
2425
/// Produces a URL to the package ownership request confirmation page.
@@ -27,8 +28,9 @@ public interface IUrlHelper
2728
/// <param name="username">The username of the ownership request recipient (new owner).</param>
2829
/// <param name="confirmationCode">The confirmation code (secret) associated with the request.</param>
2930
/// <param name="relativeUrl">True to return a relative URL, false to return an absolute URL.</param>
31+
/// <param name="supportEmail">True to return a supportEmail root site URL, false to return an root site URL.</param>
3032
/// <returns>The relative or absolute URL as a string.</returns>
31-
string ConfirmPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl);
33+
string ConfirmPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl, bool supportEmail);
3234

3335
/// <summary>
3436
/// Produces a URL to the package ownership request rejection page.
@@ -37,8 +39,9 @@ public interface IUrlHelper
3739
/// <param name="username">The username of the ownership request recipient (new owner).</param>
3840
/// <param name="confirmationCode">The confirmation code (secret) associated with the request.</param>
3941
/// <param name="relativeUrl">True to return a relative URL, false to return an absolute URL.</param>
42+
/// <param name="supportEmail">True to return a supportEmail root site URL, false to return an root site URL.</param>
4043
/// <returns>The relative or absolute URL as a string.</returns>
41-
string RejectPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl);
44+
string RejectPendingOwnershipRequest(string id, string username, string confirmationCode, bool relativeUrl, bool supportEmail);
4245

4346
/// <summary>
4447
/// Produces a URL to manage the ownership of an existing package.

src/NuGetGallery/Areas/Admin/Controllers/ApiKeysController.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ public async Task<ActionResult> Revoke(RevokeApiKeysRequest revokeApiKeysRequest
130130
credential: apiKeyCredential,
131131
leakedUrl: apiKeyInfo.LeakedUrl,
132132
revocationSource: apiKeyInfo.RevocationSource,
133-
manageApiKeyUrl: Url.ManageMyApiKeys(relativeUrl: false),
134-
contactUrl: Url.Contact(relativeUrl: false));
133+
manageApiKeyUrl: Url.ManageMyApiKeys(relativeUrl: false, supportEmail: true),
134+
contactUrl: Url.Contact(relativeUrl: false, supportEmail: true));
135135
await _messageService.SendMessageAsync(credentialRevokedMessage);
136136

137137
await _authenticationService.RevokeApiKeyCredential(apiKeyCredential, revocationSourceKey, commitChanges: false);

0 commit comments

Comments
 (0)