public void Delete(Post post, User user) { if (user.UserID == post.UserID || user.IsInRole(PermanentRoles.Moderator)) { var topic = _topicService.Get(post.TopicID); var forum = _forumService.Get(topic.ForumID); if (post.IsFirstInTopic) { _topicService.DeleteTopic(topic, user); } else { _moderationLogService.LogPost(user, ModerationType.PostDelete, post, String.Empty, String.Empty); post.IsDeleted = true; post.LastEditTime = DateTime.UtcNow; post.LastEditName = user.Name; post.IsEdited = true; _postRepository.Update(post); _topicService.RecalculateReplyCount(topic); _topicService.UpdateLast(topic); _forumService.UpdateCounts(forum); _forumService.UpdateLast(forum); } } else { throw new InvalidOperationException("User must be Moderator or author to delete post."); } }
public void EditPost(Post post, PostEdit postEdit, User editingUser) { // TODO: text parsing is controller for new topic and replies, see issue #121 https://github.com/POPWorldMedia/POPForums/issues/121 // TODO: also not checking for empty posts var oldText = post.FullText; post.Title = _textParsingService.Censor(postEdit.Title); if (postEdit.IsPlainText) { post.FullText = _textParsingService.ForumCodeToHtml(postEdit.FullText); } else { post.FullText = _textParsingService.ClientHtmlToHtml(postEdit.FullText); } post.ShowSig = postEdit.ShowSig; post.LastEditTime = DateTime.UtcNow; post.LastEditName = editingUser.Name; post.IsEdited = true; _postRepository.Update(post); _moderationLogService.LogPost(editingUser, ModerationType.PostEdit, post, postEdit.Comment, oldText); _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = post.TopicID }); }
public async Task <BasicServiceResponse <Post> > EditPost(int postID, PostEdit postEdit, User editingUser, Func <Post, string> redirectLinkGenerator) { var censoredNewTitle = _textParsingService.Censor(postEdit.Title); var post = await _postRepository.Get(postID); if (!editingUser.IsPostEditable(post)) { return(GetReplyFailMessage(Resources.Forbidden)); } var oldText = post.FullText; if (post.IsFirstInTopic && post.Title != censoredNewTitle) { if (string.IsNullOrEmpty(censoredNewTitle)) { return(GetReplyFailMessage(Resources.PostEmpty)); } var oldTitle = post.Title; post.Title = censoredNewTitle; var topic = await _topicRepository.Get(post.TopicID); var forum = await _forumRepository.Get(topic.ForumID); var urlName = censoredNewTitle.ToUniqueUrlName(await _topicRepository.GetUrlNamesThatStartWith(censoredNewTitle.ToUrlName())); await _topicRepository.UpdateTitleAndForum(topic.TopicID, forum.ForumID, censoredNewTitle, urlName); await _moderationLogService.LogTopic(editingUser, ModerationType.TopicRenamed, topic, forum, $"Old title: {oldTitle}"); } if (postEdit.IsPlainText) { post.FullText = _textParsingService.ForumCodeToHtml(postEdit.FullText); } else { post.FullText = _textParsingService.ClientHtmlToHtml(postEdit.FullText); } if (string.IsNullOrEmpty(postEdit.FullText)) { return(GetReplyFailMessage(Resources.PostEmpty)); } post.ShowSig = postEdit.ShowSig; post.LastEditTime = DateTime.UtcNow; post.LastEditName = editingUser.Name; post.IsEdited = true; await _postRepository.Update(post); await _moderationLogService.LogPost(editingUser, ModerationType.PostEdit, post, postEdit.Comment, oldText); await _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = post.TopicID }); var redirectLink = redirectLinkGenerator(post); return(new BasicServiceResponse <Post> { Data = post, IsSuccessful = true, Message = string.Empty, Redirect = redirectLink }); }
public void EditPost(Post post, PostEdit postEdit, User editingUser) { var oldText = post.FullText; post.Title = _textParsingService.EscapeHtmlAndCensor(postEdit.Title); if (postEdit.IsPlainText) { post.FullText = _textParsingService.ForumCodeToHtml(postEdit.FullText); } else { post.FullText = _textParsingService.ClientHtmlToHtml(postEdit.FullText); } post.ShowSig = postEdit.ShowSig; post.LastEditTime = DateTime.UtcNow; post.LastEditName = editingUser.Name; post.IsEdited = true; _postRepository.Update(post); _moderationLogService.LogPost(editingUser, ModerationType.PostEdit, post, postEdit.Comment, oldText); }
public async Task Delete(Post post, User user) { if (user.UserID == post.UserID || user.IsInRole(PermanentRoles.Moderator)) { var topic = await _topicService.Get(post.TopicID); var forum = await _forumService.Get(topic.ForumID); if (post.IsFirstInTopic) { await _topicService.DeleteTopic(topic, user); } else { await _moderationLogService.LogPost(user, ModerationType.PostDelete, post, String.Empty, String.Empty); post.IsDeleted = true; post.LastEditTime = DateTime.UtcNow; post.LastEditName = user.Name; post.IsEdited = true; await _postRepository.Update(post); await _topicService.RecalculateReplyCount(topic); await _topicService.UpdateLast(topic); _forumService.UpdateCounts(forum); await _forumService.UpdateLast(forum); await _searchIndexQueueRepository.Enqueue(new SearchIndexPayload { TenantID = _tenantService.GetTenant(), TopicID = topic.TopicID }); } } else { throw new InvalidOperationException("User must be Moderator or author to delete post."); } }