Adds publishById method to contentController

This commit is contained in:
perploug
2013-10-09 15:05:27 +02:00
parent d7b732ba4b
commit 2b76d4b22d
2 changed files with 42 additions and 0 deletions

View File

@@ -531,8 +531,25 @@ function contentResource($q, $http, umbDataFormatter, umbRequestHelper) {
*/
publish: function (content, isNew, files) {
return saveContentItem(content, "publish" + (isNew ? "New" : ""), files);
},
publishById: function(id){
if (!id) {
throw "id cannot be null";
}
return umbRequestHelper.resourcePromise(
$http.post(
umbRequestHelper.getApiUrl(
"contentApiBaseUrl",
"PostPublishById",
[{ id: id }])),
'Failed to publish content with id ' + id);
}
};
}

View File

@@ -282,6 +282,30 @@ namespace Umbraco.Web.Editors
return display;
}
/// <summary>
/// Publishes a document with a given ID
/// </summary>
/// <param name="id"></param>
/// <returns></returns>
/// <remarks>
/// The CanAccessContentAuthorize attribute will deny access to this method if the current user
/// does not have Publish access to this node.
/// </remarks>
///
[EnsureUserPermissionForContent("id", 'P')]
public HttpResponseMessage PostPublishById(int id)
{
var foundContent = Services.ContentService.GetById(id);
if (foundContent == null)
{
return HandleContentNotFound(id, false);
}
Services.ContentService.Publish(foundContent, UmbracoUser.Id);
return Request.CreateResponse(HttpStatusCode.OK);
}
/// <summary>
/// Moves an item to the recycle bin, if it is already there then it will permanently delete it
/// </summary>
@@ -292,6 +316,7 @@ namespace Umbraco.Web.Editors
/// does not have Delete access to this node.
/// </remarks>
[EnsureUserPermissionForContent("id", 'D')]
[HttpDelete]
public HttpResponseMessage DeleteById(int id)
{
//TODO: We need to check if the user is allowed to do this!