Skip to content
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.Folder;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Folder;

[ApiVersion("1.0")]
public class ByKeyDocumentBlueprintFolderController : DocumentBlueprintFolderControllerBase
{
public ByKeyDocumentBlueprintFolderController(
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IContentBlueprintContainerService contentBlueprintContainerService)
: base(backOfficeSecurityAccessor, contentBlueprintContainerService)
{
}

[HttpGet("{id:guid}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(FolderResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> ByKey(CancellationToken cancellationToken, Guid id) => await GetFolderAsync(id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.Folder;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Folder;

[ApiVersion("1.0")]
public class CreateDocumentBlueprintFolderController : DocumentBlueprintFolderControllerBase
{
public CreateDocumentBlueprintFolderController(
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IContentBlueprintContainerService contentBlueprintContainerService)
: base(backOfficeSecurityAccessor, contentBlueprintContainerService)
{
}

[HttpPost]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> Create(CancellationToken cancellationToken, CreateFolderRequestModel createFolderRequestModel)
=> await CreateFolderAsync<ByKeyDocumentBlueprintFolderController>(
createFolderRequestModel,
controller => nameof(controller.ByKey));
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Folder;

[ApiVersion("1.0")]
public class DeleteDocumentBlueprintFolderController : DocumentBlueprintFolderControllerBase
{
public DeleteDocumentBlueprintFolderController(
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IContentBlueprintContainerService contentBlueprintContainerService)
: base(backOfficeSecurityAccessor, contentBlueprintContainerService)
{
}

[HttpDelete("{id:guid}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> Delete(CancellationToken cancellationToken, Guid id) => await DeleteFolderAsync(id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.Routing;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Models;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Web.Common.Authorization;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Folder;

[VersionedApiBackOfficeRoute($"{Constants.UdiEntityType.DocumentBlueprint}/folder")]
[ApiExplorerSettings(GroupName = "Document Blueprint")]
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)]
public abstract class DocumentBlueprintFolderControllerBase : FolderManagementControllerBase<IContent>
{
protected DocumentBlueprintFolderControllerBase(
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IContentBlueprintContainerService contentBlueprintContainerService)
: base(backOfficeSecurityAccessor, contentBlueprintContainerService)
{
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.Folder;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Folder;

[ApiVersion("1.0")]
public class UpdateDocumentBlueprintFolderController : DocumentBlueprintFolderControllerBase
{
public UpdateDocumentBlueprintFolderController(
IBackOfficeSecurityAccessor backOfficeSecurityAccessor,
IContentBlueprintContainerService contentBlueprintContainerService)
: base(backOfficeSecurityAccessor, contentBlueprintContainerService)
{
}

[HttpPut("{id:guid}")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> Update(CancellationToken cancellationToken, Guid id, UpdateFolderResponseModel updateFolderResponseModel)
=> await UpdateFolderAsync(id, updateFolderResponseModel);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels.DocumentBlueprint;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Security;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Cms.Web.Common.Authorization;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint;

[ApiVersion("1.0")]
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)]
public class MoveDocumentBlueprintController : DocumentBlueprintControllerBase
{
private readonly IContentBlueprintEditingService _contentBlueprintEditingService;
private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor;

public MoveDocumentBlueprintController(IContentBlueprintEditingService contentBlueprintEditingService, IBackOfficeSecurityAccessor backOfficeSecurityAccessor)
{
_contentBlueprintEditingService = contentBlueprintEditingService;
_backOfficeSecurityAccessor = backOfficeSecurityAccessor;
}

[HttpPut("{id:guid}/move")]
[MapToApiVersion("1.0")]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> Move(CancellationToken cancellationToken, Guid id, MoveDocumentBlueprintRequestModel requestModel)
{
Attempt<ContentEditingOperationStatus> result = await _contentBlueprintEditingService.MoveAsync(id, requestModel.Target?.Id, CurrentUserKey(_backOfficeSecurityAccessor));
return result.Success
? Ok()
: ContentEditingOperationStatusResult(result.Result);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Common.ViewModels.Pagination;
using Umbraco.Cms.Api.Management.Factories;
using Umbraco.Cms.Api.Management.ViewModels.Tree;
using Umbraco.Cms.Core.Services;

namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Tree;

[ApiVersion("1.0")]
public class ChildrenDocumentBlueprintTreeController : DocumentBlueprintTreeControllerBase
{
public ChildrenDocumentBlueprintTreeController(IEntityService entityService, IDocumentPresentationFactory documentPresentationFactory)
: base(entityService, documentPresentationFactory)
{
}

[HttpGet("children")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(PagedViewModel<DocumentBlueprintTreeItemResponseModel>), StatusCodes.Status200OK)]
public async Task<ActionResult<PagedViewModel<DocumentBlueprintTreeItemResponseModel>>> Children(CancellationToken cancellationToken, Guid parentId, int skip = 0, int take = 100, bool foldersOnly = false)
{
RenderFoldersOnly(foldersOnly);
return await GetChildren(parentId, skip, take);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace Umbraco.Cms.Api.Management.Controllers.DocumentBlueprint.Tree;

[VersionedApiBackOfficeRoute($"{Constants.Web.RoutePath.Tree}/{Constants.UdiEntityType.DocumentBlueprint}")]
[ApiExplorerSettings(GroupName = "Document Blueprint")]
[Authorize(Policy = AuthorizationPolicies.SectionAccessContent)]
public class DocumentBlueprintTreeControllerBase : NamedEntityTreeControllerBase<DocumentBlueprintTreeItemResponseModel>
[Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)]
public class DocumentBlueprintTreeControllerBase : FolderTreeControllerBase<DocumentBlueprintTreeItemResponseModel>
{
private readonly IDocumentPresentationFactory _documentPresentationFactory;

Expand All @@ -25,18 +25,28 @@ public DocumentBlueprintTreeControllerBase(IEntityService entityService, IDocume

protected override UmbracoObjectTypes ItemObjectType => UmbracoObjectTypes.DocumentBlueprint;

protected override DocumentBlueprintTreeItemResponseModel[] MapTreeItemViewModels(Guid? parentId, IEntitySlim[] entities)
protected override UmbracoObjectTypes FolderObjectType => UmbracoObjectTypes.DocumentBlueprintContainer;

protected override Ordering ItemOrdering
{
IDocumentEntitySlim[] documentEntities = entities
.OfType<IDocumentEntitySlim>()
.ToArray();
get
{
var ordering = Ordering.By(nameof(Infrastructure.Persistence.Dtos.NodeDto.NodeObjectType), Direction.Descending); // We need to override to change direction
ordering.Next = Ordering.By(nameof(Infrastructure.Persistence.Dtos.NodeDto.Text));

return documentEntities.Select(entity =>
return ordering;
}
}

protected override DocumentBlueprintTreeItemResponseModel[] MapTreeItemViewModels(Guid? parentId, IEntitySlim[] entities)
=> entities.Select(entity =>
{
DocumentBlueprintTreeItemResponseModel responseModel = base.MapTreeItemViewModel(parentId, entity);
responseModel.HasChildren = false;
responseModel.DocumentType = _documentPresentationFactory.CreateDocumentTypeReferenceResponseModel(entity);
DocumentBlueprintTreeItemResponseModel responseModel = MapTreeItemViewModel(parentId, entity);
if (entity is IDocumentEntitySlim documentEntitySlim)
{
responseModel.HasChildren = false;
responseModel.DocumentType = _documentPresentationFactory.CreateDocumentTypeReferenceResponseModel(documentEntitySlim);
}
return responseModel;
}).ToArray();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public RootDocumentBlueprintTreeController(IEntityService entityService, IDocume
[HttpGet("root")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(PagedViewModel<DocumentBlueprintTreeItemResponseModel>), StatusCodes.Status200OK)]
public async Task<ActionResult<PagedViewModel<DocumentBlueprintTreeItemResponseModel>>> Root(int skip = 0, int take = 100)
=> await GetRoot(skip, take);
public async Task<ActionResult<PagedViewModel<DocumentBlueprintTreeItemResponseModel>>> Root(CancellationToken cancellationToken, int skip = 0, int take = 100, bool foldersOnly = false)
{
RenderFoldersOnly(foldersOnly);
return await GetRoot(skip, take);
}
}
Loading