2018-12-06 09:54:21 +00:00
|
|
|
|
using System.Collections.Generic;
|
2018-12-06 11:21:28 +00:00
|
|
|
|
using System.Linq;
|
2018-12-06 09:54:21 +00:00
|
|
|
|
using System.Net;
|
|
|
|
|
|
using System.Net.Http;
|
2018-12-06 13:54:38 +00:00
|
|
|
|
using System.Net.Http.Formatting;
|
2018-12-06 09:50:05 +00:00
|
|
|
|
using System.Web.Http;
|
2019-01-10 12:44:57 +11:00
|
|
|
|
using Umbraco.Core.Models.Packaging;
|
|
|
|
|
|
using Umbraco.Web.Models.ContentEditing;
|
2018-12-06 09:50:05 +00:00
|
|
|
|
using Umbraco.Web.Mvc;
|
2018-12-06 13:54:38 +00:00
|
|
|
|
using Umbraco.Web.WebApi;
|
2018-12-06 09:50:05 +00:00
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
2019-01-10 12:44:57 +11:00
|
|
|
|
using Umbraco.Web._Legacy.Packager.PackageInstance;
|
2018-12-06 09:50:05 +00:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Editors
|
|
|
|
|
|
{
|
2018-12-06 10:18:31 +00:00
|
|
|
|
//TODO: Packager stuff still lives in business logic - YUK
|
|
|
|
|
|
|
2018-12-06 09:50:05 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// A controller used for installing packages and managing all of the data in the packages section in the back office
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[PluginController("UmbracoApi")]
|
2018-12-06 13:54:38 +00:00
|
|
|
|
[SerializeVersion]
|
2018-12-06 09:50:05 +00:00
|
|
|
|
[UmbracoApplicationAuthorize(Core.Constants.Applications.Packages)]
|
|
|
|
|
|
public class PackageController : UmbracoAuthorizedJsonController
|
|
|
|
|
|
{
|
2019-01-10 12:44:57 +11:00
|
|
|
|
public List<PackageDefinition> GetCreatedPackages()
|
2018-12-06 09:50:05 +00:00
|
|
|
|
{
|
2018-12-06 11:21:28 +00:00
|
|
|
|
return CreatedPackage.GetAllCreatedPackages().Select(x => x.Data).ToList();
|
2018-12-06 09:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
public PackageDefinition GetCreatedPackageById(int id)
|
2018-12-06 09:50:05 +00:00
|
|
|
|
{
|
2018-12-07 10:22:33 +00:00
|
|
|
|
var package = CreatedPackage.GetById(id);
|
|
|
|
|
|
if (package == null)
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
|
|
|
|
|
|
return package.Data;
|
2018-12-06 09:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
public PackageDefinition PostUpdatePackage(PackageDefinition model)
|
2018-12-06 10:18:31 +00:00
|
|
|
|
{
|
2019-01-10 12:44:57 +11:00
|
|
|
|
var package = CreatedPackage.GetById(model.Id);
|
|
|
|
|
|
if (package == null)
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
|
2018-12-07 10:22:33 +00:00
|
|
|
|
if (ModelState.IsValid == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Throw/bubble up errors
|
2019-01-10 12:44:57 +11:00
|
|
|
|
throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState));
|
2018-12-07 10:22:33 +00:00
|
|
|
|
}
|
2018-12-07 10:37:33 +00:00
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
package.Data = model;
|
2018-12-07 10:22:33 +00:00
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
//We should have packagepath populated now
|
|
|
|
|
|
return package.Data;
|
|
|
|
|
|
}
|
2018-12-06 14:41:53 +00:00
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
public PackageDefinition PostCreatePackage(PackageDefinition model)
|
|
|
|
|
|
{
|
|
|
|
|
|
//creating requires an empty model/package id
|
|
|
|
|
|
if (model.Id != 0 || model.PackageGuid != null)
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
|
|
|
|
|
|
if (ModelState.IsValid == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
//Throw/bubble up errors
|
|
|
|
|
|
throw new HttpResponseException(Request.CreateValidationErrorResponse(ModelState));
|
2018-12-07 10:37:33 +00:00
|
|
|
|
}
|
2018-12-06 11:21:28 +00:00
|
|
|
|
|
2019-01-10 12:44:57 +11:00
|
|
|
|
//save it
|
|
|
|
|
|
Services.PackagingService.SavePackageDefinition(model);
|
|
|
|
|
|
|
|
|
|
|
|
//then publish to get the file
|
|
|
|
|
|
//package.Publish();
|
|
|
|
|
|
//TODO: We need a link to the downloadable zip file, in packagepath ?
|
|
|
|
|
|
|
|
|
|
|
|
return model;
|
2018-12-06 10:18:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-06 13:09:34 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Deletes a created package
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="packageId"></param>
|
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
|
[HttpPost]
|
2018-12-06 09:54:21 +00:00
|
|
|
|
[HttpDelete]
|
2018-12-06 13:09:34 +00:00
|
|
|
|
public IHttpActionResult DeleteCreatedPackage(int packageId)
|
2018-12-06 09:54:21 +00:00
|
|
|
|
{
|
2018-12-06 13:09:34 +00:00
|
|
|
|
var package = CreatedPackage.GetById(packageId);
|
|
|
|
|
|
if (package == null)
|
|
|
|
|
|
return NotFound();
|
|
|
|
|
|
|
2018-12-06 09:54:21 +00:00
|
|
|
|
package.Delete();
|
|
|
|
|
|
|
2018-12-06 13:09:34 +00:00
|
|
|
|
return Ok();
|
2018-12-06 09:54:21 +00:00
|
|
|
|
}
|
2018-12-06 13:09:34 +00:00
|
|
|
|
|
2018-12-06 09:50:05 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|