Skip to content

Templating: Move production mode validation from service layer to Management API#22383

Merged
AndyButland merged 8 commits intomainfrom
v17/bugfix/fix-validation-for-templates-in-production-mode
Apr 9, 2026
Merged

Templating: Move production mode validation from service layer to Management API#22383
AndyButland merged 8 commits intomainfrom
v17/bugfix/fix-validation-for-templates-in-production-mode

Conversation

@AndyButland
Copy link
Copy Markdown
Contributor

@AndyButland AndyButland commented Apr 8, 2026

Description

This follows up the concern raised in #21600 (comment) and moves production mode checks for templates from the service layer (TemplateService) to the Management API controllers.

This allows deployment tools to continue programmatically create template database entries on production sites via ITemplateService, while still preventing backoffice users from editing via the Management API.

Behaviour change

Operation Before (17.3) After
ITemplateService.CreateAsync in production mode ❌ Blocked ✅ Allowed (DB only, no file write)
ITemplateService.UpdateAsync content change in production mode ❌ Blocked ✅ Allowed (DB only, no file write)
ITemplateService.DeleteAsync in production mode ❌ Blocked ✅ Allowed (DB only, no file write)
Management API template endpoints in production mode ❌ Blocked ❌ Still blocked (moved here)

Testing

Verify Management API returns 400 when attempting to create/update/delete templates or partial views in production mode.

To set up for testing:

  • Configure Umbraco:CMS:Runtime:Mode to Production in appsettings.json
  • Configure Umbraco:CMS:ModelsBuilder:ModelsMode to None in appsettings.json
  • On start-up you'll likely get warnings about other things you need to do to run in production mode. If you want to avoid setting all that up, you can temporarily amend RuntimeModeValidationService.Validate to early return with validationErrorMessage = null; return true;.

For example, updating a template without changes to content should be OK:

PUT /umbraco/management/api/v1/template/{id}
{
   "name":"Test Page",
   "content":"@using Umbraco.Cms.Web.Common.PublishedModels;\n@inherits Umbraco.Cms.Web.Common.Views.UmbracoViewPage\n@{\n\tLayout = null;\n}\n\n<h3>My Test Page</h3>",
   "alias":"testPage"
}

But with a content change, it should fail with a 400 response, with a title of "Content change not allowed in production mode".

AndyButland and others added 2 commits April 8, 2026 18:05
…the service layer, and move to management API.
…ests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Moves production-mode edit restrictions for templates/partial views out of the Core service layer and into the Management API layer, so non-Management callers can invoke ITemplateService/IPartialViewService in production while the backoffice Management API remains restricted.

Changes:

  • Removed production-mode validation from TemplateService and PartialViewService.
  • Added RuntimeSettings checks to the Management API template/partial view CRUD controllers (with obsolete ctor bridging kept).
  • Removed integration tests that asserted service-layer production-mode blocking.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 10 comments.

Show a summary per file
File Description
tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TemplateServiceTests.cs Removes service-layer production-mode tests for templates.
tests/Umbraco.Tests.Integration/Umbraco.Core/Services/PartialViewServiceTests.cs Removes service-layer production-mode tests for partial views.
src/Umbraco.Core/Services/TemplateService.cs Drops production-mode guards from create/update/delete validation in the service.
src/Umbraco.Core/Services/PartialViewService.cs Drops production-mode guards from partial view CRUD in the service.
src/Umbraco.Cms.Api.Management/Controllers/Template/CreateTemplateController.cs Adds production-mode blocking at the Management API boundary for template creation.
src/Umbraco.Cms.Api.Management/Controllers/Template/DeleteTemplateController.cs Adds production-mode blocking at the Management API boundary for template deletion.
src/Umbraco.Cms.Api.Management/Controllers/Template/UpdateTemplateController.cs Adds production-mode blocking for template content changes at the Management API boundary.
src/Umbraco.Cms.Api.Management/Controllers/PartialView/CreatePartialViewController.cs Adds production-mode blocking at the Management API boundary for partial view creation.
src/Umbraco.Cms.Api.Management/Controllers/PartialView/UpdatePartialViewController.cs Adds production-mode blocking at the Management API boundary for partial view updates.
src/Umbraco.Cms.Api.Management/Controllers/PartialView/RenamePartialViewController.cs Adds production-mode blocking at the Management API boundary for partial view renames.
src/Umbraco.Cms.Api.Management/Controllers/PartialView/DeletePartialViewController.cs Adds production-mode blocking at the Management API boundary for partial view deletion.
Comments suppressed due to low confidence (2)

tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TemplateServiceTests.cs:24

  • The production-mode behavior tests were removed, but this PR changes runtime-mode semantics (service-layer validation removed, controller-layer validation added). Add/replace coverage to assert:
  • ITemplateService operations in Production mode succeed and do not write/delete view files.
  • Management API endpoints return the correct 400 status in Production mode.

Without this, a regression like deleting template files in production (via repository delete) would be easy to miss.

    private ITemplateService TemplateService => GetRequiredService<ITemplateService>();

    [SetUp]
    public void SetUp() => DeleteAllTemplateViewFiles();

    [TearDown]
    public void TearDownTemplateFiles() => DeleteAllTemplateViewFiles();

tests/Umbraco.Tests.Integration/Umbraco.Core/Services/PartialViewServiceTests.cs:24

  • The production-mode behavior tests were removed, but the PR changes production-mode semantics for partial view operations. Add/replace test coverage to assert Production mode behavior explicitly (e.g., whether IPartialViewService should be allowed and what persistence guarantees it provides, and that Management API endpoints remain blocked).

This is especially important now that repository-level persistence is suppressed in production for create/update but not necessarily for delete.

    private IPartialViewService PartialViewService => GetRequiredService<IPartialViewService>();

    [SetUp]
    public void SetUp() => DeleteAllPartialViewFiles();

    [TearDown]
    public void TearDownPartialViewFiles() => DeleteAllPartialViewFiles();

Comment thread src/Umbraco.Core/Services/PartialViewService.cs Outdated
Comment thread src/Umbraco.Core/Services/PartialViewService.cs Outdated
Comment thread src/Umbraco.Core/Services/TemplateService.cs
AndyButland and others added 5 commits April 8, 2026 18:28
…havior

Tests verify that the Management API correctly blocks template content
changes while allowing metadata-only updates in production mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Add integration tests for template controllers with production mode.
@AndyButland AndyButland requested a review from Migaroez April 9, 2026 09:53
@AndyButland AndyButland merged commit e5de587 into main Apr 9, 2026
27 checks passed
@AndyButland AndyButland deleted the v17/bugfix/fix-validation-for-templates-in-production-mode branch April 9, 2026 10:44
AndyButland added a commit that referenced this pull request Apr 9, 2026
…agement API (#22383)

* Revert production mode validation for templates and partial views at the service layer, and move to management API.

* Remove unused ConfigureProductionMode helper from PartialViewServiceTests

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Add integration tests for UpdateTemplateController production mode behavior

Tests verify that the Management API correctly blocks template content
changes while allowing metadata-only updates in production mode.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>

* Restore partial view service checks.
Add integration tests for template controllers with production mode.

* Align delete with create/update for file system changes in production mode.

* Restore partial view service tests.

* Add test for update to delete template repository.

* Refactored to use single test setup method.

---------

Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.

3 participants