Skip to content

Elements: Split content type validation for create and update#21906

Merged
lauraneto merged 10 commits into
v18/devfrom
v18/bugfix/element-editing-service-content-type-validation
Mar 6, 2026
Merged

Elements: Split content type validation for create and update#21906
lauraneto merged 10 commits into
v18/devfrom
v18/bugfix/element-editing-service-content-type-validation

Conversation

@lauraneto

@lauraneto lauraneto commented Feb 25, 2026

Copy link
Copy Markdown
Contributor

Summary

The ElementEditingService previously enforced both IsElement and AllowedInLibrary checks on every content type validation, regardless of whether the operation was a create or an update. This meant that if an element type was later disallowed from the library, existing elements of that type could no longer be saved/updated.

This PR updates the TryGetAndValidateContentType override to distinguish between create and update operations by checking if the model is a ContentCreationModelBase:

  • Create operations enforce that the content type exists, is an element type, and is allowed in the library. This ensures only permitted types can be created.
  • Update operations only enforce that the content type exists. This allows existing elements to still be saved even if their type is no longer permitted in the library.

Additionally, the ValidateCreateAsync method now performs its own content type lookup and IsElement/AllowedInLibrary validation before delegating to ValidateCulturesAndPropertiesAsync, ensuring the validation endpoint also rejects disallowed types on create.

An integration test was added to verify that updating an element succeeds after its content type has been disallowed from the library.

Testing

Create an element type that is allowed in the library and create an element of that type. Then update the element type to no longer be allowed in the library. Verify that the existing element can still be saved/updated, but new elements of that type cannot be created.

@lauraneto lauraneto marked this pull request as ready for review February 26, 2026 08:08
Copilot AI review requested due to automatic review settings February 26, 2026 08:08

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adjusts ElementEditingService content-type validation so element creation still enforces IsElement + AllowedInLibrary, while element updates only require that the content type exists—allowing existing elements to remain editable even if their type is later disallowed from the library.

Changes:

  • Split content type validation into ValidateContentTypeForCreate (strict) and ValidateContentTypeForUpdate (existence-only).
  • Apply the create/update-specific validation in ValidateCreateAsync/ValidateUpdateAsync and in the CreateAsync/UpdateAsync flows.
  • Remove reliance on the previous TryGetAndValidateContentType override approach for these checks.

Comment thread src/Umbraco.Core/Services/ElementEditingService.cs Outdated
Comment thread src/Umbraco.Core/Services/ElementEditingService.cs Outdated
Comment thread src/Umbraco.Core/Services/ElementEditingService.cs Outdated
Verify that ElementEditingService.UpdateAsync succeeds when the content
type's AllowedInLibrary flag is set to false after the element was
created, covering the split validation introduced for create vs update.
Eliminate redundant content type lookups in CreateAsync and UpdateAsync
by moving the IsElement/AllowedInLibrary check into the
TryGetAndValidateContentType override, which distinguishes create from
update by checking if the model is a ContentCreationModelBase.

@Migaroez Migaroez left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, left some suggestions but nothing that feels blocking to me. Feel free to merge as is or implement the suggestions.

Comment thread src/Umbraco.Core/Services/ElementEditingService.cs Outdated
@lauraneto lauraneto enabled auto-merge (squash) March 6, 2026 16:29
@lauraneto lauraneto merged commit 421ad35 into v18/dev Mar 6, 2026
26 of 27 checks passed
@lauraneto lauraneto deleted the v18/bugfix/element-editing-service-content-type-validation branch March 6, 2026 17:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants