Templating: Move production mode validation from service layer to Management API#22383
Conversation
…the service layer, and move to management API.
…ests Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
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
TemplateServiceandPartialViewService. - Added
RuntimeSettingschecks 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();
…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.
…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>
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
ITemplateService.CreateAsyncin production modeITemplateService.UpdateAsynccontent change in production modeITemplateService.DeleteAsyncin production modeTesting
Verify Management API returns 400 when attempting to create/update/delete templates or partial views in production mode.
To set up for testing:
Umbraco:CMS:Runtime:ModetoProductioninappsettings.jsonUmbraco:CMS:ModelsBuilder:ModelsModetoNoneinappsettings.jsonRuntimeModeValidationService.Validateto early return withvalidationErrorMessage = null; return true;.For example, updating a template without changes to content should be OK:
But with a content change, it should fail with a 400 response, with a title of "Content change not allowed in production mode".