public void DeleteComment_Owner() { //Assert.Inconclusive("Complete this test"); var user = TestHelper.SetPrincipal("TestUser01"); var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know").SetUserContext(user); var c = cmdcreate.Execute().Result; VoatAssert.IsValid(c); int id = c.Response.ID; var cmd = new DeleteCommentCommand(id).SetUserContext(user); var r = cmd.Execute().Result; VoatAssert.IsValid(r); //verify using (var db = new VoatDataContext()) { var comment = db.Comment.FirstOrDefault(x => x.ID == id); Assert.AreEqual(true, comment.IsDeleted); Assert.AreNotEqual(c.Response.Content, comment.Content); //Ensure content is replaced in moderator deletion Assert.IsTrue(comment.Content.StartsWith("Deleted by")); Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(comment.Content)); } }
public async Task DeleteComment_Moderator() { //Assert.Inconclusive("Complete this test"); var content = "This is my data too you know 2"; var user = TestHelper.SetPrincipal("TestUser01"); var cmdcreate = new CreateCommentCommand(1, null, content).SetUserContext(user); var c = cmdcreate.Execute().Result; VoatAssert.IsValid(c); int id = c.Response.ID; //switch to mod of sub user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new DeleteCommentCommand(id, "This is spam").SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); //verify using (var db = new VoatDataContext()) { var comment = db.Comment.FirstOrDefault(x => x.ID == id); Assert.AreEqual(true, comment.IsDeleted); //Content should remain unchanged in mod deletion Assert.AreEqual(comment.Content, content); Assert.AreEqual(comment.FormattedContent, Formatting.FormatMessage(content)); } }
public void TestCommentDelete() { var authorCommentID = CommentIDs.Item1; var modCommentID = CommentIDs.Item2; //read content, ensure data is correct VerifyComment(authorCommentID, CONTENT, false); VerifyComment(modCommentID, CONTENT, false); //delete comment (mod) var user = TestHelper.SetPrincipal(AUTHOR_NAME); var d = new DeleteCommentCommand(authorCommentID).SetUserContext(user); var r = d.Execute().Result; Assert.IsTrue(r.Success, r.Message); user = TestHelper.SetPrincipal(MOD_NAME); d = new DeleteCommentCommand(modCommentID, "My Reason Here").SetUserContext(user);; r = d.Execute().Result; Assert.IsTrue(r.Success, r.Message); //read comment, ensure data exists VerifyComment(authorCommentID, "Deleted", true); VerifyComment(modCommentID, "Deleted", true); }
public void DeleteComment() { TestHelper.SetPrincipal("TestUser1"); var cmdcreate = new CreateCommentCommand(1, null, "This is my data too you know"); var c = cmdcreate.Execute().Result; Assert.IsNotNull(c, "response null"); Assert.IsTrue(c.Success, c.Message); Assert.IsNotNull(c.Response, "Response payload null"); int id = c.Response.ID; var cmd = new DeleteCommentCommand(id); var r = cmd.Execute().Result; Assert.IsTrue(r.Success); //verify using (var db = new Voat.Data.Repository()) { var comment = db.GetComment(id); Assert.AreEqual(true, comment.IsDeleted); Assert.AreNotEqual(c.Response.Content, comment.Content); } }
public async Task <ActionResult> ModeratorDelete(string subverse, int submissionID, ModeratorDeleteContentViewModel model) { var q = new QueryComment(model.ID); var comment = await q.ExecuteAsync(); if (comment == null || comment.SubmissionID != submissionID) { ModelState.AddModelError("", "Can not find comment. Who did this?"); return(View(new ModeratorDeleteContentViewModel())); } if (!ModeratorPermission.HasPermission(User.Identity.Name, comment.Subverse, Domain.Models.ModeratorAction.DeleteComments)) { return(new HttpUnauthorizedResult()); } if (!ModelState.IsValid) { return(View(model)); } var cmd = new DeleteCommentCommand(model.ID, model.Reason); var r = await cmd.Execute(); if (r.Success) { return(RedirectToRoute("SubverseCommentsWithSort_Short", new { subverseName = subverse, submissionID = submissionID })); } else { ModelState.AddModelError("", r.Message); return(View(model)); } }
public ActionResult DeleteComment(int id, [FromServices] DeleteCommentCommand delCommentcmd) { var model = new DeleteCommentModel(); model.Id = id; var comment = _dataContext.Comments .Include(c => c.MediaItem) .FirstOrDefault(c => c.Id == id); delCommentcmd.Execute(model); return(RedirectToAction("Details", new { id = comment.MediaItem.Id })); }
public async Task <ActionResult> DeleteComment(int id) { if (ModelState.IsValid) { var cmd = new DeleteCommentCommand(id, "This feature is not yet implemented").SetUserContext(User); var result = await cmd.Execute(); return(base.JsonResult(result)); } else { return(base.JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); //return new HttpStatusCodeResult(HttpStatusCode.BadRequest); } }
public async Task Bug_Trap_Positive_ContributionPoints_Removed() { //Test that when a user deletes comments and submissions with positive points, that the points are reset var altList = new[] { "UnitTestUser10", "UnitTestUser11", "UnitTestUser12", "UnitTestUser13", "UnitTestUser14", "UnitTestUser15" }; var primaryUser = "******"; var currentUser = TestHelper.SetPrincipal(primaryUser); var cmdSubmission = new CreateSubmissionCommand(new Domain.Models.UserSubmission() { Title = "Test Positive SCP Removed upon Delete", Content = "Does this get removed?", Subverse = "unit" }).SetUserContext(currentUser); var subResponse = await cmdSubmission.Execute(); VoatAssert.IsValid(subResponse); var submissionID = subResponse.Response.ID; var cmdComment = new CreateCommentCommand(submissionID, null, "This is my manipulation comment. Upvote. Go.").SetUserContext(currentUser); var commentResponse = await cmdComment.Execute(); VoatAssert.IsValid(commentResponse); var commentID = commentResponse.Response.ID; var vote = new Func <int, Domain.Models.ContentType, string[], Task>(async(id, contentType, users) => { foreach (string user in users) { var userIdentity = TestHelper.SetPrincipal(user); switch (contentType) { case Domain.Models.ContentType.Comment: var c = new CommentVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity); var cr = await c.Execute(); VoatAssert.IsValid(cr); break; case Domain.Models.ContentType.Submission: var s = new SubmissionVoteCommand(id, 1, Guid.NewGuid().ToString()).SetUserContext(userIdentity); var sr = await s.Execute(); VoatAssert.IsValid(sr); break; } } }); await vote(commentID, Domain.Models.ContentType.Comment, altList); var deleteComment = new DeleteCommentCommand(commentID).SetUserContext(currentUser); var deleteCommentResponse = await deleteComment.Execute(); VoatAssert.IsValid(deleteCommentResponse); //verify ups where reset using (var context = new Voat.Data.Models.VoatDataContext()) { var votes = context.CommentVoteTracker.Where(x => x.CommentID == commentID); Assert.AreEqual(altList.Length, votes.Count()); var anyInvalid = votes.Any(x => x.VoteValue != 0); Assert.IsFalse(anyInvalid, "Found comment votes with a non-zero vote value"); } await vote(submissionID, Domain.Models.ContentType.Submission, altList); var deleteSubmission = new DeleteSubmissionCommand(submissionID).SetUserContext(currentUser); var deleteSubmissionResponse = await deleteSubmission.Execute(); VoatAssert.IsValid(deleteSubmissionResponse); //verify ups where reset using (var context = new Voat.Data.Models.VoatDataContext()) { var votes = context.SubmissionVoteTracker.Where(x => x.SubmissionID == submissionID); Assert.AreEqual(altList.Length + 1, votes.Count()); //author has a vote var anyInvalid = votes.Any(x => x.VoteValue != 0); Assert.IsFalse(anyInvalid, "Found submission votes with a non-zero vote value"); } }
public async Task <ActionResult> DeleteComment(int commentId) { if (ModelState.IsValid) { var cmd = new DeleteCommentCommand(commentId, "This feature is not yet implemented"); var result = await cmd.Execute(); if (result.Success) { if (Request.IsAjaxRequest()) { return(new HttpStatusCodeResult(HttpStatusCode.OK)); } var url = Request.UrlReferrer.AbsolutePath; return(Redirect(url)); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } //var commentToDelete = _db.Comments.Find(commentId); //if (commentToDelete != null && !commentToDelete.IsDeleted) //{ // var commentSubverse = commentToDelete.Submission.Subverse; // // delete comment if the comment author is currently logged in user // if (commentToDelete.UserName == User.Identity.Name) // { // commentToDelete.IsDeleted = true; // commentToDelete.Content = "deleted by author at " + Repository.CurrentDate; // await _db.SaveChangesAsync(); // } // // delete comment if delete request is issued by subverse moderator // else if (UserHelper.IsUserSubverseModerator(User.Identity.Name, commentSubverse)) // { // // notify comment author that his comment has been deleted by a moderator // var message = new Domain.Models.SendMessage() // { // Sender = $"v/{commentSubverse}", // Recipient = commentToDelete.UserName, // Subject = "Your comment has been deleted by a moderator", // Message = "Your [comment](/v/" + commentSubverse + "/comments/" + commentToDelete.SubmissionID + "/" + commentToDelete.ID + ") has been deleted by: " + // "/u/" + User.Identity.Name + " on: " + Repository.CurrentDate + " " + Environment.NewLine + // "Original comment content was: " + Environment.NewLine + // "---" + Environment.NewLine + // commentToDelete.Content // }; // var cmd = new SendMessageCommand(message); // await cmd.Execute(); // commentToDelete.IsDeleted = true; // // move the comment to removal log // var removalLog = new CommentRemovalLog // { // CommentID = commentToDelete.ID, // Moderator = User.Identity.Name, // Reason = "This feature is not yet implemented", // CreationDate = Repository.CurrentDate // }; // _db.CommentRemovalLogs.Add(removalLog); // commentToDelete.Content = "deleted by a moderator at " + Repository.CurrentDate; // await _db.SaveChangesAsync(); // } //} //if (Request.IsAjaxRequest()) //{ // return new HttpStatusCodeResult(HttpStatusCode.OK); //} //var url = Request.UrlReferrer.AbsolutePath; //return Redirect(url); }