public void CreateTopic_NoPermission() { var contract = new DiscussionTopicContract { Author = new UserWithIconContract { Id = 2 }, Name = "New topic", Content = "Content" }; queries.CreateTopic(folder.Id, contract); }
public void CreateTopic_NoPermission() { var contract = new DiscussionTopicContract { Author = new UserForApiContract { Id = 2 }, Name = "New topic", Content = "Content" }; _queries.Invoking(subject => subject.CreateTopic(_folder.Id, contract)).Should().Throw <NotAllowedException>(); }
public void UpdateTopic(int topicId, DiscussionTopicContract contract) { PermissionContext.VerifyPermission(PermissionToken.CreateComments); repository.HandleTransaction(ctx => { var topic = ctx.OfType <DiscussionTopic>().Load(topicId); PermissionContext.VerifyAccess(topic, EntryPermissionManager.CanEdit); topic.Name = contract.Name; topic.Content = contract.Content; ctx.Update(topic); ctx.AuditLogger.AuditLog("updated " + topic); }); }
/// <summary> /// /// </summary> /// <param name="folderId"></param> /// <param name="contract"></param> /// <returns>DiscussionTopicContract</returns> public DiscussionTopicContract DiscussionApiPostNewTopic(int?folderId, DiscussionTopicContract contract) { // verify the required parameter 'folderId' is set if (folderId == null) { throw new ApiException(400, "Missing required parameter 'folderId' when calling DiscussionApiPostNewTopic"); } // verify the required parameter 'contract' is set if (contract == null) { throw new ApiException(400, "Missing required parameter 'contract' when calling DiscussionApiPostNewTopic"); } var path = "/api/discussions/folders/{folderId}/topics"; path = path.Replace("{format}", "json"); path = path.Replace("{" + "folderId" + "}", ApiClient.ParameterToString(folderId)); var queryParams = new Dictionary <String, String>(); var headerParams = new Dictionary <String, String>(); var formParams = new Dictionary <String, String>(); var fileParams = new Dictionary <String, FileParameter>(); String postBody = null; postBody = ApiClient.Serialize(contract); // http body (model) parameter // authentication setting, if any String[] authSettings = new String[] { }; // make the HTTP request IRestResponse response = (IRestResponse)ApiClient.CallApi(path, Method.POST, queryParams, postBody, headerParams, formParams, fileParams, authSettings); if (((int)response.StatusCode) >= 400) { throw new ApiException((int)response.StatusCode, "Error calling DiscussionApiPostNewTopic: " + response.Content, response.Content); } else if (((int)response.StatusCode) == 0) { throw new ApiException((int)response.StatusCode, "Error calling DiscussionApiPostNewTopic: " + response.ErrorMessage, response.ErrorMessage); } return((DiscussionTopicContract)ApiClient.Deserialize(response.Content, typeof(DiscussionTopicContract), response.Headers)); }
public void CreateTopic() { var contract = new DiscussionTopicContract { Author = new UserWithIconContract(user), Name = "New topic", Content = "Content" }; var result = queries.CreateTopic(folder.Id, contract); Assert.AreNotEqual(0, result.Id, "Id was assigned"); Assert.AreEqual(1, repo.List <DiscussionTopic>().Count, "Number of discussion topics in repo"); Assert.AreEqual(1, folder.AllTopics.Count, "Topic was added to folder"); Assert.IsTrue(result.Id == folder.AllTopics.First().Id, "Topic Id in folder matches returned topic ID"); var topicInRepo = repo.List <DiscussionTopic>().First(); Assert.IsTrue(result.Id == topicInRepo.Id, "Persisted topic ID matches returned topic ID"); Assert.AreEqual("New topic", topicInRepo.Name, "Name"); Assert.AreEqual("Content", topicInRepo.Content, "Content"); }
public void CreateTopic() { var contract = new DiscussionTopicContract { Author = new UserForApiContract(_user), Name = "New topic", Content = "Content" }; var result = _queries.CreateTopic(_folder.Id, contract); result.Id.Should().NotBe(0, "Id was assigned"); _repo.List <DiscussionTopic>().Count.Should().Be(1, "Number of discussion topics in repo"); _folder.AllTopics.Count.Should().Be(1, "Topic was added to folder"); (result.Id == _folder.AllTopics.First().Id).Should().BeTrue("Topic Id in folder matches returned topic ID"); var topicInRepo = _repo.List <DiscussionTopic>().First(); (result.Id == topicInRepo.Id).Should().BeTrue("Persisted topic ID matches returned topic ID"); topicInRepo.Name.Should().Be("New topic", "Name"); topicInRepo.Content.Should().Be("Content", "Content"); }
public DiscussionTopicContract CreateTopic(int folderId, DiscussionTopicContract contract) { PermissionContext.VerifyPermission(PermissionToken.CreateComments); if (contract.Author == null || contract.Author.Id != PermissionContext.LoggedUserId) { throw new NotAllowedException("Can only post as self"); } return(repository.HandleTransaction(ctx => { var folder = ctx.Load(folderId); var agent = ctx.OfType <User>().CreateAgentLoginData(PermissionContext, ctx.OfType <User>().Load(contract.Author.Id)); var topic = new DiscussionTopic(folder, contract.Name, contract.Content, agent); folder.AllTopics.Add(topic); ctx.Save(topic); ctx.AuditLogger.AuditLog("created " + topic, agent); return new DiscussionTopicContract(topic, userIconFactory, DiscussionTopicOptionalFields.None); })); }
public void UpdateTopic(int topicId, DiscussionTopicContract contract) { PermissionContext.VerifyPermission(PermissionToken.CreateComments); _repository.HandleTransaction(ctx => { var topic = ctx.OfType <DiscussionTopic>().Load(topicId); PermissionContext.VerifyAccess(topic, EntryPermissionManager.CanEdit); if (topic.Folder.Id != contract.FolderId && PermissionContext.HasPermission(PermissionToken.DeleteComments)) { MoveTopic(ctx, topic, contract.FolderId); } topic.Locked = contract.Locked; topic.Name = contract.Name; topic.FirstComment.Message = contract.Content; ctx.Update(topic); ctx.AuditLogger.AuditLog("updated " + topic); }); }
public DiscussionTopicContract PostNewTopic(int folderId, DiscussionTopicContract contract) => _queries.CreateTopic(folderId, contract);
public void PostEditTopic(int topicId, DiscussionTopicContract contract) => _queries.UpdateTopic(topicId, contract);
public DiscussionTopicContract PostNewTopic(int folderId, DiscussionTopicContract contract) { return(queries.CreateTopic(folderId, contract)); }