public async Task <Topic> UpdateTopic(PangulDbContext db, UserContext user, UpdateTopic model) { model.UserContext = user; await _updateTopic.Execute(db, model); return(await _getTopic.Execute(db, new GetTopic() { UserContext = user, TopicId = model.TopicId, IgnoreRowVersion = true, })); }
public async Task <ActionResult> UpdateTopic(PostPageModel model) { var site = await _contextService.CurrentSiteAsync(); var user = await _contextService.CurrentUserAsync(); var command = new UpdateTopic { Id = model.Topic.Id, ForumId = model.Forum.Id, Title = model.Topic.Title, Content = model.Topic.Content, Status = PostStatusType.Published, SiteId = site.Id, UserId = user.Id }; var topicInfo = await _dbContext.Posts .Where(x => x.Id == command.Id && x.TopicId == null && x.ForumId == command.ForumId && x.Forum.Category.SiteId == command.SiteId && x.Status != PostStatusType.Deleted) .Select(x => new { UserId = x.CreatedBy, x.Locked }) .FirstOrDefaultAsync(); var permissions = await _permissionModelBuilder.BuildPermissionModelsByForumId(site.Id, model.Forum.Id); var canEdit = _securityService.HasPermission(PermissionType.Edit, permissions); var canModerate = _securityService.HasPermission(PermissionType.Moderate, permissions); var authorized = (canEdit && topicInfo.UserId == user.Id && !topicInfo.Locked || canModerate) && !user.IsSuspended; if (!authorized) { _logger.LogWarning("Unauthorized access to update topic", new { SiteId = site.Id, ForumId = model.Forum?.Id, TopicId = model.Topic?.Id, User = User.Identity.Name }); return(Unauthorized()); } var slug = await _topicService.UpdateAsync(command); return(Ok(slug)); }
public Form2(ClientTopicsManager client, String pseudo, String password) { transm.AddReceiveDel(receiveMessage); this.client = client; this.pseudo = pseudo; this.password = password; this.topic = ""; this.Text = pseudo; InitializeComponent(); textChat += new UpdateChat(this.showText); textTopic += new UpdateTopic(this.showTopic); textMember += new UpdateMember(this.showMember); showTopic(); }
public async Task <string> UpdateAsync(UpdateTopic command) { await _updateValidator.ValidateCommandAsync(command); var topic = await _dbContext.Posts .FirstOrDefaultAsync(x => x.Id == command.Id && x.TopicId == null && x.ForumId == command.ForumId && x.Forum.Category.SiteId == command.SiteId && x.Status != StatusType.Deleted); if (topic == null) { throw new DataException($"Topic with Id {command.Id} not found."); } var title = Regex.Replace(command.Title, @"\s+", " "); // Remove multiple spaces from title var slug = string.IsNullOrWhiteSpace(command.Slug) ? await GenerateSlugAsync(command.ForumId, title) : command.Slug; topic.UpdateDetails(command.UserId, title, slug, command.Content, command.Status); _dbContext.Events.Add(new Event(command.SiteId, command.UserId, EventType.Updated, typeof(Post), command.Id, new { title, Slug = slug, command.Content, command.Status })); await _dbContext.SaveChangesAsync(); _cacheManager.Remove(CacheKeys.Forum(topic.ForumId)); return(slug); }
public static ResultState UpdateTopic(this DiscourseApi api, int topicId, string newTitle, int?categoryId, string apiUserName = DefaultUsername) { var path = String.Format("/t/{0}", topicId); var data = new UpdateTopic(topicId, newTitle, categoryId); var result = api.ExecuteRequest <RestResponse>(path, Method.PUT, true, apiUserName, null, data); switch (result.StatusCode) { case (HttpStatusCode)422: return(ResultState.Unchanged); case HttpStatusCode.Accepted: return(ResultState.Modified); default: return(ResultState.Error); } }