diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index de3f96d834ba..a8a9e1fd3bd3 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -14,6 +14,7 @@ using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Web.Common.DependencyInjection; using Umbraco.Extensions; +using static System.Formats.Asn1.AsnWriter; namespace Umbraco.Cms.Core.Services.Implement { @@ -441,34 +442,31 @@ private void ConvertMissingEditorsOfDataTypesToLabels(IEnumerable dat return OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, evtMsgs); } - public Attempt?> Copy(IDataType copying, int containerId) + public Attempt?> Copy(IDataType copying, int containerId, int userId = Constants.Security.SuperUserId) { var evtMsgs = EventMessagesFactory.Get(); IDataType copy; - using (var scope = ScopeProvider.CreateCoreScope()) + try { - try + if (containerId > 0) { - if (containerId > 0) + var container = GetContainer(containerId); + if (container is null) { - var container = _dataTypeContainerRepository.Get(containerId); - if (container is null) - { - throw new DataOperationException(MoveOperationStatusType.FailedParentNotFound); // causes rollback - } + throw new DataOperationException(MoveOperationStatusType.FailedParentNotFound); // causes rollback } - copy = copying.DeepCloneWithResetIdentities(); - - copy.Name += " (copy)"; // might not be unique - copy.ParentId = containerId; - _dataTypeRepository.Save(copy); - scope.Complete(); - } - catch (DataOperationException ex) - { - return OperationResult.Attempt.Fail(ex.Operation, evtMsgs); // causes rollback } + copy = copying.DeepCloneWithResetIdentities(); + + copy.Name += " (copy)"; // might not be unique + copy.ParentId = containerId; + + Save(copy, userId); + } + catch (DataOperationException ex) + { + return OperationResult.Attempt.Fail(ex.Operation, evtMsgs); // causes rollback } return OperationResult.Attempt.Succeed(MoveOperationStatusType.Success, evtMsgs, copy); diff --git a/src/Umbraco.Core/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs index 02bc51a8f65a..11fa1fc964f0 100644 --- a/src/Umbraco.Core/Services/IDataTypeService.cs +++ b/src/Umbraco.Core/Services/IDataTypeService.cs @@ -107,8 +107,9 @@ public interface IDataTypeService : IService /// /// The data type that will be copied /// The container ID under where the data type will be copied + /// The user that did the Copy action /// /// - Attempt?> Copy(IDataType copying, int containerId) => throw new NotImplementedException(); + Attempt?> Copy(IDataType copying, int containerId, int userId = Constants.Security.SuperUserId) => throw new NotImplementedException(); } diff --git a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs index 7de06dfe6d23..376d6af3fa51 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/DataTypeController.cs @@ -8,6 +8,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using NPoco; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Mapping; @@ -391,7 +392,8 @@ public IActionResult PostCopy(MoveOrCopy copy) return NotFound(); } - Attempt?> result = _dataTypeService.Copy(toCopy, copy.ParentId); + var currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser; + Attempt?> result = _dataTypeService.Copy(toCopy, copy.ParentId, currentUser?.Id ?? Constants.Security.SuperUserId); if (result.Success) { return Content(toCopy.Path, MediaTypeNames.Text.Plain, Encoding.UTF8);