Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue 4258 - ContactOwners e-mails contain the package version numer next to package id #5116

Merged
merged 14 commits into from
Jan 19, 2018
2 changes: 1 addition & 1 deletion src/NuGetGallery/App_Start/Routes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -386,7 +386,7 @@ public static void RegisterUIRoutes(RouteCollection routes)
routes.Redirect(
r => r.MapRoute(
"PackageActions",
"Package/{action}/{id}",
"Package/{action}/{id}/{version}",
new { controller = "Packages", action = "ContactOwners" },
// This next bit looks bad, but it's not. It will never change because
// it's mapping the legacy routes to the new better routes.
Expand Down
16 changes: 8 additions & 8 deletions src/NuGetGallery/Controllers/PackagesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -909,10 +909,9 @@ await _supportRequestService.UpdateIssueAsync(
[HttpGet]
[Authorize]
[RequiresAccountConfirmation("contact package owners")]
public virtual ActionResult ContactOwners(string id)
public virtual ActionResult ContactOwners(string id, string version)
{
var package = _packageService.FindPackageByIdAndVersion(id, version: null);

var package = _packageService.FindPackageByIdAndVersionStrict(id, version);
if (package == null || package.PackageRegistration == null)
{
return HttpNotFound();
Expand All @@ -921,7 +920,8 @@ public virtual ActionResult ContactOwners(string id)
bool hasOwners = package.PackageRegistration.Owners.Any();
var model = new ContactOwnersViewModel
{
PackageId = package.PackageRegistration.Id,
PackageId = id,
PackageVersion = package.Version,
ProjectUrl = package.ProjectUrl,
Owners = package.PackageRegistration.Owners.Where(u => u.EmailAllowed),
CopySender = true,
Expand All @@ -935,17 +935,17 @@ public virtual ActionResult ContactOwners(string id)
[Authorize]
[ValidateAntiForgeryToken]
[RequiresAccountConfirmation("contact package owners")]
public virtual ActionResult ContactOwners(string id, ContactOwnersViewModel contactForm)
public virtual ActionResult ContactOwners(string id, string version, ContactOwnersViewModel contactForm)
{
// Html Encode the message
contactForm.Message = System.Web.HttpUtility.HtmlEncode(contactForm.Message);

if (!ModelState.IsValid)
{
return ContactOwners(id);
return ContactOwners(id, version);
}

var package = _packageService.FindPackageRegistrationById(id);
var package = _packageService.FindPackageByIdAndVersionStrict(id, version);
if (package == null)
{
return HttpNotFound();
Expand All @@ -969,7 +969,7 @@ public virtual ActionResult ContactOwners(string id, ContactOwnersViewModel cont
routeValues: new
{
id,
version = (string)null
version
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Services/IMessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace NuGetGallery
{
public interface IMessageService
{
void SendContactOwnersMessage(MailAddress fromAddress, PackageRegistration packageRegistration, string packageUrl, string message, string emailSettingsUrl, bool copyFromAddress);
void SendContactOwnersMessage(MailAddress fromAddress, Package package, string packageUrl, string message, string emailSettingsUrl, bool copyFromAddress);
void ReportAbuse(ReportPackageRequest report);
void ReportMyPackage(ReportPackageRequest report);
void SendNewAccountEmail(MailAddress toAddress, string confirmationUrl);
Expand Down
17 changes: 9 additions & 8 deletions src/NuGetGallery/Services/MessageService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,31 +129,32 @@ public void ReportMyPackage(ReportPackageRequest request)
}
}

public void SendContactOwnersMessage(MailAddress fromAddress, PackageRegistration packageRegistration, string packageUrl, string message, string emailSettingsUrl, bool copySender)
public void SendContactOwnersMessage(MailAddress fromAddress, Package package, string packageUrl, string message, string emailSettingsUrl, bool copySender)
{
string subject = "[{0}] Message for owners of the package '{1}'";
string body = @"_User {0} <{1}> sends the following message to the owners of Package '[{2}]({3})'._
string body = @"_User {0} <{1}> sends the following message to the owners of Package '[{2} {3}]({4})'._

{4}
{5}

-----------------------------------------------
<em style=""font-size: 0.8em;"">
To stop receiving contact emails as an owner of this package, sign in to the {5} and
[change your email notification settings]({6}).
To stop receiving contact emails as an owner of this package, sign in to the {6} and
[change your email notification settings]({7}).
</em>";

body = String.Format(
CultureInfo.CurrentCulture,
body,
fromAddress.DisplayName,
fromAddress.Address,
packageRegistration.Id,
package.PackageRegistration.Id,
package.Version,
packageUrl,
message,
Config.GalleryOwner.DisplayName,
emailSettingsUrl);

subject = String.Format(CultureInfo.CurrentCulture, subject, Config.GalleryOwner.DisplayName, packageRegistration.Id);
subject = String.Format(CultureInfo.CurrentCulture, subject, Config.GalleryOwner.DisplayName, package.PackageRegistration.Id);

using (var mailMessage = new MailMessage())
{
Expand All @@ -162,7 +163,7 @@ [change your email notification settings]({6}).
mailMessage.From = Config.GalleryOwner;
mailMessage.ReplyToList.Add(fromAddress);

AddOwnersToMailMessage(packageRegistration, mailMessage);
AddOwnersToMailMessage(package.PackageRegistration, mailMessage);

if (mailMessage.To.Any())
{
Expand Down
5 changes: 3 additions & 2 deletions src/NuGetGallery/UrlExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public static string Contact(this UrlHelper url, bool relativeUrl = true)
return GetActionLink(url, "Contact", "Pages", relativeUrl);
}

public static string ContactOwners(this UrlHelper url, string id, bool relativeUrl = true)
public static string ContactOwners(this UrlHelper url, string id, string version, bool relativeUrl = true)
{
return GetActionLink(
url,
Expand All @@ -893,7 +893,8 @@ public static string ContactOwners(this UrlHelper url, string id, bool relativeU
relativeUrl,
routeValues: new RouteValueDictionary
{
{ "id", id }
{ "id", id },
{ "version", version }
});
}

Expand Down
2 changes: 2 additions & 0 deletions src/NuGetGallery/ViewModels/ContactOwnersViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class ContactOwnersViewModel
{
public string PackageId { get; set; }

public string PackageVersion { get; set; }

public string ProjectUrl { get; set; }

public IEnumerable<User> Owners { get; set; }
Expand Down
7 changes: 4 additions & 3 deletions src/NuGetGallery/Views/Packages/ContactOwners.cshtml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@model ContactOwnersViewModel
@{
ViewBag.Title = "Contact Owners";
ViewBag.Title = "Contact the Owners of " + Model.PackageId + " " + Model.PackageVersion;
ViewBag.Tab = "Packages";
ViewBag.MdPageColumns = Constants.ColumnsFormMd;
Layout = "~/Views/Shared/Gallery/Layout.cshtml";
Expand All @@ -12,9 +12,10 @@
@Html.Partial("_PackageHeading", new PackageHeadingModel
{
PageHeading = "Contact the Owners of",
PackageDisplay = Model.PackageId.Abbreviate(50),
PackageDisplay = Model.PackageId + " " + Model.PackageVersion,
Id = Model.PackageId,
LinkIdOnly = true
Version = Model.PackageVersion,
LinkIdOnly = false
})
@if (Model.Owners.Any())
{
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Packages/DisplayPackage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@
}
<li>
<i class="ms-Icon ms-Icon--Mail" aria-hidden="true"></i>
<a href="@Url.ContactOwners(Model.Id)" title="Ask the package owners a question">Contact owners</a>
<a href="@Url.ContactOwners(Model.Id, Model.Version)" title="Ask the package owners a question">Contact owners</a>
</li>
@if (Model.IsActionAllowed(User, PackageActions.ReportMyPackage))
{
Expand Down
2 changes: 1 addition & 1 deletion src/NuGetGallery/Views/Packages/ReportAbuse.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
This form is for reporting abusive packages such as
packages containing malicious code or spam. If "@Model.PackageId" simply doesn't
work, or if you need help getting the package installed, please
<a href="@Url.ContactOwners(Model.PackageId)" title="contact the owners">contact the owners instead.</a>
<a href="@Url.ContactOwners(Model.PackageId, Model.PackageVersion)" title="contact the owners">contact the owners instead.</a>
</text>
)

Expand Down
Loading