- 
                Notifications
    You must be signed in to change notification settings 
- Fork 2.8k
Templating: Creating a doctype with template now yields a strongly typed template (closes #20443) #20507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Closed
      
      
            lauraneto
  wants to merge
  6
  commits into
  main
from
v16/bugfix/creating-a-doctype-with-template-does-not-yield-a-strongly-typed-template
  
      
      
   
      
    
  
     Closed
                    Templating: Creating a doctype with template now yields a strongly typed template (closes #20443) #20507
Changes from 1 commit
      Commits
    
    
            Show all changes
          
          
            6 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      6a4c687
              
                Adjust the document type creation flow so that a template can be crea…
              
              
                lauraneto 083d630
              
                Add id, name and alias to the request payload to allow creating multi…
              
              
                lauraneto 27020f5
              
                Small adjustments
              
              
                lauraneto f4056f5
              
                Remove unused import and unnecessary async
              
              
                lauraneto 0447764
              
                Switched content type template creation to content type controller
              
              
                lauraneto e0252fc
              
                Missing constant export
              
              
                lauraneto File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            41 changes: 41 additions & 0 deletions
          
          41 
        
  ...mbraco.Cms.Api.Management/Controllers/Template/CreateTemplateForDocumentTypeController.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| using Asp.Versioning; | ||
| using Microsoft.AspNetCore.Http; | ||
| using Microsoft.AspNetCore.Mvc; | ||
| using Umbraco.Cms.Api.Management.ViewModels.Template; | ||
| using Umbraco.Cms.Core; | ||
| using Umbraco.Cms.Core.Models; | ||
| using Umbraco.Cms.Core.Security; | ||
| using Umbraco.Cms.Core.Services; | ||
| using Umbraco.Cms.Core.Services.OperationStatus; | ||
|  | ||
| namespace Umbraco.Cms.Api.Management.Controllers.Template; | ||
|  | ||
| [ApiVersion("1.0")] | ||
| public class CreateTemplateForDocumentTypeController : TemplateControllerBase | ||
| { | ||
| private readonly ITemplateService _templateService; | ||
| private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; | ||
|  | ||
| public CreateTemplateForDocumentTypeController( | ||
| ITemplateService templateService, | ||
| IBackOfficeSecurityAccessor backOfficeSecurityAccessor) | ||
| { | ||
| _templateService = templateService; | ||
| _backOfficeSecurityAccessor = backOfficeSecurityAccessor; | ||
| } | ||
|  | ||
| [HttpPost("for-document-type")] | ||
| [MapToApiVersion("1.0")] | ||
| [ProducesResponseType(StatusCodes.Status201Created)] | ||
| [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status400BadRequest)] | ||
| public async Task<IActionResult> CreateForDocumentType(CancellationToken cancellationToken, CreateTemplateForDocumentTypeRequestModel requestModel) | ||
| { | ||
| Attempt<ITemplate?, TemplateOperationStatus> result = await _templateService.CreateForContentTypeAsync( | ||
| requestModel.DocumentType.Id, | ||
| CurrentUserKey(_backOfficeSecurityAccessor)); | ||
|  | ||
| return result.Success | ||
| ? CreatedAtId<ByKeyTemplateController>(controller => nameof(controller.ByKey), result.Result!.Key) | ||
| : TemplateOperationStatusResult(result.Status); | ||
| } | ||
| } | ||
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
        
          
          
            9 changes: 9 additions & 0 deletions
          
          9 
        
  ...braco.Cms.Api.Management/ViewModels/Template/CreateTemplateForDocumentTypeRequestModel.cs
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| using System.ComponentModel.DataAnnotations; | ||
|  | ||
| namespace Umbraco.Cms.Api.Management.ViewModels.Template; | ||
|  | ||
| public class CreateTemplateForDocumentTypeRequestModel | ||
| { | ||
| [Required] | ||
| public required ReferenceByIdModel DocumentType { get; set; } | ||
| } | 
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              
              
        
          
          
            19 changes: 18 additions & 1 deletion
          
          19 
        
  src/Umbraco.Web.UI.Client/src/packages/core/backend-api/sdk.gen.ts
  
  
      
      
   
        
      
      
    Large diffs are not rendered by default.
      
      Oops, something went wrong.
      
    
  
      
      Oops, something went wrong.
        
    
  
      
      Oops, something went wrong.
        
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another thought - would it be better to remove this new endpoint and instead extend the existing create one? So have
CreateTemplateRequestModeltake an optionalpublic ReferenceByIdModel? DocumentType { get; set; }, and depending on whether that is provided call_templateService.CreateAsync()or_templateService.CreateForContentTypeAsync.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess that depends on whether we want to allow users to create the template after the document type has been created.
Not sure if that was an option in v13 or not, I will double check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked how this worked in v13.
You had both options:
POST 'https://localhost:44340/umbraco/backoffice/umbracoapi/contenttype/PostCreateDefaultTemplate?id=1055', with id being the id of the content type.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't necessarily have to expose it in the UI even if the management API supports it (there are other clients of the API these days of course!).
My comment here though was more just about whether it's cleaner to have a single endpoint for creating templates, with a model that optionally allows you to provide the document type to create it for. Or to have, as you currently do in this PR, two endpoints, with two models - one for create a standalone template, and one for creating one for a document type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, my confusion.
For a moment I was thinking that it was about adding an option to the endpoint that creates the document type.
I think that makes sense, my only doubt is what to do if you also provide
contentin the request, I'm guessing we would then ignore the provided content type key?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see your point, and had missed that possibility. In which case I think it's better how you have it as two discrete endpoints. It's clear then you either have the option to a) create and populate a template or b) create an empty template for a document type. And avoids otherwise messy logic of the nature of "if this is provided ignore that".