diff --git a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs index e14ac00fff..43374162e6 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/ContentTypeController.cs @@ -15,6 +15,7 @@ using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.ContentEditing; using Umbraco.Cms.Core.PropertyEditors; +using Umbraco.Cms.Core.Scoping; using Umbraco.Cms.Core.Security; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; @@ -46,6 +47,7 @@ public class ContentTypeController : ContentTypeControllerBase private readonly ILogger _logger; private readonly PackageDataInstallation _packageDataInstallation; private readonly BlockGridSampleHelper _blockGridSampleHelper; + private readonly ICoreScopeProvider _coreScopeProvider; private readonly PropertyEditorCollection _propertyEditors; // TODO: Split this controller apart so that authz is consistent, currently we need to authz each action individually. @@ -99,7 +101,7 @@ public class ContentTypeController : ContentTypeControllerBase { } - [ActivatorUtilitiesConstructor] + [Obsolete("Please use constructor that takes an ICoreScopeProvider")] public ContentTypeController( ICultureDictionary cultureDictionary, IContentTypeService contentTypeService, @@ -120,6 +122,52 @@ public class ContentTypeController : ContentTypeControllerBase EditorValidatorCollection editorValidatorCollection, PackageDataInstallation packageDataInstallation, BlockGridSampleHelper blockGridSampleHelper) + : this( + cultureDictionary, + contentTypeService, + mediaTypeService, + memberTypeService, + umbracoMapper, + localizedTextService, + serializer, + propertyEditors, + backofficeSecurityAccessor, + dataTypeService, + shortStringHelper, + fileService, + logger, + contentService, + contentTypeBaseServiceProvider, + hostingEnvironment, + editorValidatorCollection, + packageDataInstallation, + blockGridSampleHelper, + StaticServiceProvider.Instance.GetRequiredService()) + { + } + + [ActivatorUtilitiesConstructor] + public ContentTypeController( + ICultureDictionary cultureDictionary, + IContentTypeService contentTypeService, + IMediaTypeService mediaTypeService, + IMemberTypeService memberTypeService, + IUmbracoMapper umbracoMapper, + ILocalizedTextService localizedTextService, + IEntityXmlSerializer serializer, + PropertyEditorCollection propertyEditors, + IBackOfficeSecurityAccessor backofficeSecurityAccessor, + IDataTypeService dataTypeService, + IShortStringHelper shortStringHelper, + IFileService fileService, + ILogger logger, + IContentService contentService, + IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, + IHostingEnvironment hostingEnvironment, + EditorValidatorCollection editorValidatorCollection, + PackageDataInstallation packageDataInstallation, + BlockGridSampleHelper blockGridSampleHelper, + ICoreScopeProvider coreScopeProvider) : base( cultureDictionary, editorValidatorCollection, @@ -144,6 +192,7 @@ public class ContentTypeController : ContentTypeControllerBase _hostingEnvironment = hostingEnvironment; _packageDataInstallation = packageDataInstallation; _blockGridSampleHelper = blockGridSampleHelper; + _coreScopeProvider = coreScopeProvider; } [Authorize(Policy = AuthorizationPolicies.TreeAccessDocumentTypes)] @@ -444,6 +493,7 @@ public class ContentTypeController : ContentTypeControllerBase private ITemplate? CreateTemplateForContentType(string contentTypeAlias, string? contentTypeName) { + using ICoreScope scope = _coreScopeProvider.CreateCoreScope(); ITemplate? template = _fileService.GetTemplate(contentTypeAlias); if (template == null) { @@ -460,6 +510,8 @@ public class ContentTypeController : ContentTypeControllerBase template = tryCreateTemplate.Result?.Entity; } + scope.Complete(); + return template; }