public virtual PartialViewResult Edit(CommentEditModel model) { var editCommentId = FullContext.Value.EntityId.Value; var commentsTarget = FullContext.GetCommentsTarget(); var targetEntityId = commentsTarget.EntityId.Value; if (!ModelState.IsValid) { return(OverView(editCommentId)); } var comment = _commentsService.Get(editCommentId); if (!_commentsService.CanEdit(comment, _intranetUserService.GetCurrentUserId())) { return(OverView(editCommentId)); } var editDto = MapToEditDto(model, editCommentId); var command = new EditCommentCommand(FullContext, editDto); _commandPublisher.Publish(command); switch (commentsTarget.Type.ToInt()) { case int type when ContextExtensions.HasFlagScalar(type, ContextType.Activity | ContextType.PagePromotion): var activityCommentsInfo = GetActivityComments(targetEntityId); return(OverView(activityCommentsInfo)); default: return(OverView(comment.ActivityId)); } }
public BroadcastResult Handle(EditCommentCommand command) { _commentsService.Update(command.EditDto); UpdateCache(command.TargetType, command.TargetId); return(BroadcastResult.Success); }
public async Task <CommentsOverviewModel> Edit(CommentEditModel model) { var comment = await _commentsService.GetAsync(model.Id); if (!_commentsService.CanEdit(comment, await _intranetMemberService.GetCurrentMemberIdAsync())) { return(await _commentsHelper.OverViewAsync(model.Id)); } var editDto = MapToEditDto(model, model.Id); var command = new EditCommentCommand(model.EntityId, model.EntityType, editDto); _commandPublisher.Publish(command); await OnCommentEditedAsync(model.Id, model.EntityType); switch (model.EntityType) { case IntranetEntityTypeEnum type when type.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events): var activityCommentsInfo = GetActivityComments(model.EntityId); return(await _commentsHelper.OverViewAsync(activityCommentsInfo.Id, activityCommentsInfo.Comments, activityCommentsInfo.IsReadOnly)); default: return(await _commentsHelper.OverViewAsync(comment.ActivityId)); } }
public void Handle(EditCommentCommand command) { //Lesson lesson = repo.GetById<Lesson>(command.Id, command.Version); Lesson lesson = repo.GetById <Lesson>(command.Id); lesson.EditComment(command.CommentId, command.Content, command.Date); repo.Save(lesson, Guid.NewGuid()); }
public BroadcastResult Handle(EditCommentCommand command) { var commentsTarget = command.Context.GetCommentsTarget(); _commentsService.Update(command.EditDto); UpdateCache(commentsTarget.Type, commentsTarget.EntityId.Value); return(BroadcastResult.Success); }
public async Task EditComment_IsSuccessful() { var commentId = await CreateDefaultCommentAsync(); var command = new EditCommentCommand(commentId, "edit text"); await _fixture.Mediator.Send(command); var comment = await _commentQuery.GetCommentAsync(commentId); Assert.Equal(command.Text, comment.Text); }
public void CreateInstance_WhenConstructorsArgumentsAreNotNull() { //arrange var context = new Mock <IStoreContext>(); var writer = new Mock <IWriter>(); var reader = new Mock <IReader>(); //act var testcommand = new EditCommentCommand(context.Object, writer.Object, reader.Object); //assert Assert.IsNotNull(testcommand); }
public BroadcastResult Handle(EditCommentCommand command) { var commentsTarget = command.Context.GetCommentsTarget(); var commentsTargetEntityId = commentsTarget.EntityId.Value; if (ContextExtensions.HasFlagScalar(commentsTarget.Type, ContextType.Activity)) { var notifiableService = _activitiesServiceFactory.GetNotifyableService(commentsTargetEntityId); notifiableService.Notify(command.EditDto.Id, NotificationTypeEnum.CommentEdited); } return(BroadcastResult.Success); }
private CommandResponse ExecuteEditComment(EditCommentCommand command) { var existingComment = Questions.SelectMany(q => q.Comments).Concat(Questions.SelectMany(q => q.Answers.SelectMany(a => a.Comments))) .SingleOrDefault(c => c.Id == command.CommentId); if (existingComment == null) { return(CommandResponse.Failure($"Comment with id {command.CommentId} does not exist.")); } existingComment.Text = command.Text; return(CommandResponse.Success(existingComment)); }
public void EditComment_Empty() { var user = TestHelper.SetPrincipal("TestUser11"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); var editCmd = new EditCommentCommand(c.Response.ID, " ").SetUserContext(user); var editResult = editCmd.Execute().Result; Assert.IsFalse(editResult.Success, editResult.Message); Assert.AreEqual("Empty comments not allowed", editResult.Message); }
public void EditComment_BannedDomain() { var user = TestHelper.SetPrincipal("TestUser02"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); var editCmd = new EditCommentCommand(c.Response.ID, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!").SetUserContext(user); var editResult = editCmd.Execute().Result; VoatAssert.IsValid(editResult, Status.Denied, "Expecting Denied Status"); Assert.AreEqual("Comment contains banned domains", editResult.Message); }
public BroadcastResult Handle(EditCommentCommand command) { var commentsTargetEntityId = command.TargetId; if (!command.TargetType.Is(IntranetEntityTypeEnum.News, IntranetEntityTypeEnum.Social, IntranetEntityTypeEnum.Events)) { return(BroadcastResult.Success); } var notifiableService = _activitiesServiceFactory.GetNotifyableService(commentsTargetEntityId); notifiableService.Notify(command.EditDto.Id, NotificationTypeEnum.CommentEdited); return(BroadcastResult.Success); }
public void EditComment_WrongOwner() { TestHelper.SetPrincipal("TestUser15"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it."); var c = cmd.Execute().Result; Assert.IsTrue(c.Success, c.Message); TestHelper.SetPrincipal("TestUser12"); var editCmd = new EditCommentCommand(c.Response.ID, "All your comment are belong to us!"); var editResult = editCmd.Execute().Result; Assert.IsFalse(editResult.Success, editResult.Message); Assert.AreEqual("User doesn't have permissions to perform requested action", editResult.Message); }
public void EditComment_WrongOwner() { var user = TestHelper.SetPrincipal("TestUser15"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it.").SetUserContext(user); var c = cmd.Execute().Result; VoatAssert.IsValid(c); user = TestHelper.SetPrincipal("TestUser12"); var editCmd = new EditCommentCommand(c.Response.ID, "All your comment are belong to us!").SetUserContext(user); var editResult = editCmd.Execute().Result; VoatAssert.IsValid(editResult, Status.Denied); Assert.AreEqual("User does not have permissions to perform requested action", editResult.Message); }
public void EditComment_BannedDomain() { TestHelper.SetPrincipal("TestUser2"); var cmd = new CreateCommentCommand(1, null, "This is a unit test and I like it."); var c = cmd.Execute().Result; Assert.IsTrue(c.Success); var editCmd = new EditCommentCommand(c.Response.ID, "[Check out this killer website](http://fleddit.com/f/3hen3k/Look_at_this_cat_just_Looook_awww)!"); var editResult = editCmd.Execute().Result; Assert.IsFalse(editResult.Success, "Edit command with banned domain returned true"); Assert.AreEqual(Status.Denied, editResult.Status, "expecting denied status"); Assert.AreEqual("Comment contains banned domains", editResult.Message); }
private void InvalidateCommands() { EditFeeScheuleCommand.RaiseCanExecuteChanged(); SaveCommand.RaiseCanExecuteChanged(); PrintCommand.RaiseCanExecuteChanged(); CancelCommand.RaiseCanExecuteChanged(); DeleteCommand.RaiseCanExecuteChanged(); EditAttributeCommand.RaiseCanExecuteChanged(); DeleteAttributeCommand.RaiseCanExecuteChanged(); DeleteFeeScheuleCommand.RaiseCanExecuteChanged(); NewOrderCommand.RaiseCanExecuteChanged(); EditContactCommand.RaiseCanExecuteChanged(); DeleteContactCommand.RaiseCanExecuteChanged(); EditEmployeeCommand.RaiseCanExecuteChanged(); DeleteEmployeeCommand.RaiseCanExecuteChanged(); EditCommentCommand.RaiseCanExecuteChanged(); DeleteCommentCommand.RaiseCanExecuteChanged(); }
public async Task <ActionResult> EditComment([FromBody()] CommentEditInput commentModel) { if (ModelState.IsValid) { var cmd = new EditCommentCommand(commentModel.ID, commentModel.Content).SetUserContext(User); var result = await cmd.Execute(); if (!result.Success) { PreventSpamAttribute.Reset(HttpContext); } return(JsonResult(result)); } else { PreventSpamAttribute.Reset(HttpContext); return(JsonResult(CommandResponse.FromStatus(Status.Error, ModelState.GetFirstErrorMessage()))); } }
public async Task EditComment() { string content = "This is data [howdy](http://www.howdy.com)"; var user = TestHelper.SetPrincipal(USERNAMES.Unit); var cmd = new EditCommentCommand(1, content).SetUserContext(user); var r = await cmd.Execute(); VoatAssert.IsValid(r); Assert.AreEqual(content, r.Response.Content); Assert.AreEqual(Formatting.FormatMessage(content), r.Response.FormattedContent); //verify using (var db = new Voat.Data.Repository(user)) { var comment = await db.GetComment(1); Assert.IsNotNull(comment.LastEditDate); Assert.AreEqual(cmd.Content, comment.Content); } }
public async Task Comment_Length_Validations() { var user = TestHelper.SetPrincipal("TestUser20"); var createCmd = new CreateCommentCommand(1, null, "Can you hear me now?".RepeatUntil(10001)).SetUserContext(user); var r = await createCmd.Execute(); VoatAssert.IsValid(r, Status.Denied); createCmd = new CreateCommentCommand(1, null, "Can you hear me now?").SetUserContext(user); r = await createCmd.Execute(); VoatAssert.IsValid(r); var editCmd = new EditCommentCommand(r.Response.ID, "Can you hear me now?".RepeatUntil(100001)).SetUserContext(user); r = await editCmd.Execute(); VoatAssert.IsValid(r, Status.Denied); }
public void EditComment() { string content = "This is data [howdy](http://www.howdy.com)"; TestHelper.SetPrincipal("unit"); var cmd = new EditCommentCommand(1, content); var r = cmd.Execute().Result; Assert.IsTrue(r.Success); Assert.AreEqual(content, r.Response.Content); Assert.AreEqual(Formatting.FormatMessage(content), r.Response.FormattedContent); //verify using (var db = new Voat.Data.Repository()) { var comment = db.GetComment(1); Assert.IsNotNull(comment.LastEditDate); Assert.AreEqual(cmd.Content, comment.Content); } }
public async Task <ActionResult> EditComment([Bind(Include = "ID, Content")] Data.Models.Comment commentModel) { if (ModelState.IsValid) { var cmd = new EditCommentCommand(commentModel.ID, commentModel.Content); var result = await cmd.Execute(); if (result.Success) { return(Json(new { response = result.Response.FormattedContent })); } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest, result.Message)); } } else { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } // var existingComment = _db.Comments.Find(commentModel.ID); // if (existingComment != null) // { // if (existingComment.UserName.Trim() == User.Identity.Name && !existingComment.IsDeleted) // { // bool containsBannedDomain = BanningUtility.ContentContainsBannedDomain(existingComment.Submission.Subverse, commentModel.Content); // if (containsBannedDomain) // { // return new HttpStatusCodeResult(HttpStatusCode.BadRequest, "Comment contains links to banned domain(s)."); // } // existingComment.LastEditDate = Repository.CurrentDate; // existingComment.Content = commentModel.Content; // if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPreSave)) // { // existingComment.Content = ContentProcessor.Instance.Process(existingComment.Content, ProcessingStage.InboundPreSave, existingComment); // } // //save fully formatted content // var formattedComment = Voat.Utilities.Formatting.FormatMessage(existingComment.Content); // existingComment.FormattedContent = formattedComment; // await _db.SaveChangesAsync(); // //HACK: Update comment in cache - to be replaced with EditCommentCommand in future // string key = CachingKey.CommentTree(existingComment.SubmissionID.Value); // if (CacheHandler.Instance.Exists(key)) // { // CacheHandler.Instance.Replace<usp_CommentTree_Result>(key, existingComment.ID, x => { // x.Content = existingComment.Content; // x.FormattedContent = existingComment.FormattedContent; // return x; // }); // } // if (ContentProcessor.Instance.HasStage(ProcessingStage.InboundPostSave)) // { // ContentProcessor.Instance.Process(existingComment.Content, ProcessingStage.InboundPostSave, existingComment); // } // //return the formatted comment so that it can replace the existing html comment which just got modified // return Json(new { response = formattedComment }); // } // return Json("Unauthorized edit.", JsonRequestBehavior.AllowGet); // } //} //if (Request.IsAjaxRequest()) //{ // return new HttpStatusCodeResult(HttpStatusCode.BadRequest); //} //return Json("Unauthorized edit or comment not found - comment ID was.", JsonRequestBehavior.AllowGet); }
/// <inheritdoc cref="IRequestHandler{TRequest,TResponse}.Handle" /> public Task <IRequestResult <Comment> > Handle(EditCommentCommand request, CancellationToken cancellationToken) { throw new System.NotImplementedException(); }
public async Task <ActionResult> Edit(int id, EditCommentCommand command) => await this.Send(command.SetId(id));