Skip to content

Commit 7844e95

Browse files
authored
Merge pull request #7142 from NuGet/ryuyu-allow-anglebracketownerrequest
Allow HTML in owner request messages.
2 parents 822e4e6 + 6abf098 commit 7844e95

4 files changed

Lines changed: 45 additions & 4 deletions

File tree

src/NuGetGallery/Controllers/JsonApiController.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,12 @@ public virtual ActionResult GetPackageOwners(string id)
103103

104104
[HttpPost]
105105
[ValidateAntiForgeryToken]
106-
public async Task<JsonResult> AddPackageOwner(string id, string username, string message)
106+
public async Task<JsonResult> AddPackageOwner(AddPackageOwnerViewModel addOwnerData)
107107
{
108+
string id = addOwnerData.Id;
109+
string username = addOwnerData.Username;
110+
string message = addOwnerData.Message;
111+
108112
if (Regex.IsMatch(username, GalleryConstants.EmailValidationRegex, RegexOptions.None, GalleryConstants.EmailValidationRegexTimeout))
109113
{
110114
return Json(new { success = false, message = Strings.AddOwner_NameIsEmail }, JsonRequestBehavior.AllowGet);

src/NuGetGallery/NuGetGallery.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -752,6 +752,7 @@
752752
<Compile Include="Telemetry\UserPackageDeleteOutcome.cs" />
753753
<Compile Include="UrlHelperExtensions.cs" />
754754
<Compile Include="ViewModels\AddOrganizationViewModel.cs" />
755+
<Compile Include="ViewModels\AddPackageOwnerViewModel.cs" />
755756
<Compile Include="ViewModels\CompositeLicenseExpressionSegmentViewModel.cs" />
756757
<Compile Include="ViewModels\DeleteOrganizationViewModel.cs" />
757758
<Compile Include="ViewModels\DeleteUserViewModel.cs" />
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) .NET Foundation. All rights reserved.
2+
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3+
4+
using System.Web.Mvc;
5+
6+
namespace NuGetGallery
7+
{
8+
public class AddPackageOwnerViewModel
9+
{
10+
public string Id { get; set; }
11+
public string Username { get; set; }
12+
13+
[AllowHtml]
14+
public string Message { get; set; }
15+
}
16+
}

tests/NuGetGallery.Facts/Controllers/JsonApiControllerFacts.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,15 @@ public async Task FailsIfUserInputIsEmailAddress(Func<Fakes, User> getCurrentUse
355355
var package = fakes.Package;
356356
var controller = GetController<JsonApiController>();
357357
controller.SetCurrentUser(currentUser);
358+
AddPackageOwnerViewModel testData = new AddPackageOwnerViewModel
359+
{
360+
Id = package.Id,
361+
Username = usernameToAdd,
362+
Message = "a message"
363+
};
358364

359365
// Act
360-
var result = await controller.AddPackageOwner(package.Id, usernameToAdd, "a message");
366+
var result = await controller.AddPackageOwner(testData);
361367
dynamic data = result.Data;
362368

363369
// Assert
@@ -444,8 +450,15 @@ public async Task CreatesPackageOwnerRequestSendsEmailAndReturnsPendingState(Fun
444450
.Verifiable();
445451
}
446452
}
453+
AddPackageOwnerViewModel testData = new AddPackageOwnerViewModel
454+
{
455+
Id = fakes.Package.Id,
456+
Username = userToAdd.Username,
457+
Message = "Hello World! Html Encoded <3"
458+
};
447459

448-
JsonResult result = await controller.AddPackageOwner(fakes.Package.Id, userToAdd.Username, "Hello World! Html Encoded <3");
460+
461+
JsonResult result = await controller.AddPackageOwner(testData);
449462
dynamic data = result.Data;
450463
PackageOwnersResultViewModel model = data.model;
451464

@@ -679,7 +692,14 @@ public async Task RemovesExistingOwner(Func<Fakes, User> getCurrentUser, Func<Fa
679692

680693
private static async Task<ActionResult> AddPackageOwner(JsonApiController jsonApiController, string packageId, string username)
681694
{
682-
return await jsonApiController.AddPackageOwner(packageId, username, "message");
695+
AddPackageOwnerViewModel testData = new AddPackageOwnerViewModel
696+
{
697+
Id = packageId,
698+
Username = username,
699+
Message = "message"
700+
};
701+
702+
return await jsonApiController.AddPackageOwner(testData);
683703
}
684704

685705
private static async Task<ActionResult> RemovePackageOwner(JsonApiController jsonApiController, string packageId, string username)

0 commit comments

Comments
 (0)