本文整理汇总了C#中NuGetGallery.ReportAbuseViewModel类的典型用法代码示例。如果您正苦于以下问题:C# ReportAbuseViewModel类的具体用法?C# ReportAbuseViewModel怎么用?C# ReportAbuseViewModel使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ReportAbuseViewModel类属于NuGetGallery命名空间,在下文中一共展示了ReportAbuseViewModel类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ReportMyPackage
public virtual ActionResult ReportMyPackage(string id, string version)
{
var user = _userService.FindByUsername(HttpContext.User.Identity.Name);
var package = _packageService.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return HttpNotFound();
}
// If user hit this url by constructing it manually but is not the owner, redirect them to ReportAbuse
if (!(HttpContext.User.IsInRole(Constants.AdminRoleName) || package.IsOwner(user)))
{
return RedirectToAction(ActionNames.ReportAbuse, new { id, version });
}
var model = new ReportAbuseViewModel
{
ReasonChoices = ReportMyPackageReasons,
ConfirmedUser = user.Confirmed,
PackageId = id,
PackageVersion = package.Version,
};
return View(model);
}
示例2: ReportMyPackage
public virtual ActionResult ReportMyPackage(string id, string version, ReportAbuseViewModel reportForm)
{
// Html Encode the message
reportForm.Message = System.Web.HttpUtility.HtmlEncode(reportForm.Message);
if (!ModelState.IsValid)
{
return ReportMyPackage(id, version);
}
var package = _packageService.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return HttpNotFound();
}
var user = GetCurrentUser();
MailAddress from = user.ToMailAddress();
_messageService.ReportMyPackage(
new ReportPackageRequest
{
FromAddress = from,
Message = reportForm.Message,
Package = package,
Reason = EnumHelper.GetDescription(reportForm.Reason.Value),
RequestingUser = user,
Url = Url,
CopySender = reportForm.CopySender
});
TempData["Message"] = "Your support request has been sent to the gallery operators.";
return Redirect(Url.Package(id, version));
}
示例3: ReportAbuse
public virtual ActionResult ReportAbuse(string id, string version)
{
var package = _packageService.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return HttpNotFound();
}
var model = new ReportAbuseViewModel
{
ReasonChoices = ReportOtherPackageReasons,
PackageId = id,
PackageVersion = package.Version,
};
if (Request.IsAuthenticated)
{
var user = _userService.FindByUsername(HttpContext.User.Identity.Name);
// If user logged on in as owner a different tab, then clicked the link, we can redirect them to ReportMyPackage
if (package.IsOwner(user))
{
return RedirectToAction(ActionNames.ReportMyPackage, new {id, version});
}
if (user.Confirmed)
{
model.ConfirmedUser = true;
}
}
ViewData[Constants.ReturnUrlViewDataKey] = Url.Action(ActionNames.ReportMyPackage, new {id, version});
return View(model);
}
示例4: SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated
public void SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(
s => s.ReportAbuse(It.Is<ReportPackageRequest>(r => r.Message == "Mordor took my finger")));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
Version = "2.0.1"
};
var packageService = new Mock<IPackageService>();
packageService.Setup(p => p.FindPackageByIdAndVersion("mordor", It.IsAny<string>(), true)).Returns(package);
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(h => h.Request.IsAuthenticated).Returns(true);
httpContext.Setup(h => h.User.Identity.Name).Returns("Frodo");
var userService = new Mock<IUserService>();
userService.Setup(u => u.FindByUsername("Frodo")).Returns(new User { EmailAddress = "[email protected]", Username = "Frodo", Key = 1 });
var controller = CreateController(
packageService: packageService,
messageService: messageService,
userService: userService,
httpContext: httpContext);
var model = new ReportAbuseViewModel
{
Message = "Mordor took my finger",
Reason = ReportPackageReason.IsFraudulent,
};
TestUtility.SetupUrlHelper(controller, httpContext);
ActionResult result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectResult;
Assert.NotNull(result);
userService.VerifyAll();
messageService.Verify(
s => s.ReportAbuse(
It.Is<ReportPackageRequest>(
r => r.Message == "Mordor took my finger"
&& r.FromAddress.Address == "[email protected]"
&& r.FromAddress.DisplayName == "Frodo"
&& r.Reason == EnumHelper.GetDescription(ReportPackageReason.IsFraudulent))));
}
示例5: ReportAbuse
public virtual ActionResult ReportAbuse(string id, string version, ReportAbuseViewModel reportForm)
{
// Html Encode the message
reportForm.Message = System.Web.HttpUtility.HtmlEncode(reportForm.Message);
if (!ModelState.IsValid)
{
return ReportAbuse(id, version);
}
var package = _packageService.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return HttpNotFound();
}
User user = null;
MailAddress from;
if (Request.IsAuthenticated)
{
user = GetCurrentUser();
from = user.ToMailAddress();
}
else
{
from = new MailAddress(reportForm.Email);
}
var request = new ReportPackageRequest
{
AlreadyContactedOwners = reportForm.AlreadyContactedOwner,
FromAddress = from,
Message = reportForm.Message,
Package = package,
Reason = EnumHelper.GetDescription(reportForm.Reason.Value),
RequestingUser = user,
Url = Url,
CopySender = reportForm.CopySender,
Signature = reportForm.Signature
};
_messageService.ReportAbuse(request);
TempData["Message"] = "Your abuse report has been sent to the gallery operators.";
return Redirect(Url.Package(id, version));
}
示例6: ReportMyPackage
public virtual async Task<ActionResult> ReportMyPackage(string id, string version, ReportAbuseViewModel reportForm)
{
// Html Encode the message
reportForm.Message = System.Web.HttpUtility.HtmlEncode(reportForm.Message);
if (!ModelState.IsValid)
{
return ReportMyPackage(id, version);
}
var package = _packageService.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return HttpNotFound();
}
var user = GetCurrentUser();
MailAddress from = user.ToMailAddress();
var request = new ReportPackageRequest
{
FromAddress = from,
Message = reportForm.Message,
Package = package,
Reason = EnumHelper.GetDescription(reportForm.Reason.Value),
RequestingUser = user,
Url = Url,
CopySender = reportForm.CopySender
};
var subject = $"Owner Support Request for '{package.PackageRegistration.Id}' version {package.Version}";
var requestorEmailAddress = user != null ? user.EmailAddress : reportForm.Email;
var reason = EnumHelper.GetDescription(reportForm.Reason.Value);
await _supportRequestService.AddNewSupportRequestAsync(subject, reportForm.Message, requestorEmailAddress, reason, user, package);
_messageService.ReportMyPackage(request);
TempData["Message"] = "Your support request has been sent to the gallery operators.";
return Redirect(Url.Package(id, version));
}
示例7: SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated
public void SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(
s => s.ReportAbuse(It.Is<ReportPackageRequest>(r => r.Message == "Mordor took my finger")));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
Version = "2.0.1"
};
var packageService = new Mock<IPackageService>();
packageService.Setup(p => p.FindPackageByIdAndVersion("mordor", "2.0.1", true)).Returns(package);
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(h => h.Request.IsAuthenticated).Returns(false);
var controller = CreateController(
packageService: packageService,
messageService: messageService,
httpContext: httpContext);
var model = new ReportAbuseViewModel
{
Email = "[email protected]",
Message = "Mordor took my finger.",
Reason = ReportPackageReason.IsFraudulent,
AlreadyContactedOwner = true,
};
TestUtility.SetupUrlHelper(controller, httpContext);
var result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectResult;
Assert.NotNull(result);
messageService.Verify(
s => s.ReportAbuse(
It.Is<ReportPackageRequest>(
r => r.FromAddress.Address == "[email protected]"
&& r.Package == package
&& r.Reason == EnumHelper.GetDescription(ReportPackageReason.IsFraudulent)
&& r.Message == "Mordor took my finger."
&& r.AlreadyContactedOwners)));
}
示例8: ContactAdmins
public virtual ActionResult ContactAdmins(string id, string version, ReportAbuseViewModel reportForm)
{
if (!ModelState.IsValid) return ContactAdmins(id, version);
var package = packageSvc.FindPackageByIdAndVersion(id, version);
if (package == null) return PackageNotFound(id, version);
MailAddress from = null;
if (Request.IsAuthenticated)
{
var user = userSvc.FindByUsername(HttpContext.User.Identity.Name);
from = user.ToMailAddress();
} else from = new MailAddress(reportForm.Email);
var packageUrl = EnsureTrailingSlash(Configuration.GetSiteRoot(useHttps: false)) + RemoveStartingSlash(Url.Package(package));
messageService.ContactSiteAdmins(from, package, reportForm.Message, packageUrl, reportForm.CopySender);
TempData["Message"] = "Your message has been sent to the site admins.";
return RedirectToAction(MVC.Packages.DisplayPackage(id, version));
}
示例9: HtmlEncodesMessageContent
public async Task HtmlEncodesMessageContent()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(
s => s.ReportAbuse(It.Is<ReportPackageRequest>(r => r.Message == "Mordor took my finger")));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
Version = "2.0.1"
};
var packageService = new Mock<IPackageService>();
packageService.Setup(p => p.FindPackageByIdAndVersion("mordor", "2.0.1", true)).Returns(package);
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(h => h.Request.IsAuthenticated).Returns(false);
var controller = CreateController(
packageService: packageService,
messageService: messageService,
httpContext: httpContext);
var model = new ReportAbuseViewModel
{
Email = "[email protected]",
Message = "I like the cut of your jib. It's <b>bold</b>.",
Reason = ReportPackageReason.IsFraudulent,
AlreadyContactedOwner = true,
};
TestUtility.SetupUrlHelper(controller, httpContext);
await controller.ReportAbuse("mordor", "2.0.1", model);
messageService.Verify(
s => s.ReportAbuse(
It.Is<ReportPackageRequest>(
r => r.FromAddress.Address == "[email protected]"
&& r.Package == package
&& r.Reason == EnumHelper.GetDescription(ReportPackageReason.IsFraudulent)
&& r.Message == "I like the cut of your jib. It's <b>bold</b>."
&& r.AlreadyContactedOwners)));
}
示例10: ReportMyPackage
public virtual ActionResult ReportMyPackage(string id, string version)
{
var user = GetCurrentUser();
var package = _packageService.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return HttpNotFound();
}
// If user hit this url by constructing it manually but is not the owner, redirect them to ReportAbuse
if (!(User.IsInRole(Constants.AdminRoleName) || package.IsOwner(user)))
{
return RedirectToAction("ReportAbuse", new { id, version });
}
var model = new ReportAbuseViewModel
{
ReasonChoices = ReportMyPackageReasons,
ConfirmedUser = user.Confirmed,
PackageId = id,
PackageVersion = package.Version,
CopySender = true,
Signature = user.Username
};
return View(model);
}
示例11: SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated
public void SendsMessageToGalleryOwnerWithUserInfoWhenAuthenticated()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(
s => s.ReportAbuse(
It.IsAny<MailAddress>(),
It.IsAny<Package>(),
"Mordor took my finger"));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
Version = "2.0.1"
};
var packageSvc = new Mock<IPackageService>();
packageSvc.Setup(p => p.FindPackageByIdAndVersion("mordor", It.IsAny<string>(), true)).Returns(package);
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(h => h.Request.IsAuthenticated).Returns(true);
httpContext.Setup(h => h.User.Identity.Name).Returns("Frodo");
var userSvc = new Mock<IUserService>();
userSvc.Setup(u => u.FindByUsername("Frodo")).Returns(new User { EmailAddress = "[email protected]", Username = "Frodo" });
var controller = CreateController(
packageSvc: packageSvc,
messageSvc: messageService,
userSvc: userSvc,
httpContext: httpContext);
var model = new ReportAbuseViewModel
{
Message = "Mordor took my finger."
};
var result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectToRouteResult;
Assert.NotNull(result);
userSvc.VerifyAll();
messageService.Verify(
s => s.ReportAbuse(
It.Is<MailAddress>(
m => m.Address == "[email protected]"
&& m.DisplayName == "Frodo"),
package,
"Mordor took my finger."
));
}
示例12: SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated
public void SendsMessageToGalleryOwnerWithEmailOnlyWhenUnauthenticated()
{
var messageService = new Mock<IMessageService>();
messageService.Setup(
s => s.ReportAbuse(
It.IsAny<MailAddress>(),
It.IsAny<Package>(),
"Mordor took my finger"));
var package = new Package
{
PackageRegistration = new PackageRegistration { Id = "mordor" },
Version = "2.0.1"
};
var packageSvc = new Mock<IPackageService>();
packageSvc.Setup(p => p.FindPackageByIdAndVersion("mordor", "2.0.1", true)).Returns(package);
var httpContext = new Mock<HttpContextBase>();
httpContext.Setup(h => h.Request.IsAuthenticated).Returns(false);
var controller = CreateController(
packageSvc: packageSvc,
messageSvc: messageService,
httpContext: httpContext);
var model = new ReportAbuseViewModel
{
Email = "[email protected]",
Message = "Mordor took my finger."
};
var result = controller.ReportAbuse("mordor", "2.0.1", model) as RedirectToRouteResult;
Assert.NotNull(result);
messageService.Verify(
s => s.ReportAbuse(
It.Is<MailAddress>(m => m.Address == "[email protected]"),
package,
"Mordor took my finger."
));
}
示例13: ReportAbuse
public virtual ActionResult ReportAbuse(string id, string version, ReportAbuseViewModel reportForm)
{
if (!ModelState.IsValid)
{
return ReportAbuse(id, version);
}
var package = packageSvc.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return PackageNotFound(id, version);
}
MailAddress from = null;
if (Request.IsAuthenticated)
{
var user = userSvc.FindByUsername(HttpContext.User.Identity.Name);
from = user.ToMailAddress();
}
else
{
from = new MailAddress(reportForm.Email);
}
messageService.ReportAbuse(from, package, reportForm.Message);
TempData["Message"] = "Your abuse report has been sent to the gallery operators.";
return RedirectToAction(MVC.Packages.DisplayPackage(id, version));
}
示例14: ReportAbuse
// NOTE: Intentionally NOT requiring authentication
public virtual ActionResult ReportAbuse(string id, string version)
{
var package = _packageSvc.FindPackageByIdAndVersion(id, version);
if (package == null)
{
return PackageNotFound(id, version);
}
var model = new ReportAbuseViewModel
{
PackageId = id,
PackageVersion = package.Version,
};
if (Request.IsAuthenticated)
{
var user = _userSvc.FindByUsername(HttpContext.User.Identity.Name);
if (user.Confirmed)
{
model.ConfirmedUser = true;
}
}
return View(model);
}