public void ApproveShouldUpdateCommentStatus() { var commentedItem = _contentManager.New("commentedItem"); _contentManager.Create(commentedItem); _contentManager.Create(commentedItem, VersionOptions.Published); int commentId = commentedItem.As<CommentPart>().Id; _commentService.ApproveComment(commentId); Assert.That(_commentService.GetComment(commentId).Record.Status, Is.EqualTo(CommentStatus.Approved)); }
public ActionResult Index(FormCollection input) { var viewModel = new CommentsIndexViewModel { Comments = new List <CommentEntry>(), Options = new CommentIndexOptions() }; UpdateModel(viewModel); IEnumerable <CommentEntry> checkedEntries = viewModel.Comments.Where(c => c.IsChecked); switch (viewModel.Options.BulkAction) { case CommentIndexBulkAction.None: break; case CommentIndexBulkAction.Unapprove: if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { return(new HttpUnauthorizedResult()); } //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.UnapproveComment(entry.Comment.Id); } break; case CommentIndexBulkAction.Approve: if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { return(new HttpUnauthorizedResult()); } //TODO: Transaction foreach (CommentEntry entry in checkedEntries) { _commentService.ApproveComment(entry.Comment.Id); } break; case CommentIndexBulkAction.Delete: if (!_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment"))) { return(new HttpUnauthorizedResult()); } foreach (CommentEntry entry in checkedEntries) { _commentService.DeleteComment(entry.Comment.Id); } break; default: throw new ArgumentOutOfRangeException(); } return(RedirectToAction("Index")); }
public ActionResult Approve(string nonce) { int id; if (_commentService.DecryptNonce(nonce, out id)) { _commentService.ApproveComment(id); } Services.Notifier.Success(T("Comment approved successfully")); return(Redirect("~/")); }
public ContentItem Import(ImportSettings importSettings, object objectToImport, IContent parentContent) { Comments commentsToImport = (Comments)objectToImport; foreach (var commentToImport in commentsToImport.CommentList) { var author = (commentToImport.UserName ?? string.Empty).Truncate(255); var dateCreated = commentToImport.DateCreated; var comment = _commentService.GetCommentsForCommentedContent(parentContent.Id) .Where(o => o.Author == author) .List() .FirstOrDefault(o => o.Record.CommentDateUtc.HasValue && o.Record.CommentDateUtc.Value.Equals(dateCreated)); if (comment != null) { return(comment.ContentItem); } else { comment = _orchardServices.ContentManager.New <CommentPart>("Comment"); } comment.Author = author; comment.CommentText = (_dataCleaner.Clean(commentToImport.Content.Value, importSettings) ?? string.Empty).Truncate(10000); comment.Email = (commentToImport.UserEmail ?? string.Empty).Truncate(255); comment.SiteName = (commentToImport.UserURL ?? string.Empty).Truncate(255); comment.CommentedOn = parentContent.Id; comment.CommentDateUtc = dateCreated; comment.UserName = (commentToImport.UserName ?? "Anonymous").Truncate(255); if (parentContent.As <CommentsPart>().Record.CommentPartRecords == null) { parentContent.As <CommentsPart>().Record.CommentPartRecords = new List <CommentPartRecord>(); } _orchardServices.ContentManager.Create(comment); if (commentToImport.Approved) { _commentService.ApproveComment(comment.Id); } } return(null); }
// POST protected override DriverResult Editor(CommentPart part, IUpdateModel updater, dynamic shapeHelper) { updater.TryUpdateModel(part, Prefix, null, null); var workContext = _workContextAccessor.GetContext(); // applying moderate/approve actions var httpContext = workContext.HttpContext; var name = httpContext.Request.Form["submit.Save"]; if (!string.IsNullOrEmpty(name) && String.Equals(name, "moderate", StringComparison.OrdinalIgnoreCase)) { if (_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't moderate comment"))) { _commentService.UnapproveComment(part.Id); _orchardServices.Notifier.Information(T("Comment successfully moderated.")); return(Editor(part, shapeHelper)); } } if (!string.IsNullOrEmpty(name) && String.Equals(name, "approve", StringComparison.OrdinalIgnoreCase)) { if (_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't approve comment"))) { _commentService.ApproveComment(part.Id); _orchardServices.Notifier.Information(T("Comment approved.")); return(Editor(part, shapeHelper)); } } if (!string.IsNullOrEmpty(name) && String.Equals(name, "delete", StringComparison.OrdinalIgnoreCase)) { if (_orchardServices.Authorizer.Authorize(Permissions.ManageComments, T("Couldn't delete comment"))) { _commentService.DeleteComment(part.Id); _orchardServices.Notifier.Information(T("Comment successfully deleted.")); return(Editor(part, shapeHelper)); } } // if editing from the admin, don't update the owner or the status if (!string.IsNullOrEmpty(name) && String.Equals(name, "save", StringComparison.OrdinalIgnoreCase)) { _orchardServices.Notifier.Information(T("Comment saved.")); return(Editor(part, shapeHelper)); } part.CommentDateUtc = _clock.UtcNow; if (!String.IsNullOrEmpty(part.SiteName) && !part.SiteName.StartsWith("http://") && !part.SiteName.StartsWith("https://")) { part.SiteName = "http://" + part.SiteName; } var currentUser = workContext.CurrentUser; part.UserName = (currentUser != null ? currentUser.UserName : null); if (currentUser != null) { part.Author = currentUser.UserName; } var moderateComments = workContext.CurrentSite.As <CommentSettingsPart>().ModerateComments; part.Status = moderateComments ? CommentStatus.Pending : CommentStatus.Approved; var commentedOn = _contentManager.Get <ICommonPart>(part.CommentedOn); // prevent users from commenting on a closed thread by hijacking the commentedOn property var commentsPart = commentedOn.As <CommentsPart>(); if (!commentsPart.CommentsActive) { _orchardServices.TransactionManager.Cancel(); return(Editor(part, shapeHelper)); } if (commentedOn != null && commentedOn.Container != null) { part.CommentedOnContainer = commentedOn.Container.ContentItem.Id; } commentsPart.Record.CommentPartRecords.Add(part.Record); return(Editor(part, shapeHelper)); }