Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels;
using Umbraco.Cms.Api.Management.ViewModels.DocumentType;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;

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

[ApiVersion("1.0")]
public class AllowedParentsDocumentTypeController : DocumentTypeControllerBase
{
private readonly IContentTypeService _contentTypeService;

public AllowedParentsDocumentTypeController(IContentTypeService contentTypeService)
{
_contentTypeService = contentTypeService;
}

[HttpGet("{id:guid}/allowed-parents")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(DocumentTypeAllowedParentsResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> AllowedParentsByKey(
CancellationToken cancellationToken,
Guid id)
{
Attempt<IEnumerable<Guid>, ContentTypeOperationStatus> attempt = await _contentTypeService.GetAllowedParentKeysAsync(id);
if (attempt.Success is false)
{
return OperationStatusResult(attempt.Status);
}

var model = new DocumentTypeAllowedParentsResponseModel
{
AllowedParentIds = (attempt.Result ?? []).Select(x => new ReferenceByIdModel(x)).ToHashSet(),
};

return Ok(model);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using Asp.Versioning;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Umbraco.Cms.Api.Management.ViewModels;
using Umbraco.Cms.Api.Management.ViewModels.MediaType;
using Umbraco.Cms.Core;
using Umbraco.Cms.Core.Services;
using Umbraco.Cms.Core.Services.OperationStatus;

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

[ApiVersion("1.0")]
public class AllowedParentsMediaTypeController : MediaTypeControllerBase
{
private readonly IMediaTypeService _mediaTypeService;

public AllowedParentsMediaTypeController(IMediaTypeService mediaTypeService)
{
_mediaTypeService = mediaTypeService;
}

[HttpGet("{id:guid}/allowed-parents")]
[MapToApiVersion("1.0")]
[ProducesResponseType(typeof(MediaTypeAllowedParentsResponseModel), StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)]
public async Task<IActionResult> AllowedParentsByKey(
CancellationToken cancellationToken,
Guid id)
{
Attempt<IEnumerable<Guid>, ContentTypeOperationStatus> attempt = await _mediaTypeService.GetAllowedParentKeysAsync(id);
if (attempt.Success is false)
{
return OperationStatusResult(attempt.Status);
}

var model = new MediaTypeAllowedParentsResponseModel
{
AllowedParentIds = (attempt.Result ?? []).Select(x => new ReferenceByIdModel(x)).ToHashSet(),
};

return Ok(model);
}
}
160 changes: 160 additions & 0 deletions src/Umbraco.Cms.Api.Management/OpenApi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4940,6 +4940,66 @@
]
}
},
"/umbraco/management/api/v1/document-type/{id}/allowed-parents": {
"get": {
"tags": [
"Document Type"
],
"operationId": "GetDocumentTypeByIdAllowedParents",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/DocumentTypeAllowedParentsResponseModel"
}
]
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/ProblemDetails"
}
]
}
}
}
},
"401": {
"description": "The resource is protected and requires an authentication token"
},
"403": {
"description": "The authenticated user does not have access to this resource"
}
},
"security": [
{
"Backoffice-User": [ ]
}
]
}
},
"/umbraco/management/api/v1/document-type/{id}/blueprint": {
"get": {
"tags": [
Expand Down Expand Up @@ -14812,6 +14872,66 @@
]
}
},
"/umbraco/management/api/v1/media-type/{id}/allowed-parents": {
"get": {
"tags": [
"Media Type"
],
"operationId": "GetMediaTypeByIdAllowedParents",
"parameters": [
{
"name": "id",
"in": "path",
"required": true,
"schema": {
"type": "string",
"format": "uuid"
}
}
],
"responses": {
"200": {
"description": "OK",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/MediaTypeAllowedParentsResponseModel"
}
]
}
}
}
},
"404": {
"description": "Not Found",
"content": {
"application/json": {
"schema": {
"oneOf": [
{
"$ref": "#/components/schemas/ProblemDetails"
}
]
}
}
}
},
"401": {
"description": "The resource is protected and requires an authentication token"
},
"403": {
"description": "The authenticated user does not have access to this resource"
}
},
"security": [
{
"Backoffice-User": [ ]
}
]
}
},
"/umbraco/management/api/v1/media-type/{id}/composition-references": {
"get": {
"tags": [
Expand Down Expand Up @@ -40227,6 +40347,26 @@
},
"additionalProperties": false
},
"DocumentTypeAllowedParentsResponseModel": {
"required": [
"allowedParentIds"
],
"type": "object",
"properties": {
"allowedParentIds": {
"uniqueItems": true,
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/ReferenceByIdModel"
}
]
}
}
},
"additionalProperties": false
},
"DocumentTypeBlueprintItemResponseModel": {
"required": [
"flags",
Expand Down Expand Up @@ -42542,6 +42682,26 @@
},
"additionalProperties": false
},
"MediaTypeAllowedParentsResponseModel": {
"required": [
"allowedParentIds"
],
"type": "object",
"properties": {
"allowedParentIds": {
"uniqueItems": true,
"type": "array",
"items": {
"oneOf": [
{
"$ref": "#/components/schemas/ReferenceByIdModel"
}
]
}
}
},
"additionalProperties": false
},
"MediaTypeCollectionReferenceResponseModel": {
"required": [
"alias",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Umbraco.Cms.Api.Management.ViewModels.DocumentType;

public class DocumentTypeAllowedParentsResponseModel
{
public required ISet<ReferenceByIdModel> AllowedParentIds { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
namespace Umbraco.Cms.Api.Management.ViewModels.MediaType;

public class MediaTypeAllowedParentsResponseModel
{
public required ISet<ReferenceByIdModel> AllowedParentIds { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,12 @@ public interface IContentTypeRepositoryBase<TItem> : IReadWriteQueryRepository<i
/// Returns true or false depending on whether content nodes have been created based on the provided content type id.
/// </summary>
bool HasContentNodes(int id);

/// <summary>
/// Gets the allowed parent keys for a child content type.
/// </summary>
/// <param name="key">The child content type.</param>
/// <returns>An IEnumerable of the allowed parent keys.</returns>
/// TODO (V18): Remove default implementation.
IEnumerable<Guid> GetAllowedParentKeys(Guid key) => [];
}
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,28 @@ public async Task<PagedModel<TItem>> GetAllAllowedAsRootAsync(int skip, int take
return Attempt.SucceedWithStatus<PagedModel<TItem>?, ContentTypeOperationStatus>(ContentTypeOperationStatus.Success, result);
}

/// <inheritdoc/>
public async Task<Attempt<IEnumerable<Guid>, ContentTypeOperationStatus>> GetAllowedParentKeysAsync(Guid key)
{
using ICoreScope scope = ScopeProvider.CreateCoreScope(autoComplete: true);

TItem? content = Get(key);
if (content is null)
{
return Attempt.FailWithStatus<IEnumerable<Guid>, ContentTypeOperationStatus>(ContentTypeOperationStatus.NotFound, []);
}

IEnumerable<Guid> allowedParentKeys = await PerformGetAllowedParentKeysAsync(key);

return Attempt.SucceedWithStatus(ContentTypeOperationStatus.Success, allowedParentKeys);
}

/// <summary>
/// Retrieves a collection of allowed parent keys for the specified key.
/// </summary>
/// <param name="key">The unique identifier of the key for which to retrieve allowed parent keys.</param>
protected virtual Task<IEnumerable<Guid>> PerformGetAllowedParentKeysAsync(Guid key) => Task.FromResult(Repository.GetAllowedParentKeys(key));

#endregion

#region Containers
Expand Down
8 changes: 8 additions & 0 deletions src/Umbraco.Core/Services/IContentTypeBaseService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,12 @@ Task<Attempt<ContentTypeOperationStatus>> UpdateAsync(TItem item, Guid performin
Task<Attempt<PagedModel<TItem>?, ContentTypeOperationStatus>> GetAllowedChildrenAsync(Guid key, Guid? parentContentKey, int skip, int take)
=> GetAllowedChildrenAsync(key, skip, take);

/// <summary>
/// Gets the keys of all content types that allow the provided content type key as a child (i.e. all potential parents of the provided key).
/// </summary>
/// <param name="key">The key of the child content type.</param>
/// <returns>A collection of the keys of all potential parents.</returns>
/// <exception cref="NotImplementedException">Default implementation due to breaking changes.</exception>
/// TODO (V18): Remove the default implementation.
Task<Attempt<IEnumerable<Guid>, ContentTypeOperationStatus>> GetAllowedParentKeysAsync(Guid key) => Task.FromResult(Attempt.FailWithStatus<IEnumerable<Guid>, ContentTypeOperationStatus>(ContentTypeOperationStatus.NotImplemented, []));
}
7 changes: 7 additions & 0 deletions src/Umbraco.Core/Services/MemberTypeService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using Umbraco.Cms.Core.Scoping;
using Umbraco.Cms.Core.Services.Changes;
using Umbraco.Cms.Core.Services.Filters;
using Umbraco.Cms.Core.Services.OperationStatus;
using Umbraco.Extensions;

namespace Umbraco.Cms.Core.Services;
Expand Down Expand Up @@ -142,6 +143,12 @@ protected override void DeleteItemsOfTypes(IEnumerable<int> typeIds)
}
}

/// <inheritdoc />
/// <remarks>
/// Unlike document and media types, allowed children (and therefore parents) are not defined for member types.
/// </remarks>
protected override Task<IEnumerable<Guid>> PerformGetAllowedParentKeysAsync(Guid key) => Task.FromResult(Enumerable.Empty<Guid>());

#region Notifications

protected override SavingNotification<IMemberType> GetSavingNotification(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,5 @@ public enum ContentTypeOperationStatus
InvalidElementFlagComparedToParent,
Unknown,
InvalidTemplateAlias,
NotImplemented,
}
Loading
Loading