Browse files

Changes to report abuse email formatting (work in progress)

  • Loading branch information...
1 parent a390707 commit a423496366cf327c8f3d17653d27e2f2ce028eab @TimLovellSmith TimLovellSmith committed Mar 22, 2013
View
8 Facts/Controllers/PackagesControllerFacts.cs
@@ -401,7 +401,7 @@ public void SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated()
It.IsAny<string>(),
"Mordor took my finger",
It.IsAny<bool>(),
- It.IsAny<string>()));
+ It.IsAny<string>(), TODO));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
@@ -434,7 +434,7 @@ public void SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated()
"GollumWasThere",
"Mordor took my finger.",
true,
- It.IsAny<string>()));
+ It.IsAny<string>(), TODO));
}
[Fact]
@@ -448,7 +448,7 @@ public void SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated()
It.IsAny<string>(),
"Mordor took my finger",
It.IsAny<bool>(),
- It.IsAny<string>()));
+ It.IsAny<string>(), TODO));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
@@ -486,7 +486,7 @@ public void SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated()
"GollumWasThere",
It.IsAny<string>(),
It.IsAny<bool>(),
- It.IsAny<string>()));
+ It.IsAny<string>(), TODO));
}
[Fact]
View
2 Facts/Services/MessageServiceFacts.cs
@@ -27,7 +27,7 @@ public void WillSendEmailToGalleryOwner()
MailMessage message = null;
mailSender.Setup(m => m.Send(It.IsAny<MailMessage>())).Callback<MailMessage>(m => { message = m; });
- messageService.ReportAbuse(from, package, "Reason!", "Abuse!", true, "http://package.url/");
+ messageService.ReportAbuse(@from, package, "Reason!", "Abuse!", true, "http://package.url/", TODO);
Assert.Equal("joe@example.com", message.To[0].Address);
Assert.Equal("[NuGet Gallery] Abuse Report for Package 'smangit' Version '1.42.0.1' (Reason: Reason!)", message.Subject);
View
2 Website/App_Code/ViewHelpers.cshtml
@@ -108,7 +108,7 @@
@helper OwnerGravatar(User owner, int size, UrlHelper url, bool showName = true)
{
- <a class="owner" href="@url.Action(MVC.Users.Profiles(owner.Username))" title="@owner.Username">
+ <a class="owner" href="@url.User(owner)" title="@owner.Username">
@if (!String.IsNullOrEmpty(owner.EmailAddress))
{
@GravatarImage(owner.EmailAddress, owner.Username, size)
View
4 Website/Controllers/PackagesController.cs
@@ -318,8 +318,8 @@ public virtual ActionResult ReportAbuse(string id, string version, ReportAbuseVi
from = new MailAddress(reportForm.Email);
}
- _messageService.ReportAbuse(from, package, reportForm.Reason, reportForm.Message, reportForm.AlreadyContactedOwner,
- _config.GetSiteRoot(false) + Url.Package(id, version));
+ _messageService.ReportAbuse(@from, package, reportForm.Reason, reportForm.Message, reportForm.AlreadyContactedOwner,
+ _config.GetSiteRoot(false) + Url.Package(id, version), TODO);
TempData["Message"] = "Your abuse report has been sent to the gallery operators.";
return RedirectToAction(MVC.Packages.DisplayPackage(id, version));
View
16 Website/Services/IMessageService.cs
@@ -1,17 +1,29 @@
using System;
using System.Net.Mail;
+using System.Web.Mvc;
namespace NuGetGallery
{
public interface IMessageService
{
void SendContactOwnersMessage(MailAddress fromAddress, PackageRegistration packageRegistration, string message, string emailSettingsUrl);
- void ReportAbuse(MailAddress fromAddress, Package package, string reason, string message, bool alreadyContactedOwners, string packageUrl);
- void ReportMyPackage(MailAddress fromAddress, Package package, string reason, string message, string packageUrl);
+ void ReportAbuse(ReportPackageRequest report);
+ void ReportMyPackage(ReportPackageRequest report);
void SendNewAccountEmail(MailAddress toAddress, string confirmationUrl);
void SendEmailChangeConfirmationNotice(MailAddress newEmailAddress, string confirmationUrl);
void SendPasswordResetInstructions(User user, string resetPasswordUrl);
void SendEmailChangeNoticeToPreviousEmailAddress(User user, string oldEmailAddress);
void SendPackageOwnerRequest(User fromUser, User toUser, PackageRegistration package, string confirmationUrl);
}
+
+ public class ReportPackageRequest
+ {
+ public MailAddress FromAddress { get; set; }
+ public User RequestingUser { get; set; }
+ public Package Package { get; set; }
+ public string Reason { get; set; }
+ public string Message { get; set; }
+ public bool AlreadyContactedOwners { get; set; }
+ public UrlHelper Url { get; set; }
+ }
}
View
112 Website/Services/MessageService.cs
@@ -2,6 +2,7 @@
using System.Globalization;
using System.Linq;
using System.Net.Mail;
+using System.Text;
using System.Web;
using AnglicanGeek.MarkdownMailer;
using Elmah;
@@ -19,44 +20,90 @@ public MessageService(IMailSender mailSender, IConfiguration config)
_config = config;
}
- public void ReportAbuse(MailAddress fromAddress, Package package, string reason, string message,
- bool alreadyContactedOwners, string packageUrl)
+ private string FormatPart(params object[] args)
{
- const string subject = "[{0}] Abuse Report for Package '{1}' Version '{2}' (Reason: {3})";
- string body = @"_User {0} ({1}) reports the <a href=""{8}"">package '{2}' version '{3}'</a> as abusive ({4}).
-{0} left the following information in the report:_
+ string partTemplate;
+ if (args.Length < 2)
+ {
+ partTemplate = @"_{0}:_
+{1}
+";
+ }
+ else
+ {
+ partTemplate = @"_{0}:_
+{1} - {2}
+";
+ }
-{5}
+ return string.Format(CultureInfo.InvariantCulture, partTemplate, args);
+ }
-_User {7} already contacted the package owners._
+ public void ReportAbuse(ReportPackageRequest request)
+ {
+ string subject = "[{0}] Support Request for '{1}' version {2} (Reason: {3})";
+ var subjectArgs = new object[4];
+ subjectArgs[0] = _config.GalleryOwnerName;
+ subjectArgs[1] = request.Package.PackageRegistration.Id;
+ subjectArgs[2] = request.Package.Version;
+ subjectArgs[3] = request.Reason;
+ subject = String.Format(CultureInfo.InvariantCulture, subject, subjectArgs);
+
+ var body = new StringBuilder();
+ if (request.RequestingUser != null)
+ {
+ string user = FormatPart(
+ "User",
+ request.RequestingUser.Username,
+ request.Url.User(request.RequestingUser));
-_Message sent from {6}_
-";
- body = String.Format(
- CultureInfo.CurrentCulture,
- body,
- fromAddress.DisplayName,
- fromAddress.Address,
- package.PackageRegistration.Id,
- package.Version,
- reason,
- message,
- _config.GalleryOwnerName,
- alreadyContactedOwners ? "HAS" : "has NOT",
- packageUrl
- );
+ body.Append(user);
+ }
- using (var mailMessage = new MailMessage())
+ string email = FormatPart(
+ "Email",
+ request.FromAddress.DisplayName,
+ request.FromAddress.Address);
+ body.Append(email);
+
+ string package = FormatPart(
+ "Package",
+ request.Package.PackageRegistration.Id,
+ request.Url.Package(request.Package.PackageRegistration));
+ body.Append(package);
+
+ string version = FormatPart(
+ "Version",
+ request.Package.Version,
+ request.Url.Package(request.Package));
+ body.Append(version);
+
+ var owners = new StringBuilder(@"_Owners:_");
+ owners.AppendLine();
+ foreach (var owner in request.Package.PackageRegistration.Owners)
{
- mailMessage.Subject = String.Format(
- CultureInfo.CurrentCulture, subject,
- _config.GalleryOwnerName,
- package.PackageRegistration.Id,
- package.Version,
- reason);
- mailMessage.Body = body;
- mailMessage.From = fromAddress;
+ owners.AppendFormat(
+ CultureInfo.InvariantCulture,
+ "{0} - {1}",
+ owner.Username,
+ request.Url.User(owner));
+ owners.AppendLine();
+ }
+ owners.AppendLine();
+ body.Append(owners);
+ body.Append(FormatPart("Reason", request.Reason));
+ body.Append(FormatPart(
+ "Has the package owner been contacted?",
+ request.AlreadyContactedOwners ? "Yes" : "No"));
+ body.Append(FormatPart("Message", request.Message));
+ body.AppendFormat(CultureInfo.InvariantCulture, "*Message sent from {0}*", _config.GalleryOwnerName)
+
+ using (var mailMessage = new MailMessage())
+ {
+ mailMessage.Subject = subject;
+ mailMessage.Body = body.ToString();
+ mailMessage.From = request.FromAddress;
mailMessage.To.Add(_config.GalleryOwnerEmail);
SendMessage(mailMessage);
}
@@ -103,8 +150,7 @@ public void ReportMyPackage(MailAddress fromAddress, Package package, string rea
}
}
- public void SendContactOwnersMessage(
- MailAddress fromAddress, PackageRegistration packageRegistration, string message, string emailSettingsUrl)
+ public void SendContactOwnersMessage(ReportPackageRequest request)
{
string subject = "[{0}] Message for owners of the package '{1}'";
string body = @"_User {0} &lt;{1}&gt; sends the following message to the owners of Package '{2}'._
View
17 Website/T4MVC.cs
@@ -341,8 +341,6 @@ public static class Scripts {
public static readonly string knockout_2_2_1_js = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/knockout-2.2.1.min.js") ? Url("knockout-2.2.1.min.js") : Url("knockout-2.2.1.js");
- public static readonly string modernizr_2_0_6_development_only_js = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/modernizr-2.0.6-development-only.min.js") ? Url("modernizr-2.0.6-development-only.min.js") : Url("modernizr-2.0.6-development-only.js");
-
public static readonly string stats_js = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/stats.min.js") ? Url("stats.min.js") : Url("stats.js");
public static readonly string ZeroClipboard_js = T4MVCHelpers.IsProduction() && T4Extensions.FileExists(URLPATH + "/ZeroClipboard.min.js") ? Url("ZeroClipboard.min.js") : Url("ZeroClipboard.js");
@@ -356,6 +354,21 @@ public static class Content {
public static string Url() { return T4MVCHelpers.ProcessVirtualPath(URLPATH); }
public static string Url(string fileName) { return T4MVCHelpers.ProcessVirtualPath(URLPATH + "/" + fileName); }
[GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
+ public static class font {
+ private const string URLPATH = "~/Content/font";
+ public static string Url() { return T4MVCHelpers.ProcessVirtualPath(URLPATH); }
+ public static string Url(string fileName) { return T4MVCHelpers.ProcessVirtualPath(URLPATH + "/" + fileName); }
+ public static readonly string fontawesome_webfont_eot = Url("fontawesome-webfont.eot");
+ public static readonly string fontawesome_webfont_svg = Url("fontawesome-webfont.svg");
+ public static readonly string fontawesome_webfont_ttf = Url("fontawesome-webfont.ttf");
+ public static readonly string fontawesome_webfont_woff = Url("fontawesome-webfont.woff");
+ public static readonly string FontAwesome_otf = Url("FontAwesome.otf");
+ }
+
+ public static readonly string font_awesome_ie7_min_css = Url("font-awesome-ie7.min.css");
+ public static readonly string font_awesome_css = Url("font-awesome.css");
+ public static readonly string font_awesome_min_css = Url("font-awesome.min.css");
+ [GeneratedCode("T4MVC", "2.0"), DebuggerNonUserCode]
public static class Images {
private const string URLPATH = "~/Content/Images";
public static string Url() { return T4MVCHelpers.ProcessVirtualPath(URLPATH); }
View
6 Website/UrlExtensions.cs
@@ -119,6 +119,12 @@ public static string UploadPackage(this UrlHelper url)
return url.Action(actionName: "UploadPackage", controllerName: MVC.Packages.Name);
}
+ public static string User(this UrlHelper url, User user)
+ {
+ string result = url.Action(MVC.Users.Profiles(user.Username));
+ return EnsureTrailingSlash(result);
+ }
+
public static string EditPackage(this UrlHelper url, IPackageVersionModel package)
{
return url.Action(MVC.Packages.Edit(package.Id, package.Version));
View
2 Website/Views/Packages/_ListPackage.cshtml
@@ -16,7 +16,7 @@
<ul class="owners">
@foreach (var owner in Model.Owners)
{
- <li><a href="@Url.Action(MVC.Users.Profiles(owner.Username))" title="@owner.Username">@owner.Username</a></li>
+ <li><a href="@Url.User(owner)" title="@owner.Username">@owner.Username</a></li>
}
</ul>
</header>

0 comments on commit a423496

Please sign in to comment.