From 93da4371e304742c76db2a90b51f5ba3bf65b5c3 Mon Sep 17 00:00:00 2001 From: Nikolaj Geisle <70372949+Zeegaan@users.noreply.github.com> Date: Tue, 21 Mar 2023 12:41:20 +0100 Subject: [PATCH] V13: Rework attempt pattern to use userkey (#13964) * Add default super user key to migrations * Start refactoring all interfaces signatures with ids * Refactor datatype service to use userKey pattern instead * Refactor ContentEditingService to use userkeys * Refactor services to userKey * Refactor more services to use userkey instead of id * Refactor RelationService to use userKeys * Refactor template service to use keys instead of ids * Refactor fileservice to use keys instead of ids * Refactor LocalizationService to use keys instead of ids * Refactor PackagingService to use keys instead of ids * Refactor TemplateController to use current user keys * Refactor DataTypeContainerService.cs * Refactor DataTypeService to use keys instead of ids * Fix up tests * Fix up media editing service to use userkey instead of ID * Update service ctor to avoid ambigious ctors * refactor DataTypeService * Refactor DataTypeService to not have a default value for parentKey * Apply suggestions from code review Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> * Update comment * Add suppression file * Add backoffice CompatibilitySuppressions --------- Co-authored-by: Zeegaan Co-authored-by: Elitsa Marinovska <21998037+elit0451@users.noreply.github.com> --- .../DataType/CopyDataTypeController.cs | 2 +- .../DataType/CreateDataTypeController.cs | 2 +- .../DataType/DeleteDataTypeController.cs | 2 +- .../Folder/DataTypeFolderControllerBase.cs | 12 +- .../DataType/MoveDataTypeController.cs | 2 +- .../DataType/UpdateDataTypeController.cs | 2 +- .../Dictionary/CreateDictionaryController.cs | 2 +- .../Dictionary/DeleteDictionaryController.cs | 2 +- .../Dictionary/ImportDictionaryController.cs | 2 +- .../Dictionary/MoveDictionaryController.cs | 2 +- .../Dictionary/UpdateDictionaryController.cs | 2 +- .../Document/CreateDocumentController.cs | 2 +- .../MoveToRecycleBinDocumentController.cs | 2 +- .../Document/UpdateDocumentController.cs | 2 +- .../FolderManagementControllerBase.cs | 12 +- .../Language/CreateLanguageController.cs | 2 +- .../Language/DeleteLanguageController.cs | 2 +- .../Language/UpdateLanguageController.cs | 2 +- .../ManagementApiControllerBase.cs | 4 +- .../Media/CreateMediaController.cs | 2 +- .../Media/MoveToRecycleBinMediaController.cs | 2 +- .../Media/UpdateMediaController.cs | 2 +- .../Created/CreateCreatedPackageController.cs | 2 +- .../Created/DeleteCreatedPackageController.cs | 2 +- .../Created/UpdateCreatedPackageController.cs | 2 +- .../Query/CreateRelationTypeController.cs | 2 +- .../Query/DeleteRelationTypeController.cs | 2 +- .../Query/UpdateRelationTypeController.cs | 2 +- .../Template/CreateTemplateController.cs | 2 +- .../Template/DeleteTemplateController.cs | 2 +- .../Template/UpdateTemplateController.cs | 2 +- .../Services/DictionaryItemImportService.cs | 12 +- .../Services/IDictionaryItemImportService.cs | 2 +- .../CompatibilitySuppressions.xml | 78 ++++++++++++- .../Services/ContentEditingService.cs | 34 ++++-- .../Services/DataTypeContainerService.cs | 29 +++-- src/Umbraco.Core/Services/DataTypeService.cs | 68 +++++++---- .../Services/DictionaryItemService.cs | 28 +++-- src/Umbraco.Core/Services/FileService.cs | 27 +++-- .../Services/IContentEditingService.cs | 8 +- .../Services/IDataTypeContainerService.cs | 16 +-- src/Umbraco.Core/Services/IDataTypeService.cs | 20 ++-- .../Services/IDictionaryItemService.cs | 16 +-- src/Umbraco.Core/Services/ILanguageService.cs | 12 +- .../Services/IMediaEditingService.cs | 8 +- .../Services/IPackagingService.cs | 10 +- src/Umbraco.Core/Services/IRelationService.cs | 12 +- src/Umbraco.Core/Services/ITemplateService.cs | 24 ++-- src/Umbraco.Core/Services/LanguageService.cs | 23 ++-- .../Services/LocalizationService.cs | 32 ++++-- .../Services/MediaEditingService.cs | 33 ++++-- src/Umbraco.Core/Services/RelationService.cs | 44 +++++-- src/Umbraco.Core/Services/TemplateService.cs | 71 ++++++++---- src/Umbraco.Core/Services/UserService.cs | 5 +- .../Services/Implement/PackagingService.cs | 28 +++-- .../CompatibilitySuppressions.xml | 8 +- .../Controllers/TemplateController.cs | 20 +--- .../CreatedPackagesRepositoryTests.cs | 10 +- .../Services/RelationServiceTests.cs | 10 +- .../Services/TelemetryProviderTests.cs | 4 +- .../ContentVariantAllowedActionTests.cs | 3 +- .../Packaging/PackageDataInstallationTests.cs | 10 +- .../Repositories/DictionaryRepositoryTest.cs | 11 +- .../Repositories/LanguageRepositoryTest.cs | 9 +- .../Scoping/ScopedRepositoryTests.cs | 12 +- .../ContentEditingServiceTests.Create.cs | 42 +++---- .../ContentEditingServiceTests.Delete.cs | 5 +- .../ContentEditingServiceTests.Update.cs | 20 ++-- .../Services/ContentEditingServiceTests.cs | 6 +- .../ContentServiceNotificationTests.cs | 7 +- .../ContentServicePublishBranchTests.cs | 6 +- .../Services/ContentServiceTagsTests.cs | 11 +- .../Services/ContentServiceTests.cs | 48 ++++---- .../ContentTypeServiceVariantsTests.cs | 11 +- .../Services/DataTypeContainerServiceTests.cs | 60 +++++----- .../Services/DataTypeServiceTests.cs | 64 ++++++----- .../Services/DictionaryItemServiceTests.cs | 108 ++++++++++-------- .../Services/EntityServiceTests.cs | 4 +- .../Services/EntityXmlSerializerTests.cs | 12 +- .../Services/LanguageServiceTests.cs | 65 +++++------ .../Services/TemplateServiceTests.cs | 70 ++++++------ .../Controllers/ContentControllerTests.cs | 66 +++++++---- .../OutgoingEditorModelEventFilterTests.cs | 5 +- 83 files changed, 853 insertions(+), 578 deletions(-) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/DataType/CopyDataTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/DataType/CopyDataTypeController.cs index 9aa3695a5d..82c796a2a1 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/DataType/CopyDataTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/DataType/CopyDataTypeController.cs @@ -32,7 +32,7 @@ public class CopyDataTypeController : DataTypeControllerBase return NotFound(); } - Attempt result = await _dataTypeService.CopyAsync(source, copyDataTypeRequestModel.TargetKey, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _dataTypeService.CopyAsync(source, copyDataTypeRequestModel.TargetKey, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), result.Result.Key) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/DataType/CreateDataTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/DataType/CreateDataTypeController.cs index a456442098..7994562011 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/DataType/CreateDataTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/DataType/CreateDataTypeController.cs @@ -31,7 +31,7 @@ public class CreateDataTypeController : DataTypeControllerBase public async Task Create(CreateDataTypeRequestModel createDataTypeRequestModel) { IDataType? created = _umbracoMapper.Map(createDataTypeRequestModel)!; - Attempt result = await _dataTypeService.CreateAsync(created, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _dataTypeService.CreateAsync(created, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), created.Key) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/DataType/DeleteDataTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/DataType/DeleteDataTypeController.cs index c93ab3b86b..359f4e0c3d 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/DataType/DeleteDataTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/DataType/DeleteDataTypeController.cs @@ -26,7 +26,7 @@ public class DeleteDataTypeController : DataTypeControllerBase [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task Delete(Guid key) { - Attempt result = await _dataTypeService.DeleteAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _dataTypeService.DeleteAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/DataType/Folder/DataTypeFolderControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/DataType/Folder/DataTypeFolderControllerBase.cs index d71d1a5607..d6629aba44 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/DataType/Folder/DataTypeFolderControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/DataType/Folder/DataTypeFolderControllerBase.cs @@ -30,14 +30,14 @@ public abstract class DataTypeFolderControllerBase : FolderManagementControllerB protected override async Task GetParentContainerAsync(EntityContainer container) => await _dataTypeContainerService.GetParentAsync(container); - protected override async Task> CreateContainerAsync(EntityContainer container, Guid? parentId, int userId) - => await _dataTypeContainerService.CreateAsync(container, parentId, userId); + protected override async Task> CreateContainerAsync(EntityContainer container, Guid? parentId, Guid userKey) + => await _dataTypeContainerService.CreateAsync(container, parentId, userKey); - protected override async Task> UpdateContainerAsync(EntityContainer container, int userId) - => await _dataTypeContainerService.UpdateAsync(container, userId); + protected override async Task> UpdateContainerAsync(EntityContainer container, Guid userKey) + => await _dataTypeContainerService.UpdateAsync(container, userKey); - protected override async Task> DeleteContainerAsync(Guid id, int userId) - => await _dataTypeContainerService.DeleteAsync(id, userId); + protected override async Task> DeleteContainerAsync(Guid id, Guid userKey) + => await _dataTypeContainerService.DeleteAsync(id, userKey); protected override IActionResult OperationStatusResult(DataTypeContainerOperationStatus status) => status switch diff --git a/src/Umbraco.Cms.Api.Management/Controllers/DataType/MoveDataTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/DataType/MoveDataTypeController.cs index 0bcf5b9392..33e8f87658 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/DataType/MoveDataTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/DataType/MoveDataTypeController.cs @@ -32,7 +32,7 @@ public class MoveDataTypeController : DataTypeControllerBase return NotFound(); } - Attempt result = await _dataTypeService.MoveAsync(source, moveDataTypeRequestModel.TargetKey, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _dataTypeService.MoveAsync(source, moveDataTypeRequestModel.TargetKey, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/DataType/UpdateDataTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/DataType/UpdateDataTypeController.cs index f6d86dc90d..dbb1a004a7 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/DataType/UpdateDataTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/DataType/UpdateDataTypeController.cs @@ -37,7 +37,7 @@ public class UpdateDataTypeController : DataTypeControllerBase } IDataType updated = _umbracoMapper.Map(updateDataTypeViewModel, current); - Attempt result = await _dataTypeService.UpdateAsync(updated, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _dataTypeService.UpdateAsync(updated, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/CreateDictionaryController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/CreateDictionaryController.cs index b7eea9d20e..715582dbb6 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/CreateDictionaryController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/CreateDictionaryController.cs @@ -37,7 +37,7 @@ public class CreateDictionaryController : DictionaryControllerBase IDictionaryItem created = await _dictionaryPresentationFactory.MapCreateModelToDictionaryItemAsync(createDictionaryItemRequestModel); Attempt result = - await _dictionaryItemService.CreateAsync(created, CurrentUserId(_backOfficeSecurityAccessor)); + await _dictionaryItemService.CreateAsync(created, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), result.Result!.Key) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/DeleteDictionaryController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/DeleteDictionaryController.cs index b66965fb6b..186d9925d9 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/DeleteDictionaryController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/DeleteDictionaryController.cs @@ -26,7 +26,7 @@ public class DeleteDictionaryController : DictionaryControllerBase [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task Delete(Guid key) { - Attempt result = await _dictionaryItemService.DeleteAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _dictionaryItemService.DeleteAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/ImportDictionaryController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/ImportDictionaryController.cs index c4dc5cf5f4..4c53ccba9b 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/ImportDictionaryController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/ImportDictionaryController.cs @@ -34,7 +34,7 @@ public class ImportDictionaryController : DictionaryControllerBase .ImportDictionaryItemFromUdtFileAsync( importDictionaryRequestModel.TemporaryFileKey, importDictionaryRequestModel.ParentKey, - CurrentUserId(_backOfficeSecurityAccessor)); + CurrentUserKey(_backOfficeSecurityAccessor)); return result.Status switch { diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/MoveDictionaryController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/MoveDictionaryController.cs index f74f4c82a8..853268351e 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/MoveDictionaryController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/MoveDictionaryController.cs @@ -36,7 +36,7 @@ public class MoveDictionaryController : DictionaryControllerBase Attempt result = await _dictionaryItemService.MoveAsync( source, moveDictionaryRequestModel.TargetKey, - CurrentUserId(_backOfficeSecurityAccessor)); + CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/UpdateDictionaryController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/UpdateDictionaryController.cs index 6f48fc87bf..0a8f0e28f0 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/UpdateDictionaryController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Dictionary/UpdateDictionaryController.cs @@ -42,7 +42,7 @@ public class UpdateDictionaryController : DictionaryControllerBase IDictionaryItem updated = await _dictionaryPresentationFactory.MapUpdateModelToDictionaryItemAsync(current, updateDictionaryItemRequestModel); Attempt result = - await _dictionaryItemService.UpdateAsync(updated, CurrentUserId(_backOfficeSecurityAccessor)); + await _dictionaryItemService.UpdateAsync(updated, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Document/CreateDocumentController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Document/CreateDocumentController.cs index f04338bf5a..79f0e03899 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Document/CreateDocumentController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Document/CreateDocumentController.cs @@ -32,7 +32,7 @@ public class CreateDocumentController : DocumentControllerBase public async Task Create(CreateDocumentRequestModel requestModel) { ContentCreateModel model = _documentEditingPresentationFactory.MapCreateModel(requestModel); - Attempt result = await _contentEditingService.CreateAsync(model, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _contentEditingService.CreateAsync(model, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), result.Result!.Key) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Document/MoveToRecycleBinDocumentController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Document/MoveToRecycleBinDocumentController.cs index edd2303c00..45e17fcbd3 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Document/MoveToRecycleBinDocumentController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Document/MoveToRecycleBinDocumentController.cs @@ -26,7 +26,7 @@ public class MoveToRecycleBinDocumentController : DocumentControllerBase [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task MoveToRecycleBin(Guid key) { - Attempt result = await _contentEditingService.MoveToRecycleBinAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _contentEditingService.MoveToRecycleBinAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() : ContentEditingOperationStatusResult(result.Status); diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateDocumentController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateDocumentController.cs index ba2cdc974e..a81279e66a 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateDocumentController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Document/UpdateDocumentController.cs @@ -41,7 +41,7 @@ public class UpdateDocumentController : DocumentControllerBase } ContentUpdateModel model = _documentEditingPresentationFactory.MapUpdateModel(requestModel); - Attempt result = await _contentEditingService.UpdateAsync(content, model, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _contentEditingService.UpdateAsync(content, model, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/FolderManagementControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/FolderManagementControllerBase.cs index acea6f11e1..5e304c5bca 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/FolderManagementControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/FolderManagementControllerBase.cs @@ -43,7 +43,7 @@ public abstract class FolderManagementControllerBase : ManagementApiCon Attempt result = await CreateContainerAsync( container, createFolderRequestModel.ParentKey, - CurrentUserId(_backOfficeSecurityAccessor)); + CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(createdAction, result.Result.Key) @@ -60,7 +60,7 @@ public abstract class FolderManagementControllerBase : ManagementApiCon container.Name = updateFolderReponseModel.Name; - Attempt result = await UpdateContainerAsync(container, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await UpdateContainerAsync(container, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() : OperationStatusResult(result.Status); @@ -68,7 +68,7 @@ public abstract class FolderManagementControllerBase : ManagementApiCon protected async Task DeleteFolderAsync(Guid key) { - Attempt result = await DeleteContainerAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await DeleteContainerAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() : OperationStatusResult(result.Status); @@ -80,11 +80,11 @@ public abstract class FolderManagementControllerBase : ManagementApiCon protected abstract Task GetParentContainerAsync(EntityContainer container); - protected abstract Task> CreateContainerAsync(EntityContainer container, Guid? parentId, int userId); + protected abstract Task> CreateContainerAsync(EntityContainer container, Guid? parentId, Guid userKey); - protected abstract Task> UpdateContainerAsync(EntityContainer container, int userId); + protected abstract Task> UpdateContainerAsync(EntityContainer container, Guid userKey); - protected abstract Task> DeleteContainerAsync(Guid id, int userId); + protected abstract Task> DeleteContainerAsync(Guid id, Guid userKey); protected abstract IActionResult OperationStatusResult(TStatus status); } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Language/CreateLanguageController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Language/CreateLanguageController.cs index d5e21026fd..6a44d5aa4f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Language/CreateLanguageController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Language/CreateLanguageController.cs @@ -35,7 +35,7 @@ public class CreateLanguageController : LanguageControllerBase { ILanguage created = _umbracoMapper.Map(createLanguageRequestModel)!; - Attempt result = await _languageService.CreateAsync(created, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _languageService.CreateAsync(created, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByIsoCode), new { isoCode = result.Result.IsoCode }) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Language/DeleteLanguageController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Language/DeleteLanguageController.cs index ced428ac67..9e6aed7f40 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Language/DeleteLanguageController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Language/DeleteLanguageController.cs @@ -26,7 +26,7 @@ public class DeleteLanguageController : LanguageControllerBase [ProducesResponseType(StatusCodes.Status200OK)] public async Task Delete(string isoCode) { - Attempt result = await _languageService.DeleteAsync(isoCode, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _languageService.DeleteAsync(isoCode, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Language/UpdateLanguageController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Language/UpdateLanguageController.cs index ac465914f5..25dcc2388d 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Language/UpdateLanguageController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Language/UpdateLanguageController.cs @@ -42,7 +42,7 @@ public class UpdateLanguageController : LanguageControllerBase ILanguage updated = _umbracoMapper.Map(updateLanguageRequestModel, current); - Attempt result = await _languageService.UpdateAsync(updated, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _languageService.UpdateAsync(updated, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/ManagementApiControllerBase.cs b/src/Umbraco.Cms.Api.Management/Controllers/ManagementApiControllerBase.cs index 29075fce3a..269520c1f7 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/ManagementApiControllerBase.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/ManagementApiControllerBase.cs @@ -38,6 +38,6 @@ public class ManagementApiControllerBase : Controller return base.CreatedAtAction(actionName, controllerName, new { name = name }, null); } - protected static int CurrentUserId(IBackOfficeSecurityAccessor backOfficeSecurityAccessor) - => backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id ?? Core.Constants.Security.SuperUserId; + protected static Guid CurrentUserKey(IBackOfficeSecurityAccessor backOfficeSecurityAccessor) + => backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Key ?? Core.Constants.Security.SuperUserKey; } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Media/CreateMediaController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Media/CreateMediaController.cs index 92a51396dd..7a427afd1f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Media/CreateMediaController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Media/CreateMediaController.cs @@ -32,7 +32,7 @@ public class CreateMediaController : MediaControllerBase public async Task Create(CreateMediaRequestModel createRequestModel) { MediaCreateModel model = _mediaEditingPresentationFactory.MapCreateModel(createRequestModel); - Attempt result = await _mediaEditingService.CreateAsync(model, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _mediaEditingService.CreateAsync(model, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), result.Result!.Key) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Media/MoveToRecycleBinMediaController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Media/MoveToRecycleBinMediaController.cs index 2310ab4400..7137521b4f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Media/MoveToRecycleBinMediaController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Media/MoveToRecycleBinMediaController.cs @@ -26,7 +26,7 @@ public class MoveToRecycleBinMediaController : MediaControllerBase [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task MoveToRecycleBin(Guid key) { - Attempt result = await _mediaEditingService.MoveToRecycleBinAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _mediaEditingService.MoveToRecycleBinAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() : ContentEditingOperationStatusResult(result.Status); diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Media/UpdateMediaController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Media/UpdateMediaController.cs index a322f04c63..9b6e24780d 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Media/UpdateMediaController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Media/UpdateMediaController.cs @@ -41,7 +41,7 @@ public class UpdateMediaController : MediaControllerBase } MediaUpdateModel model = _mediaEditingPresentationFactory.MapUpdateModel(updateRequestModel); - Attempt result = await _mediaEditingService.UpdateAsync(media, model, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _mediaEditingService.UpdateAsync(media, model, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/CreateCreatedPackageController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/CreateCreatedPackageController.cs index 044b3b6f96..acf998b94f 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/CreateCreatedPackageController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/CreateCreatedPackageController.cs @@ -40,7 +40,7 @@ public class CreateCreatedPackageController : CreatedPackageControllerBase { PackageDefinition packageDefinition = _packageDefinitionFactory.CreatePackageDefinition(createPackageRequestModel); - Attempt result = await _packagingService.CreateCreatedPackageAsync(packageDefinition, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _packagingService.CreateCreatedPackageAsync(packageDefinition, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), packageDefinition.PackageId) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/DeleteCreatedPackageController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/DeleteCreatedPackageController.cs index cbc71b7d20..427d5686a8 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/DeleteCreatedPackageController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/DeleteCreatedPackageController.cs @@ -31,7 +31,7 @@ public class DeleteCreatedPackageController : CreatedPackageControllerBase public async Task Delete(Guid key) { Attempt result = - await _packagingService.DeleteCreatedPackageAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + await _packagingService.DeleteCreatedPackageAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/UpdateCreatedPackageController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/UpdateCreatedPackageController.cs index a269d0b5f0..e6e281b2d7 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/UpdateCreatedPackageController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Package/Created/UpdateCreatedPackageController.cs @@ -48,7 +48,7 @@ public class UpdateCreatedPackageController : CreatedPackageControllerBase // Macros are not included! PackageDefinition packageDefinition = _umbracoMapper.Map(updatePackageRequestModel, package); - Attempt result = await _packagingService.UpdateCreatedPackageAsync(packageDefinition, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _packagingService.UpdateCreatedPackageAsync(packageDefinition, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/CreateRelationTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/CreateRelationTypeController.cs index 6fa80a453d..5a194af6d0 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/CreateRelationTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/CreateRelationTypeController.cs @@ -34,7 +34,7 @@ public class CreateRelationTypeController : RelationTypeControllerBase { IRelationType relationTypePersisted = _relationTypePresentationFactory.CreateRelationType(createRelationTypeRequestModel); - Attempt result = await _relationService.CreateAsync(relationTypePersisted, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _relationService.CreateAsync(relationTypePersisted, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? await Task.FromResult(CreatedAtAction(controller => nameof(controller.ByKey), relationTypePersisted.Key)) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/DeleteRelationTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/DeleteRelationTypeController.cs index d6752795b5..9a2676143a 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/DeleteRelationTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/DeleteRelationTypeController.cs @@ -25,7 +25,7 @@ public class DeleteRelationTypeController : RelationTypeControllerBase [ProducesResponseType(typeof(ProblemDetails), StatusCodes.Status404NotFound)] public async Task Delete(Guid key) { - Attempt result = await _relationService.DeleteAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _relationService.DeleteAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? await Task.FromResult(Ok()) : RelationTypeOperationStatusResult(result.Status); } } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/UpdateRelationTypeController.cs b/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/UpdateRelationTypeController.cs index 61fcc598e9..08eaa260f2 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/UpdateRelationTypeController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/RelationType/Query/UpdateRelationTypeController.cs @@ -47,7 +47,7 @@ public class UpdateRelationTypeController : RelationTypeControllerBase _relationTypePresentationFactory.MapUpdateModelToRelationType(updateRelationTypeSavingViewModel, persistedRelationType); - Attempt result = await _relationService.UpdateAsync(persistedRelationType, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _relationService.UpdateAsync(persistedRelationType, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? await Task.FromResult(Ok()) : RelationTypeOperationStatusResult(result.Status); } diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Template/CreateTemplateController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Template/CreateTemplateController.cs index 73557c3e4e..81bb0ca59a 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Template/CreateTemplateController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Template/CreateTemplateController.cs @@ -33,7 +33,7 @@ public class CreateTemplateController : TemplateControllerBase requestModel.Name, requestModel.Alias, requestModel.Content, - CurrentUserId(_backOfficeSecurityAccessor)); + CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? CreatedAtAction(controller => nameof(controller.ByKey), result.Result.Key) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Template/DeleteTemplateController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Template/DeleteTemplateController.cs index d6f31e67ce..676e835d45 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Template/DeleteTemplateController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Template/DeleteTemplateController.cs @@ -26,7 +26,7 @@ public class DeleteTemplateController : TemplateControllerBase [ProducesResponseType(StatusCodes.Status404NotFound)] public async Task Delete(Guid key) { - Attempt result = await _templateService.DeleteAsync(key, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _templateService.DeleteAsync(key, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() : TemplateOperationStatusResult(result.Status); diff --git a/src/Umbraco.Cms.Api.Management/Controllers/Template/UpdateTemplateController.cs b/src/Umbraco.Cms.Api.Management/Controllers/Template/UpdateTemplateController.cs index 6e678b21f6..801a55832d 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/Template/UpdateTemplateController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/Template/UpdateTemplateController.cs @@ -41,7 +41,7 @@ public class UpdateTemplateController : TemplateControllerBase template = _umbracoMapper.Map(requestModel, template); - Attempt result = await _templateService.UpdateAsync(template, CurrentUserId(_backOfficeSecurityAccessor)); + Attempt result = await _templateService.UpdateAsync(template, CurrentUserKey(_backOfficeSecurityAccessor)); return result.Success ? Ok() diff --git a/src/Umbraco.Cms.Api.Management/Services/DictionaryItemImportService.cs b/src/Umbraco.Cms.Api.Management/Services/DictionaryItemImportService.cs index d04da27e33..dda6acd511 100644 --- a/src/Umbraco.Cms.Api.Management/Services/DictionaryItemImportService.cs +++ b/src/Umbraco.Cms.Api.Management/Services/DictionaryItemImportService.cs @@ -19,6 +19,7 @@ internal sealed class DictionaryItemImportService : IDictionaryItemImportService private readonly PackageDataInstallation _packageDataInstallation; private readonly ILogger _logger; private readonly ITemporaryFileService _temporaryFileService; + private readonly IUserService _userService; private readonly IScopeProvider _scopeProvider; public DictionaryItemImportService( @@ -26,16 +27,18 @@ internal sealed class DictionaryItemImportService : IDictionaryItemImportService PackageDataInstallation packageDataInstallation, ILogger logger, ITemporaryFileService temporaryFileService, + IUserService userService, IScopeProvider scopeProvider) { _dictionaryItemService = dictionaryItemService; _packageDataInstallation = packageDataInstallation; _logger = logger; _temporaryFileService = temporaryFileService; + _userService = userService; _scopeProvider = scopeProvider; } - public async Task> ImportDictionaryItemFromUdtFileAsync(Guid fileKey, Guid? parentKey, int userId = Constants.Security.SuperUserId) + public async Task> ImportDictionaryItemFromUdtFileAsync(Guid fileKey, Guid? parentKey, Guid userKey) { using var scope = _scopeProvider.CreateScope(); _temporaryFileService.EnlistDeleteIfScopeCompletes(fileKey, _scopeProvider); @@ -67,7 +70,7 @@ internal sealed class DictionaryItemImportService : IDictionaryItemImportService } // import the UDT file - (IDictionaryItem? DictionaryItem, DictionaryImportOperationStatus Status) importResult = ImportUdtFile(loadResult.Document, userId, parentKey, temporaryFile); + (IDictionaryItem? DictionaryItem, DictionaryImportOperationStatus Status) importResult = ImportUdtFile(loadResult.Document, userKey, parentKey, temporaryFile); scope.Complete(); @@ -94,7 +97,7 @@ internal sealed class DictionaryItemImportService : IDictionaryItemImportService } } - private (IDictionaryItem? DictionaryItem, DictionaryImportOperationStatus Status) ImportUdtFile(XDocument udtFileContent, int userId, Guid? parentKey, TemporaryFileModel temporaryFileModel) + private (IDictionaryItem? DictionaryItem, DictionaryImportOperationStatus Status) ImportUdtFile(XDocument udtFileContent, Guid userKey, Guid? parentKey, TemporaryFileModel temporaryFileModel) { if (udtFileContent.Root == null) { @@ -103,7 +106,8 @@ internal sealed class DictionaryItemImportService : IDictionaryItemImportService try { - IEnumerable dictionaryItems = _packageDataInstallation.ImportDictionaryItem(udtFileContent.Root, userId, parentKey); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + IEnumerable dictionaryItems = _packageDataInstallation.ImportDictionaryItem(udtFileContent.Root, currentUserId, parentKey); IDictionaryItem? importedDictionaryItem = dictionaryItems.FirstOrDefault(); return importedDictionaryItem != null ? (importedDictionaryItem, DictionaryImportOperationStatus.Success) diff --git a/src/Umbraco.Cms.Api.Management/Services/IDictionaryItemImportService.cs b/src/Umbraco.Cms.Api.Management/Services/IDictionaryItemImportService.cs index b9ae55dfb4..06669a0f20 100644 --- a/src/Umbraco.Cms.Api.Management/Services/IDictionaryItemImportService.cs +++ b/src/Umbraco.Cms.Api.Management/Services/IDictionaryItemImportService.cs @@ -6,5 +6,5 @@ namespace Umbraco.Cms.Api.Management.Services; public interface IDictionaryItemImportService { - Task> ImportDictionaryItemFromUdtFileAsync(Guid temporaryFileKey, Guid? parentKey, int userId = Constants.Security.SuperUserId); + Task> ImportDictionaryItemFromUdtFileAsync(Guid temporaryFileKey, Guid? parentKey, Guid userKey); } diff --git a/src/Umbraco.Core/CompatibilitySuppressions.xml b/src/Umbraco.Core/CompatibilitySuppressions.xml index 59295e323a..c8b8cf85b6 100644 --- a/src/Umbraco.Core/CompatibilitySuppressions.xml +++ b/src/Umbraco.Core/CompatibilitySuppressions.xml @@ -1,5 +1,4 @@  - CP0001 @@ -897,6 +896,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IDataTypeService.CopyAsync(Umbraco.Cms.Core.Models.IDataType,System.Nullable{System.Guid},System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IDataTypeService.CopyAsync(Umbraco.Cms.Core.Models.IDataType,System.Nullable{System.Guid},System.Int32) @@ -904,6 +910,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IDataTypeService.CreateAsync(Umbraco.Cms.Core.Models.IDataType,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IDataTypeService.CreateAsync(Umbraco.Cms.Core.Models.IDataType,System.Int32) @@ -911,6 +924,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IDataTypeService.DeleteAsync(System.Guid,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IDataTypeService.DeleteAsync(System.Guid,System.Int32) @@ -946,6 +966,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IDataTypeService.MoveAsync(Umbraco.Cms.Core.Models.IDataType,System.Nullable{System.Guid},System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IDataTypeService.MoveAsync(Umbraco.Cms.Core.Models.IDataType,System.Nullable{System.Guid},System.Int32) @@ -953,6 +980,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IDataTypeService.UpdateAsync(Umbraco.Cms.Core.Models.IDataType,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IDataTypeService.UpdateAsync(Umbraco.Cms.Core.Models.IDataType,System.Int32) @@ -1030,6 +1064,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IPackagingService.CreateCreatedPackageAsync(Umbraco.Cms.Core.Packaging.PackageDefinition,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IPackagingService.CreateCreatedPackageAsync(Umbraco.Cms.Core.Packaging.PackageDefinition,System.Int32) @@ -1037,6 +1078,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IPackagingService.DeleteCreatedPackageAsync(System.Guid,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IPackagingService.DeleteCreatedPackageAsync(System.Guid,System.Int32) @@ -1072,6 +1120,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IPackagingService.UpdateCreatedPackageAsync(Umbraco.Cms.Core.Packaging.PackageDefinition,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IPackagingService.UpdateCreatedPackageAsync(Umbraco.Cms.Core.Packaging.PackageDefinition,System.Int32) @@ -1079,6 +1134,20 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IRelationService.CreateAsync(Umbraco.Cms.Core.Models.IRelationType,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + + + CP0006 + M:Umbraco.Cms.Core.Services.IRelationService.DeleteAsync(System.Guid,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.IRelationService.GetAllowedObjectTypes @@ -1093,6 +1162,13 @@ lib/net7.0/Umbraco.Core.dll true + + CP0006 + M:Umbraco.Cms.Core.Services.IRelationService.UpdateAsync(Umbraco.Cms.Core.Models.IRelationType,System.Guid) + lib/net7.0/Umbraco.Core.dll + lib/net7.0/Umbraco.Core.dll + true + CP0006 M:Umbraco.Cms.Core.Services.ITrackedReferencesService.GetPagedDescendantsInReferencesAsync(System.Guid,System.Int64,System.Int64,System.Boolean) diff --git a/src/Umbraco.Core/Services/ContentEditingService.cs b/src/Umbraco.Core/Services/ContentEditingService.cs index 4b70e88bb0..3f2d63c9a6 100644 --- a/src/Umbraco.Core/Services/ContentEditingService.cs +++ b/src/Umbraco.Core/Services/ContentEditingService.cs @@ -12,6 +12,8 @@ internal sealed class ContentEditingService { private readonly ITemplateService _templateService; private readonly ILogger _logger; + private readonly ICoreScopeProvider _scopeProvider; + private readonly IUserService _userService; public ContentEditingService( IContentService contentService, @@ -20,11 +22,14 @@ internal sealed class ContentEditingService IDataTypeService dataTypeService, ITemplateService templateService, ILogger logger, - ICoreScopeProvider scopeProvider) + ICoreScopeProvider scopeProvider, + IUserService userService) : base(contentService, contentTypeService, propertyEditorCollection, dataTypeService, logger, scopeProvider) { _templateService = templateService; _logger = logger; + _scopeProvider = scopeProvider; + _userService = userService; } public async Task GetAsync(Guid id) @@ -33,7 +38,7 @@ internal sealed class ContentEditingService return await Task.FromResult(content); } - public async Task> CreateAsync(ContentCreateModel createModel, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(ContentCreateModel createModel, Guid userKey) { Attempt result = await MapCreate(createModel); if (result.Success == false) @@ -48,13 +53,13 @@ internal sealed class ContentEditingService return Attempt.FailWithStatus(operationStatus, content); } - operationStatus = Save(content, userId); + operationStatus = Save(content, userKey); return operationStatus == ContentEditingOperationStatus.Success ? Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, content) : Attempt.FailWithStatus(operationStatus, content); } - public async Task> UpdateAsync(IContent content, ContentUpdateModel updateModel, int userId = Constants.Security.SuperUserId) + public async Task> UpdateAsync(IContent content, ContentUpdateModel updateModel, Guid userKey) { Attempt result = await MapUpdate(content, updateModel); if (result.Success == false) @@ -68,17 +73,23 @@ internal sealed class ContentEditingService return Attempt.FailWithStatus(operationStatus, content); } - operationStatus = Save(content, userId); + operationStatus = Save(content, userKey); return operationStatus == ContentEditingOperationStatus.Success ? Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, content) : Attempt.FailWithStatus(operationStatus, content); } - public async Task> MoveToRecycleBinAsync(Guid id, int userId = Constants.Security.SuperUserId) - => await HandleDeletionAsync(id, content => ContentService.MoveToRecycleBin(content, userId), false); + public async Task> MoveToRecycleBinAsync(Guid id, Guid userKey) + { + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + return await HandleDeletionAsync(id, content => ContentService.MoveToRecycleBin(content, currentUserId), false); + } - public async Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId) - => await HandleDeletionAsync(id, content => ContentService.Delete(content, userId), true); + public async Task> DeleteAsync(Guid id, Guid userKey) + { + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + return await HandleDeletionAsync(id, content => ContentService.Delete(content, currentUserId), false); + } protected override IContent Create(string? name, int parentId, IContentType contentType) => new Content(name, parentId, contentType); @@ -107,11 +118,12 @@ internal sealed class ContentEditingService return ContentEditingOperationStatus.Success; } - private ContentEditingOperationStatus Save(IContent content, int userId) + private ContentEditingOperationStatus Save(IContent content, Guid userKey) { try { - OperationResult saveResult = ContentService.Save(content, userId); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + OperationResult saveResult = ContentService.Save(content, currentUserId); return saveResult.Result switch { // these are the only result states currently expected from Save diff --git a/src/Umbraco.Core/Services/DataTypeContainerService.cs b/src/Umbraco.Core/Services/DataTypeContainerService.cs index 4e54609e96..0bfcc1594a 100644 --- a/src/Umbraco.Core/Services/DataTypeContainerService.cs +++ b/src/Umbraco.Core/Services/DataTypeContainerService.cs @@ -14,6 +14,7 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon private readonly IDataTypeContainerRepository _dataTypeContainerRepository; private readonly IAuditRepository _auditRepository; private readonly IEntityRepository _entityRepository; + private readonly IUserService _userService; public DataTypeContainerService( ICoreScopeProvider provider, @@ -21,12 +22,14 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon IEventMessagesFactory eventMessagesFactory, IDataTypeContainerRepository dataTypeContainerRepository, IAuditRepository auditRepository, - IEntityRepository entityRepository) + IEntityRepository entityRepository, + IUserService userService) : base(provider, loggerFactory, eventMessagesFactory) { _dataTypeContainerRepository = dataTypeContainerRepository; _auditRepository = auditRepository; _entityRepository = entityRepository; + _userService = userService; } /// @@ -45,10 +48,10 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon => await Task.FromResult(GetParent(dataType)); /// - public async Task> CreateAsync(EntityContainer container, Guid? parentId = null, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(EntityContainer container, Guid? parentKey, Guid userKey) => await SaveAsync( container, - userId, + userKey, () => { if (container.Id > 0) @@ -56,11 +59,11 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon return DataTypeContainerOperationStatus.InvalidId; } - EntityContainer? parentContainer = parentId.HasValue - ? _dataTypeContainerRepository.Get(parentId.Value) + EntityContainer? parentContainer = parentKey.HasValue + ? _dataTypeContainerRepository.Get(parentKey.Value) : null; - if (parentId.HasValue && parentContainer == null) + if (parentKey.HasValue && parentContainer == null) { return DataTypeContainerOperationStatus.ParentNotFound; } @@ -71,10 +74,10 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon AuditType.New); /// - public async Task> UpdateAsync(EntityContainer container, int userId = Constants.Security.SuperUserId) + public async Task> UpdateAsync(EntityContainer container, Guid userKey) => await SaveAsync( container, - userId, + userKey, () => { if (container.Id == 0) @@ -93,7 +96,7 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon AuditType.New); /// - public async Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId) + public async Task> DeleteAsync(Guid id, Guid userKey) { using ICoreScope scope = ScopeProvider.CreateCoreScope(); @@ -123,7 +126,8 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon _dataTypeContainerRepository.Delete(container); - Audit(AuditType.Delete, userId, container.Id); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Delete, currentUserId, container.Id); scope.Complete(); scope.Notifications.Publish(new EntityContainerDeletedNotification(container, eventMessages).WithStateFrom(deletingEntityContainerNotification)); @@ -131,7 +135,7 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon return Attempt.SucceedWithStatus(DataTypeContainerOperationStatus.Success, container); } - private async Task> SaveAsync(EntityContainer container, int userId, Func operationValidation, AuditType auditType) + private async Task> SaveAsync(EntityContainer container, Guid userKey, Func operationValidation, AuditType auditType) { if (container.ContainedObjectType != Constants.ObjectTypes.DataType) { @@ -156,7 +160,8 @@ internal sealed class DataTypeContainerService : RepositoryService, IDataTypeCon _dataTypeContainerRepository.Save(container); - Audit(auditType, userId, container.Id); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(auditType, currentUserId, container.Id); scope.Complete(); scope.Notifications.Publish(new EntityContainerSavedNotification(container, eventMessages).WithStateFrom(savingEntityContainerNotification)); diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index a96f147cda..ad6e85d793 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -30,6 +30,7 @@ namespace Umbraco.Cms.Core.Services.Implement private readonly IAuditRepository _auditRepository; private readonly IIOHelper _ioHelper; private readonly IEditorConfigurationParser _editorConfigurationParser; + private readonly IUserService _userService; private readonly IDataTypeContainerService _dataTypeContainerService; [Obsolete("Please use the constructor that takes less parameters. Will be removed in V15.")] @@ -62,6 +63,7 @@ namespace Umbraco.Cms.Core.Services.Implement { } + public DataTypeService( ICoreScopeProvider provider, ILoggerFactory loggerFactory, @@ -81,6 +83,9 @@ namespace Umbraco.Cms.Core.Services.Implement _ioHelper = ioHelper; _editorConfigurationParser = editorConfigurationParser; + // Trying to inject user service will cause ambigious constructors, this should be properly DI, when old ctor is removed. + _userService = StaticServiceProvider.Instance.GetRequiredService(); + // resolve dependencies for obsolete methods through the static service provider, so they don't pollute the constructor signature _dataTypeContainerService = StaticServiceProvider.Instance.GetRequiredService(); _dataTypeContainerRepository = StaticServiceProvider.Instance.GetRequiredService(); @@ -106,7 +111,8 @@ namespace Umbraco.Cms.Core.Services.Implement Key = key }; - Attempt result = _dataTypeContainerService.CreateAsync(container, parentKey, userId).GetAwaiter().GetResult(); + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + Attempt result = _dataTypeContainerService.CreateAsync(container, parentKey, currentUserKey).GetAwaiter().GetResult(); // mimic old service behavior return result.Status switch @@ -171,10 +177,11 @@ namespace Umbraco.Cms.Core.Services.Implement { var isNew = container.Id == 0; Guid? parentKey = isNew && container.ParentId > 0 ? _dataTypeContainerRepository.Get(container.ParentId)?.Key : null; + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; Attempt result = isNew - ? _dataTypeContainerService.CreateAsync(container, parentKey, userId).GetAwaiter().GetResult() - : _dataTypeContainerService.UpdateAsync(container, userId).GetAwaiter().GetResult(); + ? _dataTypeContainerService.CreateAsync(container, parentKey, currentUserKey).GetAwaiter().GetResult() + : _dataTypeContainerService.UpdateAsync(container, currentUserKey).GetAwaiter().GetResult(); // mimic old service behavior return result.Status switch @@ -200,7 +207,8 @@ namespace Umbraco.Cms.Core.Services.Implement return OperationResult.Attempt.NoOperation(evtMsgs); } - Attempt result = _dataTypeContainerService.DeleteAsync(container.Key, userId).GetAwaiter().GetResult(); + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + Attempt result = _dataTypeContainerService.DeleteAsync(container.Key, currentUserKey).GetAwaiter().GetResult(); // mimic old service behavior return result.Status switch { @@ -229,8 +237,8 @@ namespace Umbraco.Cms.Core.Services.Implement } container.Name = name; - - Attempt result = _dataTypeContainerService.UpdateAsync(container, userId).GetAwaiter().GetResult(); + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + Attempt result = _dataTypeContainerService.UpdateAsync(container, currentUserKey).GetAwaiter().GetResult(); // mimic old service behavior return result.Status switch { @@ -368,7 +376,7 @@ namespace Umbraco.Cms.Core.Services.Implement containerKey = container.Key; } - Attempt result = MoveAsync(toMove, containerKey).GetAwaiter().GetResult(); + Attempt result = MoveAsync(toMove, containerKey, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); // mimic old service behavior EventMessages evtMsgs = EventMessagesFactory.Get(); @@ -381,7 +389,7 @@ namespace Umbraco.Cms.Core.Services.Implement }; } - public async Task> MoveAsync(IDataType toMove, Guid? containerKey, int userId = Constants.Security.SuperUserId) + public async Task> MoveAsync(IDataType toMove, Guid? containerKey, Guid userKey) { EventMessages eventMessages = EventMessagesFactory.Get(); @@ -417,7 +425,8 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Notifications.Publish(new DataTypeMovedNotification(moveEventInfo, eventMessages).WithStateFrom(movingDataTypeNotification)); - Audit(AuditType.Move, userId, toMove.Id); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Move, currentUserId, toMove.Id); scope.Complete(); } @@ -445,7 +454,8 @@ namespace Umbraco.Cms.Core.Services.Implement containerKey = container.Key; } - Attempt result = CopyAsync(copying, containerKey, userId).GetAwaiter().GetResult(); + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + Attempt result = CopyAsync(copying, containerKey, currentUserKey).GetAwaiter().GetResult(); // mimic old service behavior EventMessages evtMsgs = EventMessagesFactory.Get(); @@ -459,7 +469,7 @@ namespace Umbraco.Cms.Core.Services.Implement } /// - public async Task> CopyAsync(IDataType toCopy, Guid? containerKey, int userId = Constants.Security.SuperUserId) + public async Task> CopyAsync(IDataType toCopy, Guid? containerKey, Guid userKey) { EntityContainer? container = null; if (containerKey.HasValue && containerKey.Value != Guid.Empty) @@ -475,7 +485,7 @@ namespace Umbraco.Cms.Core.Services.Implement copy.Name += " (copy)"; // might not be unique copy.ParentId = container?.Id ?? Constants.System.Root; - return await SaveAsync(copy, () => DataTypeOperationStatus.Success, userId, AuditType.Copy); + return await SaveAsync(copy, () => DataTypeOperationStatus.Success, userKey, AuditType.Copy); } /// @@ -497,26 +507,29 @@ namespace Umbraco.Cms.Core.Services.Implement throw new InvalidOperationException("Name cannot be more than 255 characters in length."); } - Attempt result = SaveAsync( + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + + + SaveAsync( dataType, () => DataTypeOperationStatus.Success, - userId, + currentUserKey, AuditType.Sort).GetAwaiter().GetResult(); } /// - public async Task> CreateAsync(IDataType dataType, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(IDataType dataType, Guid userKey) { if (dataType.Id != 0) { return Attempt.FailWithStatus(DataTypeOperationStatus.InvalidId, dataType); } - return await SaveAsync(dataType, () => DataTypeOperationStatus.Success, userId, AuditType.New); + return await SaveAsync(dataType, () => DataTypeOperationStatus.Success, userKey, AuditType.New); } /// - public async Task> UpdateAsync(IDataType dataType, int userId = Constants.Security.SuperUserId) + public async Task> UpdateAsync(IDataType dataType, Guid userKey) => await SaveAsync( dataType, () => @@ -526,7 +539,7 @@ namespace Umbraco.Cms.Core.Services.Implement ? DataTypeOperationStatus.NotFound : DataTypeOperationStatus.Success; }, - userId, + userKey, AuditType.New); /// @@ -571,10 +584,13 @@ namespace Umbraco.Cms.Core.Services.Implement /// to delete /// Optional Id of the user issuing the deletion public void Delete(IDataType dataType, int userId = Constants.Security.SuperUserId) - => DeleteAsync(dataType.Key, userId).GetAwaiter().GetResult(); + { + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + DeleteAsync(dataType.Key, currentUserKey).GetAwaiter().GetResult(); + } /// - public async Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId) + public async Task> DeleteAsync(Guid id, Guid userKey) { EventMessages eventMessages = EventMessagesFactory.Get(); using ICoreScope scope = ScopeProvider.CreateCoreScope(); @@ -626,7 +642,9 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Notifications.Publish(new DataTypeDeletedNotification(dataType, eventMessages).WithStateFrom(deletingDataTypeNotification)); - Audit(AuditType.Delete, userId, dataType.Id); + + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Delete, currentUserId, dataType.Id); scope.Complete(); @@ -670,7 +688,7 @@ namespace Umbraco.Cms.Core.Services.Implement private async Task> SaveAsync( IDataType dataType, Func operationValidation, - int userId, + Guid userKey, AuditType auditType) { IEnumerable validationResults = ValidateConfigurationData(dataType); @@ -683,7 +701,9 @@ namespace Umbraco.Cms.Core.Services.Implement } EventMessages eventMessages = EventMessagesFactory.Get(); - dataType.CreatorId = userId; + + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + dataType.CreatorId = currentUserId; using ICoreScope scope = ScopeProvider.CreateCoreScope(); @@ -714,7 +734,7 @@ namespace Umbraco.Cms.Core.Services.Implement scope.Notifications.Publish(new DataTypeSavedNotification(dataType, eventMessages).WithStateFrom(savingDataTypeNotification)); - Audit(auditType, userId, dataType.Id); + Audit(auditType, currentUserId, dataType.Id); scope.Complete(); return Attempt.SucceedWithStatus(DataTypeOperationStatus.Success, dataType); diff --git a/src/Umbraco.Core/Services/DictionaryItemService.cs b/src/Umbraco.Core/Services/DictionaryItemService.cs index 319808eebc..e6c8605d83 100644 --- a/src/Umbraco.Core/Services/DictionaryItemService.cs +++ b/src/Umbraco.Core/Services/DictionaryItemService.cs @@ -14,6 +14,7 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem private readonly IDictionaryRepository _dictionaryRepository; private readonly IAuditRepository _auditRepository; private readonly ILanguageService _languageService; + private readonly IUserService _userService; public DictionaryItemService( ICoreScopeProvider provider, @@ -21,12 +22,14 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem IEventMessagesFactory eventMessagesFactory, IDictionaryRepository dictionaryRepository, IAuditRepository auditRepository, - ILanguageService languageService) + ILanguageService languageService, + IUserService userService) : base(provider, loggerFactory, eventMessagesFactory) { _dictionaryRepository = dictionaryRepository; _auditRepository = auditRepository; _languageService = languageService; + _userService = userService; } /// @@ -98,7 +101,7 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem } /// - public async Task> CreateAsync(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(IDictionaryItem dictionaryItem, Guid userKey) { if (dictionaryItem.Id != 0) { @@ -118,12 +121,12 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem }, AuditType.New, "Create DictionaryItem", - userId); + userKey); } /// public async Task> UpdateAsync( - IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId) + IDictionaryItem dictionaryItem, Guid userKey) => await SaveAsync( dictionaryItem, () => @@ -138,10 +141,10 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem }, AuditType.Save, "Update DictionaryItem", - userId); + userKey); /// - public async Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId) + public async Task> DeleteAsync(Guid id, Guid userKey) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { @@ -164,7 +167,8 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem new DictionaryItemDeletedNotification(dictionaryItem, eventMessages) .WithStateFrom(deletingNotification)); - Audit(AuditType.Delete, "Delete DictionaryItem", userId, dictionaryItem.Id, nameof(DictionaryItem)); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Delete, "Delete DictionaryItem", currentUserId, dictionaryItem.Id, nameof(DictionaryItem)); scope.Complete(); return await Task.FromResult(Attempt.SucceedWithStatus(DictionaryItemOperationStatus.Success, dictionaryItem)); @@ -175,7 +179,7 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem public async Task> MoveAsync( IDictionaryItem dictionaryItem, Guid? parentId, - int userId = Constants.Security.SuperUserId) + Guid userKey) { // same parent? then just ignore this operation, assume success. if (dictionaryItem.ParentId == parentId) @@ -225,7 +229,8 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem scope.Notifications.Publish( new DictionaryItemMovedNotification(moveEventInfo, eventMessages).WithStateFrom(movingNotification)); - Audit(AuditType.Move, "Move DictionaryItem", userId, dictionaryItem.Id, nameof(DictionaryItem)); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Move, "Move DictionaryItem", currentUserId, dictionaryItem.Id, nameof(DictionaryItem)); scope.Complete(); return await Task.FromResult(Attempt.SucceedWithStatus(DictionaryItemOperationStatus.Success, dictionaryItem)); @@ -237,7 +242,7 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem Func operationValidation, AuditType auditType, string auditMessage, - int userId) + Guid userKey) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { @@ -276,7 +281,8 @@ internal sealed class DictionaryItemService : RepositoryService, IDictionaryItem scope.Notifications.Publish( new DictionaryItemSavedNotification(dictionaryItem, eventMessages).WithStateFrom(savingNotification)); - Audit(auditType, auditMessage, userId, dictionaryItem.Id, nameof(DictionaryItem)); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(auditType, auditMessage, currentUserId, dictionaryItem.Id, nameof(DictionaryItem)); scope.Complete(); return await Task.FromResult(Attempt.SucceedWithStatus(DictionaryItemOperationStatus.Success, dictionaryItem)); diff --git a/src/Umbraco.Core/Services/FileService.cs b/src/Umbraco.Core/Services/FileService.cs index 354cd0a0ef..818e522baa 100644 --- a/src/Umbraco.Core/Services/FileService.cs +++ b/src/Umbraco.Core/Services/FileService.cs @@ -34,6 +34,7 @@ public class FileService : RepositoryService, IFileService private readonly IStylesheetRepository _stylesheetRepository; private readonly ITemplateService _templateService; private readonly ITemplateRepository _templateRepository; + private readonly IUserService _userService; [Obsolete("Use other ctor - will be removed in Umbraco 15")] public FileService( @@ -61,12 +62,13 @@ public class FileService : RepositoryService, IFileService hostingEnvironment, StaticServiceProvider.Instance.GetRequiredService(), templateRepository, + StaticServiceProvider.Instance.GetRequiredService(), shortStringHelper, - globalSettings - ) + globalSettings) { } + [ActivatorUtilitiesConstructor] public FileService( ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, @@ -79,8 +81,8 @@ public class FileService : RepositoryService, IFileService IHostingEnvironment hostingEnvironment, ITemplateService templateService, ITemplateRepository templateRepository, - // unused dependencies but the DI forces us to have them, otherwise we'll get an "ambiguous constructor" - // exception (and [ActivatorUtilitiesConstructor] doesn't work here either) + IUserService userService, + // We need these else it will be ambigious ctors IShortStringHelper shortStringHelper, IOptions globalSettings) : base(uowProvider, loggerFactory, eventMessagesFactory) @@ -93,6 +95,7 @@ public class FileService : RepositoryService, IFileService _hostingEnvironment = hostingEnvironment; _templateService = templateService; _templateRepository = templateRepository; + _userService = userService; } #region Stylesheets @@ -380,7 +383,8 @@ public class FileService : RepositoryService, IFileService throw new InvalidOperationException("Name cannot be more than 255 characters in length."); } - Attempt result = _templateService.CreateForContentTypeAsync(contentTypeAlias, contentTypeName, userId).GetAwaiter().GetResult(); + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + Attempt result = _templateService.CreateForContentTypeAsync(contentTypeAlias, contentTypeName, currentUserKey).GetAwaiter().GetResult(); // mimic old service behavior EventMessages eventMessages = EventMessagesFactory.Get(); @@ -414,7 +418,8 @@ public class FileService : RepositoryService, IFileService throw new ArgumentOutOfRangeException(nameof(name), "Name cannot be more than 255 characters in length."); } - Attempt result = _templateService.CreateAsync(name, alias, content, userId).GetAwaiter().GetResult(); + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + Attempt result = _templateService.CreateAsync(name, alias, content, currentUserKey).GetAwaiter().GetResult(); return result.Result; } @@ -490,13 +495,14 @@ public class FileService : RepositoryService, IFileService "Name cannot be null, empty, contain only white-space characters or be more than 255 characters in length."); } + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; if (template.Id > 0) { - _templateService.UpdateAsync(template, userId).GetAwaiter().GetResult(); + _templateService.UpdateAsync(template, currentUserKey).GetAwaiter().GetResult(); } else { - _templateService.CreateAsync(template, userId).GetAwaiter().GetResult(); + _templateService.CreateAsync(template, currentUserKey).GetAwaiter().GetResult(); } } @@ -541,7 +547,10 @@ public class FileService : RepositoryService, IFileService /// [Obsolete("Please use ITemplateService for template operations - will be removed in Umbraco 15")] public void DeleteTemplate(string alias, int userId = Constants.Security.SuperUserId) - => _templateService.DeleteAsync(alias, userId).GetAwaiter().GetResult(); + { + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + _templateService.DeleteAsync(alias, currentUserKey).GetAwaiter().GetResult(); + } /// [Obsolete("Please use ITemplateService for template operations - will be removed in Umbraco 15")] diff --git a/src/Umbraco.Core/Services/IContentEditingService.cs b/src/Umbraco.Core/Services/IContentEditingService.cs index 512a0fb3ad..7018571af6 100644 --- a/src/Umbraco.Core/Services/IContentEditingService.cs +++ b/src/Umbraco.Core/Services/IContentEditingService.cs @@ -8,11 +8,11 @@ public interface IContentEditingService { Task GetAsync(Guid id); - Task> CreateAsync(ContentCreateModel createModel, int userId = Constants.Security.SuperUserId); + Task> CreateAsync(ContentCreateModel createModel, Guid userKey); - Task> UpdateAsync(IContent content, ContentUpdateModel updateModel, int userId = Constants.Security.SuperUserId); + Task> UpdateAsync(IContent content, ContentUpdateModel updateModel, Guid userKey); - Task> MoveToRecycleBinAsync(Guid id, int userId = Constants.Security.SuperUserId); + Task> MoveToRecycleBinAsync(Guid id, Guid userKey); - Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId); + Task> DeleteAsync(Guid id, Guid userKey); } diff --git a/src/Umbraco.Core/Services/IDataTypeContainerService.cs b/src/Umbraco.Core/Services/IDataTypeContainerService.cs index fc7ff8a5a6..6f5220583d 100644 --- a/src/Umbraco.Core/Services/IDataTypeContainerService.cs +++ b/src/Umbraco.Core/Services/IDataTypeContainerService.cs @@ -23,25 +23,25 @@ public interface IDataTypeContainerService /// Creates a new data type container /// /// The container to create. - /// The ID of the parent container to create the new container under. - /// The ID of the user issuing the creation. + /// The ID of the parent container to create the new container under. + /// Key of the user issuing the creation. /// - /// If no parent ID is supplied, the container will be created at the data type tree root. - Task> CreateAsync(EntityContainer container, Guid? parentId = null, int userId = Constants.Security.SuperUserId); + /// If parent key is supplied as null, the container will be created at the data type tree root. + Task> CreateAsync(EntityContainer container, Guid? parentKey, Guid userKey); /// /// Updates an existing data type container /// /// The container to create. - /// The ID of the user issuing the update. + /// Key of the user issuing the update. /// - Task> UpdateAsync(EntityContainer container, int userId = Constants.Security.SuperUserId); + Task> UpdateAsync(EntityContainer container, Guid userKey); /// /// Deletes a data type container /// /// The ID of the container to delete. - /// The ID of the user issuing the deletion. + /// Key of the user issuing the deletion. /// - Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId); + Task> DeleteAsync(Guid id, Guid userKey); } diff --git a/src/Umbraco.Core/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs index 5edbad40ab..6d9cae9a99 100644 --- a/src/Umbraco.Core/Services/IDataTypeService.cs +++ b/src/Umbraco.Core/Services/IDataTypeService.cs @@ -127,15 +127,15 @@ public interface IDataTypeService : IService /// Creates a new /// /// to create - /// Id of the user issuing the creation - Task> CreateAsync(IDataType dataType, int userId = Constants.Security.SuperUserId); + /// Key of the user issuing the creation + Task> CreateAsync(IDataType dataType, Guid userKey); /// /// Updates an existing /// /// to update - /// Id of the user issuing the update - Task> UpdateAsync(IDataType dataType, int userId = Constants.Security.SuperUserId); + /// Key of the user issuing the update + Task> UpdateAsync(IDataType dataType, Guid userKey); /// /// Deletes an @@ -157,8 +157,8 @@ public interface IDataTypeService : IService /// all the data that references this . /// /// The guid Id of the to delete - /// Id of the user issuing the deletion - Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId); + /// Key of the user issuing the deletion + Task> DeleteAsync(Guid id, Guid userKey); /// /// Gets a by its control Id @@ -183,9 +183,9 @@ public interface IDataTypeService : IService /// /// The data type that will be moved /// The container key where the data type will be moved to. - /// The user that did the Move action + /// The user that did the Move action /// - Task> MoveAsync(IDataType toMove, Guid? containerKey, int userId = Constants.Security.SuperUserId); + Task> MoveAsync(IDataType toMove, Guid? containerKey, Guid userKey); [Obsolete("Please use CopyASync instead. Will be removed in V15")] Attempt?> Copy(IDataType copying, int containerId) => Copy(copying, containerId, Constants.Security.SuperUserId); @@ -198,9 +198,9 @@ public interface IDataTypeService : IService /// /// The data type that will be copied /// The container key where the data type will be copied to. - /// The user that did the Copy action + /// The user that did the Copy action /// - Task> CopyAsync(IDataType toCopy, Guid? containerKey, int userId = Constants.Security.SuperUserId); + Task> CopyAsync(IDataType toCopy, Guid? containerKey, Guid userKey); /// /// Performs validation for the configuration data of a given data type. diff --git a/src/Umbraco.Core/Services/IDictionaryItemService.cs b/src/Umbraco.Core/Services/IDictionaryItemService.cs index 7aa5f2364a..19f380c4ab 100644 --- a/src/Umbraco.Core/Services/IDictionaryItemService.cs +++ b/src/Umbraco.Core/Services/IDictionaryItemService.cs @@ -72,30 +72,30 @@ public interface IDictionaryItemService /// Creates and saves a new dictionary item and assigns translations to all applicable languages if specified /// /// to create - /// Optional id of the user saving the dictionary item + /// Key of the user saving the dictionary item /// - Task> CreateAsync(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId); + Task> CreateAsync(IDictionaryItem dictionaryItem, Guid userKey); /// /// Updates an existing object /// /// to update - /// Optional id of the user saving the dictionary item - Task> UpdateAsync(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId); + /// Key of the user saving the dictionary item + Task> UpdateAsync(IDictionaryItem dictionaryItem, Guid userKey); /// /// Deletes a object and its related translations /// as well as its children. /// /// The ID of the to delete - /// Optional id of the user deleting the dictionary item - Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId); + /// Key of the user deleting the dictionary item + Task> DeleteAsync(Guid id, Guid userKey); /// /// Moves a object /// /// to move /// Id of the new parent, null if the item should be moved to the root - /// Optional id of the user moving the dictionary item - Task> MoveAsync(IDictionaryItem dictionaryItem, Guid? parentId, int userId = Constants.Security.SuperUserId); + /// Key of the user moving the dictionary item + Task> MoveAsync(IDictionaryItem dictionaryItem, Guid? parentId, Guid userKey); } diff --git a/src/Umbraco.Core/Services/ILanguageService.cs b/src/Umbraco.Core/Services/ILanguageService.cs index 8217844e28..c05af8c8b2 100644 --- a/src/Umbraco.Core/Services/ILanguageService.cs +++ b/src/Umbraco.Core/Services/ILanguageService.cs @@ -33,20 +33,20 @@ public interface ILanguageService /// Updates an existing object /// /// to update - /// Optional id of the user saving the language - Task> UpdateAsync(ILanguage language, int userId = Constants.Security.SuperUserId); + /// Key of the user saving the language + Task> UpdateAsync(ILanguage language, Guid userKey); /// /// Creates a new object /// /// to create - /// Optional id of the user creating the language - Task> CreateAsync(ILanguage language, int userId = Constants.Security.SuperUserId); + /// Key of the user creating the language + Task> CreateAsync(ILanguage language, Guid userKey); /// /// Deletes a by removing it and its usages from the db /// /// The ISO code of the to delete - /// Optional id of the user deleting the language - Task> DeleteAsync(string isoCode, int userId = Constants.Security.SuperUserId); + /// Key of the user deleting the language + Task> DeleteAsync(string isoCode, Guid userKey); } diff --git a/src/Umbraco.Core/Services/IMediaEditingService.cs b/src/Umbraco.Core/Services/IMediaEditingService.cs index 0187ca6977..ca3fe5ddc3 100644 --- a/src/Umbraco.Core/Services/IMediaEditingService.cs +++ b/src/Umbraco.Core/Services/IMediaEditingService.cs @@ -8,11 +8,11 @@ public interface IMediaEditingService { Task GetAsync(Guid id); - Task> CreateAsync(MediaCreateModel createModel, int userId = Constants.Security.SuperUserId); + Task> CreateAsync(MediaCreateModel createModel, Guid userKey); - Task> UpdateAsync(IMedia content, MediaUpdateModel updateModel, int userId = Constants.Security.SuperUserId); + Task> UpdateAsync(IMedia content, MediaUpdateModel updateModel, Guid userKey); - Task> MoveToRecycleBinAsync(Guid id, int userId = Constants.Security.SuperUserId); + Task> MoveToRecycleBinAsync(Guid id, Guid userKey); - Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId); + Task> DeleteAsync(Guid id, Guid userKey); } diff --git a/src/Umbraco.Core/Services/IPackagingService.cs b/src/Umbraco.Core/Services/IPackagingService.cs index 4c3849a789..8fd4b0cdd6 100644 --- a/src/Umbraco.Core/Services/IPackagingService.cs +++ b/src/Umbraco.Core/Services/IPackagingService.cs @@ -64,8 +64,8 @@ public interface IPackagingService : IService /// Deletes a created package by key. /// /// The key of the package. - /// Optional id of the user deleting the package. - Task> DeleteCreatedPackageAsync(Guid key, int userId = Constants.Security.SuperUserId); + /// Key of the user deleting the package. + Task> DeleteCreatedPackageAsync(Guid key, Guid userKey); /// /// Persists a package definition to storage @@ -78,13 +78,15 @@ public interface IPackagingService : IService /// Creates a new package. /// /// model for the package to create. - Task> CreateCreatedPackageAsync(PackageDefinition package, int userId); + /// Key of the user performing the create. + Task> CreateCreatedPackageAsync(PackageDefinition package, Guid userKey); /// /// Updates a created package. /// /// model for the package to update. - Task> UpdateCreatedPackageAsync(PackageDefinition package, int userId); + /// Key of the user performing the update. + Task> UpdateCreatedPackageAsync(PackageDefinition package, Guid userKey); /// /// Creates the package file and returns it's physical path diff --git a/src/Umbraco.Core/Services/IRelationService.cs b/src/Umbraco.Core/Services/IRelationService.cs index 766d26b43e..1f36ec5126 100644 --- a/src/Umbraco.Core/Services/IRelationService.cs +++ b/src/Umbraco.Core/Services/IRelationService.cs @@ -350,17 +350,17 @@ public interface IRelationService : IService /// Saves a /// /// RelationType to Save - /// Id of the user thats saving the relation type + /// Key of the user thats saving the relation type /// A with a status of whether the operations was a success or failure - Task> CreateAsync(IRelationType relationType, int userId) => throw new NotImplementedException(); + Task> CreateAsync(IRelationType relationType, Guid userKey); /// /// Saves a /// /// RelationType to Save - /// Id of the user thats saving the relation type + /// Key of the user thats saving the relation type /// A with a status of whether the operations was a success or failure - Task> UpdateAsync(IRelationType relationType, int userId) => throw new NotImplementedException(); + Task> UpdateAsync(IRelationType relationType, Guid userKey); /// /// Deletes a @@ -378,9 +378,9 @@ public interface IRelationService : IService /// Deletes a /// /// Key of the relation type to delete - /// Id of the user that is deleting the relation type + /// Key of the user that is deleting the relation type /// A representing the asynchronous operation. - Task> DeleteAsync(Guid key, int userId) => throw new NotImplementedException(); + Task> DeleteAsync(Guid key, Guid userKey); /// /// Deletes all objects based on the passed in diff --git a/src/Umbraco.Core/Services/ITemplateService.cs b/src/Umbraco.Core/Services/ITemplateService.cs index 5da85c7413..00371bada6 100644 --- a/src/Umbraco.Core/Services/ITemplateService.cs +++ b/src/Umbraco.Core/Services/ITemplateService.cs @@ -49,23 +49,23 @@ public interface ITemplateService : IService /// Updates a /// /// to update - /// Optional id of the user saving the template + /// Key of the user saving the template /// - Task> UpdateAsync(ITemplate template, int userId = Constants.Security.SuperUserId); + Task> UpdateAsync(ITemplate template, Guid userKey); /// /// Creates a template for a content type /// /// /// - /// + /// Key of the user performing the Create. /// /// The template created /// Task> CreateForContentTypeAsync( string contentTypeAlias, string? contentTypeName, - int userId = Constants.Security.SuperUserId); + Guid userKey); /// /// Creates a new template @@ -73,33 +73,33 @@ public interface ITemplateService : IService /// Name of the new template /// Alias of the template /// View content for the new template - /// Optional id of the user creating the template + /// Key of the user performing the Create. /// - Task> CreateAsync(string name, string alias, string? content, int userId = Constants.Security.SuperUserId); + Task> CreateAsync(string name, string alias, string? content, Guid userKey); /// /// Creates a new template /// /// The new template - /// Optional id of the user creating the template + /// Key of the user performing the Create. /// - Task> CreateAsync(ITemplate template, int userId = Constants.Security.SuperUserId); + Task> CreateAsync(ITemplate template, Guid userKey); /// /// Deletes a template by its alias /// /// Alias of the to delete - /// Optional id of the user deleting the template + /// Key of the user performing the Delete. /// True if the template was deleted, false otherwise - Task> DeleteAsync(string alias, int userId = Constants.Security.SuperUserId); + Task> DeleteAsync(string alias, Guid userKey); /// /// Deletes a template by its key /// /// Key of the to delete - /// Optional id of the user deleting the template + /// Key of the user performing the Delete. /// True if the template was deleted, false otherwise - Task> DeleteAsync(Guid key, int userId = Constants.Security.SuperUserId); + Task> DeleteAsync(Guid key, Guid userKey); /// /// Gets the content of a template as a stream. diff --git a/src/Umbraco.Core/Services/LanguageService.cs b/src/Umbraco.Core/Services/LanguageService.cs index f0fff46e51..59753c67f4 100644 --- a/src/Umbraco.Core/Services/LanguageService.cs +++ b/src/Umbraco.Core/Services/LanguageService.cs @@ -14,17 +14,20 @@ internal sealed class LanguageService : RepositoryService, ILanguageService { private readonly ILanguageRepository _languageRepository; private readonly IAuditRepository _auditRepository; + private readonly IUserService _userService; public LanguageService( ICoreScopeProvider provider, ILoggerFactory loggerFactory, IEventMessagesFactory eventMessagesFactory, ILanguageRepository languageRepository, - IAuditRepository auditRepository) + IAuditRepository auditRepository, + IUserService userService) : base(provider, loggerFactory, eventMessagesFactory) { _languageRepository = languageRepository; _auditRepository = auditRepository; + _userService = userService; } /// @@ -55,7 +58,7 @@ internal sealed class LanguageService : RepositoryService, ILanguageService } /// - public async Task> UpdateAsync(ILanguage language, int userId = Constants.Security.SuperUserId) + public async Task> UpdateAsync(ILanguage language, Guid userKey) => await SaveAsync( language, () => @@ -76,10 +79,10 @@ internal sealed class LanguageService : RepositoryService, ILanguageService }, AuditType.Save, "Update Language", - userId); + userKey); /// - public async Task> CreateAsync(ILanguage language, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(ILanguage language, Guid userKey) { if (language.Id != 0) { @@ -100,11 +103,11 @@ internal sealed class LanguageService : RepositoryService, ILanguageService }, AuditType.New, "Create Language", - userId); + userKey); } /// - public async Task> DeleteAsync(string isoCode, int userId = Constants.Security.SuperUserId) + public async Task> DeleteAsync(string isoCode, Guid userKey) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { @@ -136,7 +139,8 @@ internal sealed class LanguageService : RepositoryService, ILanguageService scope.Notifications.Publish( new LanguageDeletedNotification(language, eventMessages).WithStateFrom(deletingLanguageNotification)); - Audit(AuditType.Delete, "Delete Language", userId, language.Id, UmbracoObjectTypes.Language.GetName()); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Delete, "Delete Language", currentUserId, language.Id, UmbracoObjectTypes.Language.GetName()); scope.Complete(); return await Task.FromResult(Attempt.SucceedWithStatus(LanguageOperationStatus.Success, language)); } @@ -147,7 +151,7 @@ internal sealed class LanguageService : RepositoryService, ILanguageService Func operationValidation, AuditType auditType, string auditMessage, - int userId) + Guid userKey) { if (IsValidIsoCode(language.IsoCode) == false) { @@ -187,7 +191,8 @@ internal sealed class LanguageService : RepositoryService, ILanguageService scope.Notifications.Publish( new LanguageSavedNotification(language, eventMessages).WithStateFrom(savingNotification)); - Audit(auditType, auditMessage, userId, language.Id, UmbracoObjectTypes.Language.GetName()); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(auditType, auditMessage, currentUserId, language.Id, UmbracoObjectTypes.Language.GetName()); scope.Complete(); return await Task.FromResult(Attempt.SucceedWithStatus(LanguageOperationStatus.Success, language)); diff --git a/src/Umbraco.Core/Services/LocalizationService.cs b/src/Umbraco.Core/Services/LocalizationService.cs index 8acb155cbc..be36fc5671 100644 --- a/src/Umbraco.Core/Services/LocalizationService.cs +++ b/src/Umbraco.Core/Services/LocalizationService.cs @@ -22,8 +22,9 @@ internal class LocalizationService : RepositoryService, ILocalizationService private readonly ILanguageRepository _languageRepository; private readonly ILanguageService _languageService; private readonly IDictionaryItemService _dictionaryItemService; + private readonly IUserService _userService; - [Obsolete("Please use constructor with language and dictionary services. Will be removed in V15")] + [Obsolete("Please use constructor with language, dictionary and user services. Will be removed in V15")] public LocalizationService( ICoreScopeProvider provider, ILoggerFactory loggerFactory, @@ -39,7 +40,8 @@ internal class LocalizationService : RepositoryService, ILocalizationService auditRepository, languageRepository, StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService()) + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService()) { } @@ -52,7 +54,8 @@ internal class LocalizationService : RepositoryService, ILocalizationService IAuditRepository auditRepository, ILanguageRepository languageRepository, ILanguageService languageService, - IDictionaryItemService dictionaryItemService) + IDictionaryItemService dictionaryItemService, + IUserService userService) : base(provider, loggerFactory, eventMessagesFactory) { _dictionaryRepository = dictionaryRepository; @@ -60,6 +63,7 @@ internal class LocalizationService : RepositoryService, ILocalizationService _languageRepository = languageRepository; _languageService = languageService; _dictionaryItemService = dictionaryItemService; + _userService = userService; } /// @@ -105,7 +109,7 @@ internal class LocalizationService : RepositoryService, ILocalizationService .ToArray(); Attempt result = _dictionaryItemService - .CreateAsync(new DictionaryItem(parentId, key) { Translations = translations }) + .CreateAsync(new DictionaryItem(parentId, key) { Translations = translations }, Constants.Security.SuperUserKey) .GetAwaiter() .GetResult(); // mimic old service behavior @@ -217,13 +221,14 @@ internal class LocalizationService : RepositoryService, ILocalizationService [Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")] public void Save(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId) { + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; if (dictionaryItem.Id > 0) { - _dictionaryItemService.UpdateAsync(dictionaryItem, userId).GetAwaiter().GetResult(); + _dictionaryItemService.UpdateAsync(dictionaryItem, currentUserKey).GetAwaiter().GetResult(); } else { - _dictionaryItemService.CreateAsync(dictionaryItem, userId).GetAwaiter().GetResult(); + _dictionaryItemService.CreateAsync(dictionaryItem, currentUserKey).GetAwaiter().GetResult(); } } @@ -235,7 +240,10 @@ internal class LocalizationService : RepositoryService, ILocalizationService /// Optional id of the user deleting the dictionary item [Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")] public void Delete(IDictionaryItem dictionaryItem, int userId = Constants.Security.SuperUserId) - => _dictionaryItemService.DeleteAsync(dictionaryItem.Key, userId).GetAwaiter().GetResult(); + { + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + _dictionaryItemService.DeleteAsync(dictionaryItem.Key, currentUserKey).GetAwaiter().GetResult(); + } /// /// Gets a by its id @@ -313,9 +321,10 @@ internal class LocalizationService : RepositoryService, ILocalizationService [Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")] public void Save(ILanguage language, int userId = Constants.Security.SuperUserId) { + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; Attempt result = language.Id > 0 - ? _languageService.UpdateAsync(language, userId).GetAwaiter().GetResult() - : _languageService.CreateAsync(language, userId).GetAwaiter().GetResult(); + ? _languageService.UpdateAsync(language, currentUserKey).GetAwaiter().GetResult() + : _languageService.CreateAsync(language, currentUserKey).GetAwaiter().GetResult(); // mimic old Save behavior if (result.Status == LanguageOperationStatus.InvalidFallback) @@ -331,7 +340,10 @@ internal class LocalizationService : RepositoryService, ILocalizationService /// Optional id of the user deleting the language [Obsolete("Please use ILanguageService for language operations. Will be removed in V15.")] public void Delete(ILanguage language, int userId = Constants.Security.SuperUserId) - => _languageService.DeleteAsync(language.IsoCode, userId).GetAwaiter().GetResult(); + { + Guid currentUserKey = _userService.GetUserById(userId)?.Key ?? Constants.Security.SuperUserKey; + _languageService.DeleteAsync(language.IsoCode, currentUserKey).GetAwaiter().GetResult(); + } [Obsolete("Please use IDictionaryItemService for dictionary item operations. Will be removed in V15.")] public Dictionary GetDictionaryItemKeyMap() diff --git a/src/Umbraco.Core/Services/MediaEditingService.cs b/src/Umbraco.Core/Services/MediaEditingService.cs index 3f8fa20e47..cfd11f2a85 100644 --- a/src/Umbraco.Core/Services/MediaEditingService.cs +++ b/src/Umbraco.Core/Services/MediaEditingService.cs @@ -11,6 +11,7 @@ internal sealed class MediaEditingService : ContentEditingServiceBase, IMediaEditingService { private readonly ILogger> _logger; + private readonly IUserService _userService; public MediaEditingService( IMediaService contentService, @@ -18,9 +19,13 @@ internal sealed class MediaEditingService PropertyEditorCollection propertyEditorCollection, IDataTypeService dataTypeService, ILogger> logger, - ICoreScopeProvider scopeProvider) - : base(contentService, contentTypeService, propertyEditorCollection, dataTypeService, logger, scopeProvider) => + ICoreScopeProvider scopeProvider, + IUserService userService) + : base(contentService, contentTypeService, propertyEditorCollection, dataTypeService, logger, scopeProvider) + { _logger = logger; + _userService = userService; + } public async Task GetAsync(Guid id) { @@ -28,7 +33,7 @@ internal sealed class MediaEditingService return await Task.FromResult(media); } - public async Task> CreateAsync(MediaCreateModel createModel, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(MediaCreateModel createModel, Guid userKey) { Attempt result = await MapCreate(createModel); if (result.Success == false) @@ -38,13 +43,14 @@ internal sealed class MediaEditingService IMedia media = result.Result!; - ContentEditingOperationStatus operationStatus = Save(media, userId); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + ContentEditingOperationStatus operationStatus = Save(media, currentUserId); return operationStatus == ContentEditingOperationStatus.Success ? Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, media) : Attempt.FailWithStatus(operationStatus, media); } - public async Task> UpdateAsync(IMedia content, MediaUpdateModel updateModel, int userId = Constants.Security.SuperUserId) + public async Task> UpdateAsync(IMedia content, MediaUpdateModel updateModel, Guid userKey) { Attempt result = await MapUpdate(content, updateModel); if (result.Success == false) @@ -52,17 +58,24 @@ internal sealed class MediaEditingService return Attempt.FailWithStatus(result.Result, content); } - ContentEditingOperationStatus operationStatus = Save(content, userId); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + ContentEditingOperationStatus operationStatus = Save(content, currentUserId); return operationStatus == ContentEditingOperationStatus.Success ? Attempt.SucceedWithStatus(ContentEditingOperationStatus.Success, content) : Attempt.FailWithStatus(operationStatus, content); } - public async Task> MoveToRecycleBinAsync(Guid id, int userId = Constants.Security.SuperUserId) - => await HandleDeletionAsync(id, media => ContentService.MoveToRecycleBin(media, userId).Result, false); + public async Task> MoveToRecycleBinAsync(Guid id, Guid userKey) + { + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + return await HandleDeletionAsync(id, media => ContentService.MoveToRecycleBin(media, currentUserId).Result, false); + } - public async Task> DeleteAsync(Guid id, int userId = Constants.Security.SuperUserId) - => await HandleDeletionAsync(id, media => ContentService.Delete(media, userId).Result, true); + public async Task> DeleteAsync(Guid id, Guid userKey) + { + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + return await HandleDeletionAsync(id, media => ContentService.Delete(media, currentUserId).Result, true); + } protected override IMedia Create(string? name, int parentId, IMediaType contentType) => new Models.Media(name, parentId, contentType); diff --git a/src/Umbraco.Core/Services/RelationService.cs b/src/Umbraco.Core/Services/RelationService.cs index 2b0cec790e..de7ecd4084 100644 --- a/src/Umbraco.Core/Services/RelationService.cs +++ b/src/Umbraco.Core/Services/RelationService.cs @@ -1,4 +1,6 @@ +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.Entities; @@ -15,10 +17,12 @@ namespace Umbraco.Cms.Core.Services; public class RelationService : RepositoryService, IRelationService { private readonly IAuditRepository _auditRepository; + private readonly IUserService _userService; private readonly IEntityService _entityService; private readonly IRelationRepository _relationRepository; private readonly IRelationTypeRepository _relationTypeRepository; + [Obsolete("Please use ctor that takes all parameters, scheduled for removal in V15")] public RelationService( ICoreScopeProvider uowProvider, ILoggerFactory loggerFactory, @@ -27,11 +31,33 @@ public class RelationService : RepositoryService, IRelationService IRelationRepository relationRepository, IRelationTypeRepository relationTypeRepository, IAuditRepository auditRepository) + : this( + uowProvider, + loggerFactory, + eventMessagesFactory, + entityService, + relationRepository, + relationTypeRepository, + auditRepository, + StaticServiceProvider.Instance.GetRequiredService()) + { + } + + public RelationService( + ICoreScopeProvider uowProvider, + ILoggerFactory loggerFactory, + IEventMessagesFactory eventMessagesFactory, + IEntityService entityService, + IRelationRepository relationRepository, + IRelationTypeRepository relationTypeRepository, + IAuditRepository auditRepository, + IUserService userService) : base(uowProvider, loggerFactory, eventMessagesFactory) { _relationRepository = relationRepository; _relationTypeRepository = relationTypeRepository; _auditRepository = auditRepository; + _userService = userService; _entityService = entityService ?? throw new ArgumentNullException(nameof(entityService)); } @@ -539,7 +565,7 @@ public class RelationService : RepositoryService, IRelationService } } - public async Task> CreateAsync(IRelationType relationType, int userId) + public async Task> CreateAsync(IRelationType relationType, Guid userKey) { if (relationType.Id != 0) { @@ -551,18 +577,18 @@ public class RelationService : RepositoryService, IRelationService () => _relationTypeRepository.Get(relationType.Key) is not null ? RelationTypeOperationStatus.KeyAlreadyExists : RelationTypeOperationStatus.Success, AuditType.New, $"Created relation type: {relationType.Name}", - userId); + userKey); } - public async Task> UpdateAsync(IRelationType relationType, int userId) => + public async Task> UpdateAsync(IRelationType relationType, Guid userKey) => await SaveAsync( relationType, () => _relationTypeRepository.Get(relationType.Key) is null ? RelationTypeOperationStatus.NotFound : RelationTypeOperationStatus.Success, AuditType.Save, $"Created relation type: {relationType.Name}", - userId); + userKey); - private async Task> SaveAsync(IRelationType relationType, Func operationValidation, AuditType auditType, string auditMessage, int userId) + private async Task> SaveAsync(IRelationType relationType, Func operationValidation, AuditType auditType, string auditMessage, Guid userKey) { // Validate that parent & child object types are allowed UmbracoObjectTypes[] allowedObjectTypes = GetAllowedObjectTypes().ToArray(); @@ -596,7 +622,8 @@ public class RelationService : RepositoryService, IRelationService } _relationTypeRepository.Save(relationType); - Audit(auditType, userId, relationType.Id, auditMessage); + var currentUser = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(auditType, currentUser, relationType.Id, auditMessage); scope.Complete(); scope.Notifications.Publish( new RelationTypeSavedNotification(relationType, eventMessages).WithStateFrom(savingNotification)); @@ -645,7 +672,7 @@ public class RelationService : RepositoryService, IRelationService } } - public async Task> DeleteAsync(Guid key, int userId) + public async Task> DeleteAsync(Guid key, Guid userKey) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { @@ -664,7 +691,8 @@ public class RelationService : RepositoryService, IRelationService } _relationTypeRepository.Delete(relationType); - Audit(AuditType.Delete, userId, relationType.Id, "Deleted relation type"); + var currentUser = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Delete, currentUser, relationType.Id, "Deleted relation type"); scope.Notifications.Publish(new RelationTypeDeletedNotification(relationType, eventMessages).WithStateFrom(deletingNotification)); scope.Complete(); return await Task.FromResult(Attempt.SucceedWithStatus(RelationTypeOperationStatus.Success, relationType)); diff --git a/src/Umbraco.Core/Services/TemplateService.cs b/src/Umbraco.Core/Services/TemplateService.cs index a548580474..9dd00c50a3 100644 --- a/src/Umbraco.Core/Services/TemplateService.cs +++ b/src/Umbraco.Core/Services/TemplateService.cs @@ -1,4 +1,6 @@ -using Microsoft.Extensions.Logging; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Notifications; @@ -17,6 +19,7 @@ public class TemplateService : RepositoryService, ITemplateService private readonly ITemplateRepository _templateRepository; private readonly IAuditRepository _auditRepository; private readonly ITemplateContentParserService _templateContentParserService; + private readonly IUserService _userService; public TemplateService( ICoreScopeProvider provider, @@ -25,18 +28,41 @@ public class TemplateService : RepositoryService, ITemplateService IShortStringHelper shortStringHelper, ITemplateRepository templateRepository, IAuditRepository auditRepository, - ITemplateContentParserService templateContentParserService) + ITemplateContentParserService templateContentParserService, + IUserService userService) : base(provider, loggerFactory, eventMessagesFactory) { _shortStringHelper = shortStringHelper; _templateRepository = templateRepository; _auditRepository = auditRepository; _templateContentParserService = templateContentParserService; + _userService = userService; + } + + [Obsolete("Please use ctor that takes all parameters, scheduled for removal in v15")] + public TemplateService( + ICoreScopeProvider provider, + ILoggerFactory loggerFactory, + IEventMessagesFactory eventMessagesFactory, + IShortStringHelper shortStringHelper, + ITemplateRepository templateRepository, + IAuditRepository auditRepository, + ITemplateContentParserService templateContentParserService) + : this( + provider, + loggerFactory, + eventMessagesFactory, + shortStringHelper, + templateRepository, + auditRepository, + templateContentParserService, + StaticServiceProvider.Instance.GetRequiredService()) + { } /// public async Task> CreateForContentTypeAsync( - string contentTypeAlias, string? contentTypeName, int userId = Constants.Security.SuperUserId) + string contentTypeAlias, string? contentTypeName, Guid userKey) { ITemplate template = new Template(_shortStringHelper, contentTypeName, @@ -74,7 +100,8 @@ public class TemplateService : RepositoryService, ITemplateService scope.Notifications.Publish( new TemplateSavedNotification(template, eventMessages).WithStateFrom(savingEvent)); - Audit(AuditType.New, userId, template.Id, UmbracoObjectTypes.Template.GetName()); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.New, currentUserId, template.Id, UmbracoObjectTypes.Template.GetName()); scope.Complete(); } @@ -86,17 +113,17 @@ public class TemplateService : RepositoryService, ITemplateService string name, string alias, string? content, - int userId = Constants.Security.SuperUserId) - => await CreateAsync(new Template(_shortStringHelper, name, alias) { Content = content }, userId); + Guid userKey) + => await CreateAsync(new Template(_shortStringHelper, name, alias) { Content = content }, userKey); /// - public async Task> CreateAsync(ITemplate template, int userId = Constants.Security.SuperUserId) + public async Task> CreateAsync(ITemplate template, Guid userKey) { try { // file might already be on disk, if so grab the content to avoid overwriting template.Content = GetViewContent(template.Alias) ?? template.Content; - return await SaveAsync(template, AuditType.New, userId); + return await SaveAsync(template, AuditType.New, userKey); } catch (PathTooLongException ex) { @@ -161,17 +188,17 @@ public class TemplateService : RepositoryService, ITemplateService } /// - public async Task> UpdateAsync(ITemplate template, int userId = Constants.Security.SuperUserId) + public async Task> UpdateAsync(ITemplate template, Guid userKey) => await SaveAsync( template, AuditType.Save, - userId, + userKey, // fail the attempt if the template does not exist within the scope () => _templateRepository.Exists(template.Id) ? TemplateOperationStatus.Success : TemplateOperationStatus.TemplateNotFound); - private async Task> SaveAsync(ITemplate template, AuditType auditType, int userId = Constants.Security.SuperUserId, Func? scopeValidator = null) + private async Task> SaveAsync(ITemplate template, AuditType auditType, Guid userKey, Func? scopeValidator = null) { if (IsValidAlias(template.Alias) == false) { @@ -197,7 +224,7 @@ public class TemplateService : RepositoryService, ITemplateService return Attempt.FailWithStatus(TemplateOperationStatus.MasterTemplateNotFound, template); } - await SetMasterTemplateAsync(template, masterTemplate); + await SetMasterTemplateAsync(template, masterTemplate, userKey); EventMessages eventMessages = EventMessagesFactory.Get(); var savingNotification = new TemplateSavingNotification(template, eventMessages); @@ -212,19 +239,20 @@ public class TemplateService : RepositoryService, ITemplateService scope.Notifications.Publish( new TemplateSavedNotification(template, eventMessages).WithStateFrom(savingNotification)); - Audit(auditType, userId, template.Id, UmbracoObjectTypes.Template.GetName()); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(auditType, currentUserId, template.Id, UmbracoObjectTypes.Template.GetName()); scope.Complete(); return Attempt.SucceedWithStatus(TemplateOperationStatus.Success, template); } } /// - public async Task> DeleteAsync(string alias, int userId = Constants.Security.SuperUserId) - => await DeleteAsync(() => Task.FromResult(_templateRepository.Get(alias)), userId); + public async Task> DeleteAsync(string alias, Guid userKey) + => await DeleteAsync(() => Task.FromResult(_templateRepository.Get(alias)), userKey); /// - public async Task> DeleteAsync(Guid key, int userId = Constants.Security.SuperUserId) - => await DeleteAsync(async () => await GetAsync(key), userId); + public async Task> DeleteAsync(Guid key, Guid userKey) + => await DeleteAsync(async () => await GetAsync(key), userKey); /// public async Task GetFileContentStreamAsync(string filepath) @@ -256,7 +284,7 @@ public class TemplateService : RepositoryService, ITemplateService } /// - private async Task SetMasterTemplateAsync(ITemplate template, ITemplate? masterTemplate) + private async Task SetMasterTemplateAsync(ITemplate template, ITemplate? masterTemplate, Guid userKey) { if (template.MasterTemplateAlias == masterTemplate?.Alias) { @@ -299,7 +327,7 @@ public class TemplateService : RepositoryService, ITemplateService childTemplate.Path = masterTemplate.Path + "," + template.Id + "," + childTemplatePath; //Save the children with the updated path - await UpdateAsync(childTemplate); + await UpdateAsync(childTemplate, userKey); } } } @@ -334,7 +362,7 @@ public class TemplateService : RepositoryService, ITemplateService private void Audit(AuditType type, int userId, int objectId, string? entityType) => _auditRepository.Save(new AuditItem(objectId, type, userId, entityType)); - private async Task> DeleteAsync(Func> getTemplate, int userId) + private async Task> DeleteAsync(Func> getTemplate, Guid userKey) { using (ICoreScope scope = ScopeProvider.CreateCoreScope()) { @@ -358,7 +386,8 @@ public class TemplateService : RepositoryService, ITemplateService scope.Notifications.Publish( new TemplateDeletedNotification(template, eventMessages).WithStateFrom(deletingNotification)); - Audit(AuditType.Delete, userId, template.Id, UmbracoObjectTypes.Template.GetName()); + var currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + Audit(AuditType.Delete, currentUserId, template.Id, UmbracoObjectTypes.Template.GetName()); scope.Complete(); return Attempt.SucceedWithStatus(TemplateOperationStatus.Success, template); } diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index dc3acad3c5..156355591f 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -27,7 +27,6 @@ internal class UserService : RepositoryService, IUserService private readonly ILogger _logger; private readonly IRuntimeState _runtimeState; private readonly IUserGroupRepository _userGroupRepository; - private readonly IUserGroupAuthorizationService _userGroupAuthorizationService; private readonly IUserRepository _userRepository; public UserService( @@ -37,14 +36,12 @@ internal class UserService : RepositoryService, IUserService IRuntimeState runtimeState, IUserRepository userRepository, IUserGroupRepository userGroupRepository, - IOptions globalSettings, - IUserGroupAuthorizationService userGroupAuthorizationService) + IOptions globalSettings) : base(provider, loggerFactory, eventMessagesFactory) { _runtimeState = runtimeState; _userRepository = userRepository; _userGroupRepository = userGroupRepository; - _userGroupAuthorizationService = userGroupAuthorizationService; _globalSettings = globalSettings.Value; _logger = loggerFactory.CreateLogger(); } diff --git a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs index cc40b5ae73..7d8ec82800 100644 --- a/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs +++ b/src/Umbraco.Infrastructure/Services/Implement/PackagingService.cs @@ -30,6 +30,7 @@ public class PackagingService : IPackagingService private readonly IPackageInstallation _packageInstallation; private readonly PackageMigrationPlanCollection _packageMigrationPlans; private readonly IHostEnvironment _hostEnvironment; + private readonly IUserService _userService; public PackagingService( IAuditService auditService, @@ -39,7 +40,8 @@ public class PackagingService : IPackagingService ILegacyManifestParser legacyManifestParser, IKeyValueService keyValueService, PackageMigrationPlanCollection packageMigrationPlans, - IHostEnvironment hostEnvironment) + IHostEnvironment hostEnvironment, + IUserService userService) { _auditService = auditService; _createdPackages = createdPackages; @@ -49,9 +51,10 @@ public class PackagingService : IPackagingService _keyValueService = keyValueService; _packageMigrationPlans = packageMigrationPlans; _hostEnvironment = hostEnvironment; + _userService = userService; } - [Obsolete("Use constructor that also takes an IHostEnvironment instead. Scheduled for removal in V15")] + [Obsolete("Use constructor that also takes an IHostEnvironment and IUserService instead. Scheduled for removal in V15")] public PackagingService( IAuditService auditService, ICreatedPackagesRepository createdPackages, @@ -68,7 +71,8 @@ public class PackagingService : IPackagingService manifestParser, keyValueService, packageMigrationPlans, - StaticServiceProvider.Instance.GetRequiredService()) + StaticServiceProvider.Instance.GetRequiredService(), + StaticServiceProvider.Instance.GetRequiredService()) { } @@ -126,12 +130,13 @@ public class PackagingService : IPackagingService { PackageDefinition? package = GetCreatedPackageById(id); Guid key = package?.PackageId ?? Guid.Empty; + Guid currentUserKey = _userService.GetUserById(id)?.Key ?? Constants.Security.SuperUserKey; - DeleteCreatedPackageAsync(key, userId).GetAwaiter().GetResult(); + DeleteCreatedPackageAsync(key, currentUserKey).GetAwaiter().GetResult(); } /// - public async Task> DeleteCreatedPackageAsync(Guid key, int userId = Constants.Security.SuperUserId) + public async Task> DeleteCreatedPackageAsync(Guid key, Guid userKey) { PackageDefinition? package = await GetCreatedPackageByKeyAsync(key); if (package == null) @@ -139,7 +144,8 @@ public class PackagingService : IPackagingService return Attempt.FailWithStatus(PackageOperationStatus.NotFound, null); } - _auditService.Add(AuditType.Delete, userId, -1, "Package", $"Created package '{package.Name}' deleted. Package key: {key}"); + int currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + _auditService.Add(AuditType.Delete, currentUserId, -1, "Package", $"Created package '{package.Name}' deleted. Package key: {key}"); _createdPackages.Delete(package.Id); return Attempt.SucceedWithStatus(PackageOperationStatus.Success, package); @@ -156,7 +162,7 @@ public class PackagingService : IPackagingService public bool SaveCreatedPackage(PackageDefinition definition) => _createdPackages.SavePackage(definition); /// - public async Task> CreateCreatedPackageAsync(PackageDefinition package, int userId) + public async Task> CreateCreatedPackageAsync(PackageDefinition package, Guid userKey) { if (_createdPackages.SavePackage(package) == false) { @@ -168,20 +174,22 @@ public class PackagingService : IPackagingService return Attempt.FailWithStatus(PackageOperationStatus.DuplicateItemName, package); } - _auditService.Add(AuditType.New, userId, -1, "Package", $"Created package '{package.Name}' created. Package key: {package.PackageId}"); + int currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + _auditService.Add(AuditType.New, currentUserId, -1, "Package", $"Created package '{package.Name}' created. Package key: {package.PackageId}"); return await Task.FromResult(Attempt.SucceedWithStatus(PackageOperationStatus.Success, package)); } /// - public async Task> UpdateCreatedPackageAsync(PackageDefinition package, int userId) + public async Task> UpdateCreatedPackageAsync(PackageDefinition package, Guid userKey) { if (_createdPackages.SavePackage(package) == false) { return Attempt.FailWithStatus(PackageOperationStatus.NotFound, package); } - _auditService.Add(AuditType.New, userId, -1, "Package", $"Created package '{package.Name}' updated. Package key: {package.PackageId}"); + int currentUserId = _userService.GetAsync(userKey).Result?.Id ?? Constants.Security.SuperUserId; + _auditService.Add(AuditType.New, currentUserId, -1, "Package", $"Created package '{package.Name}' updated. Package key: {package.PackageId}"); return await Task.FromResult(Attempt.SucceedWithStatus(PackageOperationStatus.Success, package)); } diff --git a/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml b/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml index 0acaf5cb53..2811562e53 100644 --- a/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml +++ b/src/Umbraco.Web.BackOffice/CompatibilitySuppressions.xml @@ -1,5 +1,4 @@  - CP0002 @@ -15,6 +14,13 @@ lib/net7.0/Umbraco.Web.BackOffice.dll true + + CP0002 + M:Umbraco.Cms.Web.BackOffice.Controllers.TemplateController.#ctor(Umbraco.Cms.Core.Services.IFileService,Umbraco.Cms.Core.Mapping.IUmbracoMapper,Umbraco.Cms.Core.Strings.IShortStringHelper,Umbraco.Cms.Core.IO.IDefaultViewContentProvider) + lib/net7.0/Umbraco.Web.BackOffice.dll + lib/net7.0/Umbraco.Web.BackOffice.dll + true + CP0002 M:Umbraco.Extensions.RuntimeMinifierExtensions.GetScriptForLoadingBackOfficeAsync(Umbraco.Cms.Core.WebAssets.IRuntimeMinifier,Umbraco.Cms.Core.Configuration.Models.GlobalSettings,Umbraco.Cms.Core.Hosting.IHostingEnvironment,Umbraco.Cms.Core.Manifest.IManifestParser) diff --git a/src/Umbraco.Web.BackOffice/Controllers/TemplateController.cs b/src/Umbraco.Web.BackOffice/Controllers/TemplateController.cs index f44dfc628c..1c00e535bf 100644 --- a/src/Umbraco.Web.BackOffice/Controllers/TemplateController.cs +++ b/src/Umbraco.Web.BackOffice/Controllers/TemplateController.cs @@ -26,20 +26,6 @@ public class TemplateController : BackOfficeNotificationsController private readonly IShortStringHelper _shortStringHelper; private readonly IUmbracoMapper _umbracoMapper; - public TemplateController( - IFileService fileService, - IUmbracoMapper umbracoMapper, - IShortStringHelper shortStringHelper, - IDefaultViewContentProvider defaultViewContentProvider) - : this( - StaticServiceProvider.Instance.GetRequiredService(), - umbracoMapper, - shortStringHelper, - defaultViewContentProvider, - fileService) - { - } - [ActivatorUtilitiesConstructor] public TemplateController( ITemplateService templateService, @@ -143,7 +129,7 @@ public class TemplateController : BackOfficeNotificationsController return NotFound(); } - _templateService.DeleteAsync(template.Alias).GetAwaiter().GetResult(); + _templateService.DeleteAsync(template.Alias, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); return Ok(); } @@ -201,7 +187,7 @@ public class TemplateController : BackOfficeNotificationsController _umbracoMapper.Map(display, template); - _templateService.UpdateAsync(template).GetAwaiter().GetResult(); + _templateService.UpdateAsync(template, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); if (changeAlias) { @@ -226,7 +212,7 @@ public class TemplateController : BackOfficeNotificationsController // we need to pass the template name as alias to keep the template file casing consistent with templates created with content // - see comment in FileService.CreateTemplateForContentType for additional details Attempt result = - _templateService.CreateAsync(display.Name!, display.Name!, display.Content).GetAwaiter().GetResult(); + _templateService.CreateAsync(display.Name!, display.Name!, display.Content, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); if (result.Success == false) { return NotFound(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Packaging/CreatedPackagesRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Packaging/CreatedPackagesRepositoryTests.cs index d94fa07d20..b594495dd0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Packaging/CreatedPackagesRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Packaging/CreatedPackagesRepositoryTests.cs @@ -170,11 +170,11 @@ public class CreatedPackagesRepositoryTests : UmbracoIntegrationTest [Test] public async Task GivenNestedDictionaryItems_WhenPackageExported_ThenTheXmlIsNested() { - var parent = (await DictionaryItemService.CreateAsync(new DictionaryItem("Parent"))).Result; - var child1 = (await DictionaryItemService.CreateAsync(new DictionaryItem(parent.Key, "Child1"))).Result; - var child2 = (await DictionaryItemService.CreateAsync(new DictionaryItem(child1.Key, "Child2"))).Result; - var child3 = (await DictionaryItemService.CreateAsync(new DictionaryItem(child2.Key, "Child3"))).Result; - var child4 = (await DictionaryItemService.CreateAsync(new DictionaryItem(child3.Key, "Child4"))).Result; + var parent = (await DictionaryItemService.CreateAsync(new DictionaryItem("Parent"), Constants.Security.SuperUserKey)).Result; + var child1 = (await DictionaryItemService.CreateAsync(new DictionaryItem(parent.Key, "Child1"), Constants.Security.SuperUserKey)).Result; + var child2 = (await DictionaryItemService.CreateAsync(new DictionaryItem(child1.Key, "Child2"), Constants.Security.SuperUserKey)).Result; + var child3 = (await DictionaryItemService.CreateAsync(new DictionaryItem(child2.Key, "Child3"), Constants.Security.SuperUserKey)).Result; + var child4 = (await DictionaryItemService.CreateAsync(new DictionaryItem(child3.Key, "Child4"), Constants.Security.SuperUserKey)).Result; var def = new PackageDefinition { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/RelationServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/RelationServiceTests.cs index e5f37d8cb9..607478ea0a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/RelationServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/RelationServiceTests.cs @@ -31,7 +31,7 @@ public class RelationServiceTests : UmbracoIntegrationTest .WithIsDependency(isDependency) .Build(); - Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserId); + Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserKey); Assert.Multiple(() => { @@ -56,7 +56,7 @@ public class RelationServiceTests : UmbracoIntegrationTest .WithParentObjectType(new Guid(parentObjectTypeGuid)) .Build(); - Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserId); + Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserKey); Assert.Multiple(() => { @@ -78,7 +78,7 @@ public class RelationServiceTests : UmbracoIntegrationTest .WithParentObjectType(new Guid(parentObjectTypeGuid)) .Build(); - Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserId); + Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserKey); Assert.Multiple(() => { @@ -97,7 +97,7 @@ public class RelationServiceTests : UmbracoIntegrationTest .WithKey(new Guid(key)) .Build(); - Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserId); + Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserKey); Assert.Multiple(() => { @@ -122,7 +122,7 @@ public class RelationServiceTests : UmbracoIntegrationTest .WithId(id) .Build(); - Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserId); + Attempt result = await RelationService.CreateAsync(relationType, Constants.Security.SuperUserKey); Assert.Multiple(() => { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs index 8afcbcbdf9..2f3e47e08b 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/TelemetryProviderTests.cs @@ -145,9 +145,9 @@ public class TelemetryProviderTests : UmbracoIntegrationTest var langTwo = _languageBuilder.WithCultureInfo("da-DK").Build(); var langThree = _languageBuilder.WithCultureInfo("sv-SE").Build(); - var langTwoResult = await LanguageService.CreateAsync(langTwo); + var langTwoResult = await LanguageService.CreateAsync(langTwo, Constants.Security.SuperUserKey); Assert.IsTrue(langTwoResult.Success); - var langThreeResult = await LanguageService.CreateAsync(langThree); + var langThreeResult = await LanguageService.CreateAsync(langThree, Constants.Security.SuperUserKey); Assert.IsTrue(langThreeResult.Success); IEnumerable result = null; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Variants/ContentVariantAllowedActionTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Variants/ContentVariantAllowedActionTests.cs index 2a0b9c3168..1dcb595549 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Variants/ContentVariantAllowedActionTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Variants/ContentVariantAllowedActionTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Actions; using Umbraco.Cms.Core.Mapping; using Umbraco.Cms.Core.Models; @@ -27,7 +28,7 @@ public class ContentVariantAllowedActionTests : UmbracoTestServerTestBase public async Task SetUpTestDate() { var dk = new Language(DkIso, "Danish"); - await LanguageService.CreateAsync(dk); + await LanguageService.CreateAsync(dk, Constants.Security.SuperUserKey); } [Test] diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs index 9172b53dac..f93441ece7 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Packaging/PackageDataInstallationTests.cs @@ -856,8 +856,8 @@ public class PackageDataInstallationTests : UmbracoIntegrationTestWithContent { var norwegian = new Language("nb-NO", "Norwegian Bokmål (Norway)"); var english = new Language("en-GB", "English (United Kingdom)"); - await LanguageService.CreateAsync(norwegian, 0); - await LanguageService.CreateAsync(english, 0); + await LanguageService.CreateAsync(norwegian, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(english, Constants.Security.SuperUserKey); } private async Task AssertDictionaryItem(string dictionaryItemName, string expectedValue, string cultureCode) @@ -885,7 +885,8 @@ public class PackageDataInstallationTests : UmbracoIntegrationTestWithContent { new DictionaryTranslation(englishLanguage, expectedEnglishParentValue) } - }); + }, + Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(key, result.Result.Key); } @@ -907,7 +908,8 @@ public class PackageDataInstallationTests : UmbracoIntegrationTestWithContent new DictionaryTranslation(englishLanguage, expectedEnglishParentValue), new DictionaryTranslation(norwegianLanguage, expectedNorwegianParentValue) } - }); + }, + Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(key, result.Result.Key); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs index b4ced5d768..37ab178bd6 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/DictionaryRepositoryTest.cs @@ -2,6 +2,7 @@ // See LICENSE for more details. using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Persistence.Repositories; using Umbraco.Cms.Core.Services; @@ -317,7 +318,7 @@ public class DictionaryRepositoryTest : UmbracoIntegrationTest var repository = CreateRepository(); var languageNo = new Language("nb-NO", "Norwegian Bokmål (Norway)"); - await languageService.CreateAsync(languageNo); + await languageService.CreateAsync(languageNo, Constants.Security.SuperUserKey); // Act var item = repository.Get(1); @@ -400,7 +401,7 @@ public class DictionaryRepositoryTest : UmbracoIntegrationTest var language = await languageService.GetAsync("en-US"); var languageDK = new Language("da-DK", "Danish (Denmark)"); - await languageService.CreateAsync(languageDK); //Id 2 + await languageService.CreateAsync(languageDK, Constants.Security.SuperUserKey); //Id 2 await dictionaryItemService.CreateAsync( new DictionaryItem("Read More") @@ -409,7 +410,8 @@ public class DictionaryRepositoryTest : UmbracoIntegrationTest { new DictionaryTranslation(language, "Read More"), new DictionaryTranslation(languageDK, "Læs mere") } - }); // Id 1 + }, + Constants.Security.SuperUserKey); // Id 1 await dictionaryItemService.CreateAsync( new DictionaryItem("Article") @@ -418,6 +420,7 @@ public class DictionaryRepositoryTest : UmbracoIntegrationTest { new DictionaryTranslation(language, "Article"), new DictionaryTranslation(languageDK, "Artikel") } - }); // Id 2 + }, + Constants.Security.SuperUserKey); // Id 2 } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs index 3823103f7e..17d80bc5cb 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/LanguageRepositoryTest.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.Linq; using Microsoft.Extensions.Logging; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; @@ -374,15 +375,15 @@ public class LanguageRepositoryTest : UmbracoIntegrationTest //Id 1 is en-US - when Umbraco is installed var languageDK = new Language("da-DK", "Danish (Denmark)"); - await languageService.CreateAsync(languageDK); //Id 2 + await languageService.CreateAsync(languageDK, Constants.Security.SuperUserKey); //Id 2 var languageSE = new Language("sv-SE", "Swedish (Sweden)"); - await languageService.CreateAsync(languageSE); //Id 3 + await languageService.CreateAsync(languageSE, Constants.Security.SuperUserKey); //Id 3 var languageDE = new Language("de-DE", "German (Germany)"); - await languageService.CreateAsync(languageDE); //Id 4 + await languageService.CreateAsync(languageDE, Constants.Security.SuperUserKey); //Id 4 var languagePT = new Language("pt-PT", "Portuguese (Portugal)"); - await languageService.CreateAsync(languagePT); //Id 5 + await languageService.CreateAsync(languagePT, Constants.Security.SuperUserKey); //Id 5 } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs index 80fa416da0..6293576096 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Scoping/ScopedRepositoryTests.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Linq; using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Models; @@ -147,7 +148,7 @@ public class ScopedRepositoryTests : UmbracoIntegrationTest var globalCache = AppCaches.IsolatedCaches.GetOrCreate(typeof(ILanguage)); ILanguage lang = new Language("fr-FR", "French (France)"); - await service.CreateAsync(lang); + await service.CreateAsync(lang, Constants.Security.SuperUserKey); // global cache has been flushed, reload var globalFullCached = (IEnumerable)globalCache.Get(GetCacheTypeKey(), () => null); @@ -175,7 +176,7 @@ public class ScopedRepositoryTests : UmbracoIntegrationTest // Use IsMandatory of isocode to ensure publishedContent cache is not also rebuild lang.IsMandatory = true; - await service.UpdateAsync(lang); + await service.UpdateAsync(lang, Constants.Security.SuperUserKey); // scoped cache has been flushed, reload var scopeFullCached = (IEnumerable)scopedCache.Get(GetCacheTypeKey(), () => null); @@ -241,13 +242,14 @@ public class ScopedRepositoryTests : UmbracoIntegrationTest var globalCache = AppCaches.IsolatedCaches.GetOrCreate(typeof(IDictionaryItem)); var lang = new Language("fr-FR", "French (France)"); - await languageService.CreateAsync(lang); + await languageService.CreateAsync(lang, Constants.Security.SuperUserKey); var item = (await dictionaryItemService.CreateAsync( new DictionaryItem("item-key") { Translations = new IDictionaryTranslation[] { new DictionaryTranslation(lang, "item-value") } - })).Result; + }, + Constants.Security.SuperUserKey)).Result; // Refresh the keyed cache manually await dictionaryItemService.GetAsync(item.Key); @@ -272,7 +274,7 @@ public class ScopedRepositoryTests : UmbracoIntegrationTest Assert.AreNotSame(globalCache, scopedCache); item.ItemKey = "item-changed"; - await dictionaryItemService.UpdateAsync(item); + await dictionaryItemService.UpdateAsync(item, Constants.Security.SuperUserKey); // scoped cache contains the "new" entity // Refresh the keyed cache manually diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Create.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Create.cs index 8711a6dfde..50d84a0de1 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Create.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Create.cs @@ -14,7 +14,7 @@ public partial class ContentEditingServiceTests public async Task Create_At_Root(bool allowedAtRoot) { var template = TemplateBuilder.CreateTextPageTemplate(); - await TemplateService.CreateAsync(template); + await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey); var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); contentType.AllowedAsRoot = allowedAtRoot; @@ -33,7 +33,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); if (allowedAtRoot) { @@ -67,7 +67,7 @@ public partial class ContentEditingServiceTests public async Task Create_As_Child(bool allowedAsChild) { var template = TemplateBuilder.CreateTextPageTemplate(); - await TemplateService.CreateAsync(template); + await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey); var childContentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); childContentType.AllowedAsRoot = false; @@ -84,10 +84,12 @@ public partial class ContentEditingServiceTests } ContentTypeService.Save(rootContentType); - var rootKey = (await ContentEditingService.CreateAsync(new ContentCreateModel + var rootKey = (await ContentEditingService.CreateAsync( + new ContentCreateModel { ContentTypeKey = rootContentType.Key, InvariantName = "Root", ParentKey = Constants.System.RootKey, - })).Result.Key; + }, + Constants.Security.SuperUserKey)).Result.Key; var createModel = new ContentCreateModel { @@ -102,7 +104,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); if (allowedAsChild) { @@ -144,7 +146,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); Assert.IsNotNull(result.Result); @@ -156,7 +158,7 @@ public partial class ContentEditingServiceTests public async Task Can_Create_Without_Properties() { var template = TemplateBuilder.CreateTextPageTemplate(); - await TemplateService.CreateAsync(template); + await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey); var contentType = ContentTypeBuilder.CreateTextPageContentType(defaultTemplateId: template.Id); contentType.AllowedAsRoot = true; @@ -169,7 +171,7 @@ public partial class ContentEditingServiceTests InvariantName = "Test Create" }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); Assert.IsNotNull(result.Result); @@ -192,7 +194,7 @@ public partial class ContentEditingServiceTests InvariantName = "Test Create" }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.ParentNotFound, result.Status); Assert.IsNull(result.Result); @@ -205,10 +207,10 @@ public partial class ContentEditingServiceTests { ContentTypeKey = Guid.NewGuid(), ParentKey = Constants.System.RootKey, - InvariantName = "Test Create" + InvariantName = "Test Create", }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.ContentTypeNotFound, result.Status); Assert.IsNull(result.Result); @@ -218,7 +220,7 @@ public partial class ContentEditingServiceTests public async Task Cannot_Create_With_Invalid_Template() { var template = TemplateBuilder.CreateTextPageTemplate(); - await TemplateService.CreateAsync(template); + await TemplateService.CreateAsync(template, Constants.Security.SuperUserKey); var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.AllowedAsRoot = true; @@ -232,7 +234,7 @@ public partial class ContentEditingServiceTests InvariantName = "Test Create" }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.TemplateNotAllowed, result.Status); Assert.IsNotNull(result.Result); @@ -254,7 +256,7 @@ public partial class ContentEditingServiceTests InvariantName = "Test Create" }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.TemplateNotFound, result.Status); Assert.IsNotNull(result.Result); @@ -281,7 +283,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.PropertyTypeNotFound, result.Status); Assert.IsNull(result.Result); @@ -306,7 +308,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.ContentTypeCultureVarianceMismatch, result.Status); Assert.IsNull(result.Result); @@ -343,7 +345,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.ContentTypeCultureVarianceMismatch, result.Status); Assert.IsNull(result.Result); @@ -385,7 +387,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); VerifyCreate(result.Result); @@ -420,7 +422,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.PropertyTypeNotFound, result.Status); Assert.IsNull(result.Result); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Delete.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Delete.cs index 4cd39d42d0..26c13922ff 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Delete.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Delete.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Services.OperationStatus; namespace Umbraco.Cms.Tests.Integration.Umbraco.Infrastructure.Services; @@ -11,7 +12,7 @@ public partial class ContentEditingServiceTests { var content = await (variant ? CreateVariantContent() : CreateInvariantContent()); - var result = await ContentEditingService.DeleteAsync(content.Key); + var result = await ContentEditingService.DeleteAsync(content.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); @@ -23,7 +24,7 @@ public partial class ContentEditingServiceTests [Test] public async Task Cannot_Delete_Non_Existing() { - var result = await ContentEditingService.DeleteAsync(Guid.NewGuid()); + var result = await ContentEditingService.DeleteAsync(Guid.NewGuid(), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.NotFound, result.Status); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs index f769868a22..4b84aee555 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.Update.cs @@ -25,7 +25,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); VerifyUpdate(result.Result); @@ -76,7 +76,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); VerifyUpdate(result.Result); @@ -100,8 +100,8 @@ public partial class ContentEditingServiceTests { var templateOne = new TemplateBuilder().WithAlias("textPageOne").WithName("Text page one").Build(); var templateTwo = new TemplateBuilder().WithAlias("textPageTwo").WithName("Text page two").Build(); - await TemplateService.CreateAsync(templateOne); - await TemplateService.CreateAsync(templateTwo); + await TemplateService.CreateAsync(templateOne, Constants.Security.SuperUserKey); + await TemplateService.CreateAsync(templateTwo, Constants.Security.SuperUserKey); var content = await CreateInvariantContent(templateOne, templateTwo); Assert.AreEqual(templateOne.Id, content.TemplateId); @@ -112,7 +112,7 @@ public partial class ContentEditingServiceTests TemplateKey = templateTwo.Key }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); VerifyUpdate(result.Result); // re-get and re-test @@ -130,7 +130,7 @@ public partial class ContentEditingServiceTests public async Task Can_Remove_Template() { var templateOne = new TemplateBuilder().WithAlias("textPageOne").WithName("Text page one").Build(); - await TemplateService.CreateAsync(templateOne); + await TemplateService.CreateAsync(templateOne, Constants.Security.SuperUserKey); var content = await CreateInvariantContent(templateOne); Assert.AreEqual(templateOne.Id, content.TemplateId); @@ -141,7 +141,7 @@ public partial class ContentEditingServiceTests TemplateKey = null }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); VerifyUpdate(result.Result); // re-get and re-test @@ -169,7 +169,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(ContentEditingOperationStatus.Success, result.Status); VerifyUpdate(result.Result); @@ -212,7 +212,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.ContentTypeCultureVarianceMismatch, result.Status); @@ -239,7 +239,7 @@ public partial class ContentEditingServiceTests } }; - var result = await ContentEditingService.UpdateAsync(content, updateModel); + var result = await ContentEditingService.UpdateAsync(content, updateModel, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(ContentEditingOperationStatus.PropertyTypeNotFound, result.Status); Assert.IsNotNull(result.Result); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.cs index 6a792de915..6cbba9f3d0 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentEditingServiceTests.cs @@ -72,7 +72,7 @@ public partial class ContentEditingServiceTests : UmbracoIntegrationTestWithCont var language = new LanguageBuilder() .WithCultureInfo("da-DK") .Build(); - await LanguageService.CreateAsync(language); + await LanguageService.CreateAsync(language, Constants.Security.SuperUserKey); var contentType = new ContentTypeBuilder() .WithAlias("cultureVariationTest") @@ -111,7 +111,7 @@ public partial class ContentEditingServiceTests : UmbracoIntegrationTestWithCont } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); return result.Result!; } @@ -151,7 +151,7 @@ public partial class ContentEditingServiceTests : UmbracoIntegrationTestWithCont } }; - var result = await ContentEditingService.CreateAsync(createModel); + var result = await ContentEditingService.CreateAsync(createModel, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); return result.Result!; } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceNotificationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceNotificationTests.cs index 1e8e09c071..d39e7a4a08 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceNotificationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceNotificationTests.cs @@ -2,6 +2,7 @@ // See LICENSE for more details. using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; @@ -65,7 +66,7 @@ public class ContentServiceNotificationTests : UmbracoIntegrationTest [Test] public async Task Saving_Culture() { - await LanguageService.CreateAsync(new Language("fr-FR", "French (France)")); + await LanguageService.CreateAsync(new Language("fr-FR", "French (France)"), Constants.Security.SuperUserKey); _contentType.Variations = ContentVariation.Culture; foreach (var propertyType in _contentType.PropertyTypes) @@ -176,7 +177,7 @@ public class ContentServiceNotificationTests : UmbracoIntegrationTest [Test] public async Task Publishing_Culture() { - await LanguageService.CreateAsync(new Language("fr-FR", "French (France)")); + await LanguageService.CreateAsync(new Language("fr-FR", "French (France)"), Constants.Security.SuperUserKey); _contentType.Variations = ContentVariation.Culture; foreach (var propertyType in _contentType.PropertyTypes) @@ -336,7 +337,7 @@ public class ContentServiceNotificationTests : UmbracoIntegrationTest [Test] public async Task Unpublishing_Culture() { - await LanguageService.CreateAsync(new Language("fr-FR", "French (France)")); + await LanguageService.CreateAsync(new Language("fr-FR", "French (France)"), Constants.Security.SuperUserKey); _contentType.Variations = ContentVariation.Culture; foreach (var propertyType in _contentType.PropertyTypes) diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePublishBranchTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePublishBranchTests.cs index 089666248f..529a31559b 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePublishBranchTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServicePublishBranchTests.cs @@ -443,11 +443,11 @@ public class ContentServicePublishBranchTests : UmbracoIntegrationTest private void CreateTypes(out IContentType iContentType, out IContentType vContentType) { var langDe = new Language("de", "German") { IsDefault = true }; - LanguageService.CreateAsync(langDe).GetAwaiter().GetResult(); + LanguageService.CreateAsync(langDe, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); var langRu = new Language("ru", "Russian"); - LanguageService.CreateAsync(langRu).GetAwaiter().GetResult(); + LanguageService.CreateAsync(langRu, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); var langEs = new Language("es", "Spanish"); - LanguageService.CreateAsync(langEs).GetAwaiter().GetResult(); + LanguageService.CreateAsync(langEs, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); iContentType = new ContentType(ShortStringHelper, -1) { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs index 0fe55ab779..f02218bb54 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTagsTests.cs @@ -4,6 +4,7 @@ using System; using System.Linq; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.PropertyEditors; using Umbraco.Cms.Core.Serialization; @@ -94,7 +95,7 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest var language = new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(language); // en-US is already there + await LanguageService.CreateAsync(language, Constants.Security.SuperUserKey); // en-US is already there var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); @@ -228,7 +229,7 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest var language = new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(language); // en-US is already there + await LanguageService.CreateAsync(language, Constants.Security.SuperUserKey); // en-US is already there var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); @@ -287,7 +288,7 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest var language = new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(language); // en-US is already there + await LanguageService.CreateAsync(language, Constants.Security.SuperUserKey); // en-US is already there var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); @@ -332,7 +333,7 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest var language = new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(language); // en-US is already there + await LanguageService.CreateAsync(language, Constants.Security.SuperUserKey); // en-US is already there var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); @@ -394,7 +395,7 @@ public class ContentServiceTagsTests : UmbracoIntegrationTest var language = new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(language); // en-US is already there + await LanguageService.CreateAsync(language, Constants.Security.SuperUserKey); // en-US is already there var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs index deeb078221..0519e81c7d 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentServiceTests.cs @@ -202,8 +202,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(langFr); - await LanguageService.CreateAsync(langUk); + await LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(langUk, Constants.Security.SuperUserKey); var ctInvariant = ContentTypeBuilder.CreateBasicContentType("invariantPage"); ContentTypeService.Save(ctInvariant); @@ -850,8 +850,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(langFr); - await LanguageService.CreateAsync(langUk); + await LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(langUk, Constants.Security.SuperUserKey); var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = ContentVariation.Culture; @@ -954,8 +954,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(langFr); - await LanguageService.CreateAsync(langGb); + await LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(langGb, Constants.Security.SuperUserKey); var contentType = ContentTypeBuilder.CreateMetaContentType(); contentType.Variations = ContentVariation.Culture; @@ -1032,8 +1032,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("fr-FR") .Build(); - await LanguageService.CreateAsync(langFr); - await LanguageService.CreateAsync(langGb); + await LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(langGb, Constants.Security.SuperUserKey); var contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = ContentVariation.Culture; @@ -1222,8 +1222,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent var langDa = new LanguageBuilder() .WithCultureInfo("da") .Build(); - await LanguageService.CreateAsync(langFr); - await LanguageService.CreateAsync(langDa); + await LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(langDa, Constants.Security.SuperUserKey); var ct = ContentTypeBuilder.CreateBasicContentType(); ct.Variations = ContentVariation.Culture; @@ -2331,8 +2331,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent var langDa = new LanguageBuilder() .WithCultureInfo("da") .Build(); - await LanguageService.CreateAsync(langFr); - await LanguageService.CreateAsync(langDa); + await LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(langDa, Constants.Security.SuperUserKey); var template = TemplateBuilder.CreateTextPageTemplate(); FileService.SaveTemplate(template); @@ -2856,8 +2856,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("fr-FR") .Build(); - await languageService.CreateAsync(langFr); - await languageService.CreateAsync(langUk); + await languageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await languageService.CreateAsync(langUk, Constants.Security.SuperUserKey); var contentTypeService = ContentTypeService; @@ -2897,8 +2897,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("fr-FR") .Build(); - await languageService.CreateAsync(langFr); - await languageService.CreateAsync(langUk); + await languageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await languageService.CreateAsync(langUk, Constants.Security.SuperUserKey); var contentTypeService = ContentTypeService; @@ -2943,9 +2943,9 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("da-DK") .Build(); - await languageService.CreateAsync(langFr); - await languageService.CreateAsync(langUk); - await languageService.CreateAsync(langDa); + await languageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await languageService.CreateAsync(langUk, Constants.Security.SuperUserKey); + await languageService.CreateAsync(langDa, Constants.Security.SuperUserKey); var contentTypeService = ContentTypeService; @@ -3077,9 +3077,9 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent .WithCultureInfo("de-DE") .Build(); - await languageService.CreateAsync(langFr); - await languageService.CreateAsync(langUk); - await languageService.CreateAsync(langDe); + await languageService.CreateAsync(langFr, Constants.Security.SuperUserKey); + await languageService.CreateAsync(langUk, Constants.Security.SuperUserKey); + await languageService.CreateAsync(langDe, Constants.Security.SuperUserKey); var contentTypeService = ContentTypeService; @@ -3492,8 +3492,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent langFr = (Language)new LanguageBuilder() .WithCultureInfo("fr-FR") .Build(); - LanguageService.CreateAsync(langFr).GetAwaiter().GetResult(); - LanguageService.CreateAsync(langUk).GetAwaiter().GetResult(); + LanguageService.CreateAsync(langFr, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); + LanguageService.CreateAsync(langUk, Constants.Security.SuperUserKey).GetAwaiter().GetResult(); contentType = ContentTypeBuilder.CreateBasicContentType(); contentType.Variations = ContentVariation.Culture; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs index a7f1220ba9..9b4807c496 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/ContentTypeServiceVariantsTests.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.DependencyInjection; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; @@ -261,7 +262,7 @@ public class ContentTypeServiceVariantsTests : UmbracoIntegrationTest var nlContentName = "Content nl-NL"; var nlCulture = "nl-NL"; - await LanguageService.CreateAsync(new Language(nlCulture, "Dutch (Netherlands)")); + await LanguageService.CreateAsync(new Language(nlCulture, "Dutch (Netherlands)"), Constants.Security.SuperUserKey); var includeCultureNames = contentType.Variations.HasFlag(ContentVariation.Culture); @@ -629,9 +630,9 @@ public class ContentTypeServiceVariantsTests : UmbracoIntegrationTest var globalSettings = new GlobalSettings(); var languageEn = new Language("en", "English") { IsDefault = true }; - await LanguageService.CreateAsync(languageEn); + await LanguageService.CreateAsync(languageEn, Constants.Security.SuperUserKey); var languageFr = new Language("fr", "French"); - await LanguageService.CreateAsync(languageFr); + await LanguageService.CreateAsync(languageFr, Constants.Security.SuperUserKey); var contentType = CreateContentType(ContentVariation.Nothing); @@ -1275,9 +1276,9 @@ public class ContentTypeServiceVariantsTests : UmbracoIntegrationTest private async Task CreateFrenchAndEnglishLangs() { var languageEn = new Language("en", "English") { IsDefault = true }; - await LanguageService.CreateAsync(languageEn); + await LanguageService.CreateAsync(languageEn, Constants.Security.SuperUserKey); var languageFr = new Language("fr", "French"); - await LanguageService.CreateAsync(languageFr); + await LanguageService.CreateAsync(languageFr, Constants.Security.SuperUserKey); } private IContentType CreateContentType(ContentVariation variance, string alias = "contentType") => diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs index af20fb8f9c..473974843d 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeContainerServiceTests.cs @@ -33,7 +33,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest { EntityContainer toCreate = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - var result = await DataTypeContainerService.CreateAsync(toCreate); + var result = await DataTypeContainerService.CreateAsync(toCreate, null, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.Success, result.Status); @@ -47,10 +47,10 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Create_Child_Container() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - var result = await DataTypeContainerService.CreateAsync(child, root.Key); + var result = await DataTypeContainerService.CreateAsync(child, root.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.Success, result.Status); @@ -64,13 +64,13 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Update_Container_At_Root() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer toUpdate = await DataTypeContainerService.GetAsync(root.Key); Assert.NotNull(toUpdate); toUpdate.Name += " UPDATED"; - var result = await DataTypeContainerService.UpdateAsync(toUpdate); + var result = await DataTypeContainerService.UpdateAsync(toUpdate, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.Success, result.Status); @@ -84,16 +84,16 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Update_Child_Container() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - await DataTypeContainerService.CreateAsync(child, root.Key); + await DataTypeContainerService.CreateAsync(child, root.Key, Constants.Security.SuperUserKey); EntityContainer toUpdate = await DataTypeContainerService.GetAsync(child.Key); Assert.NotNull(toUpdate); toUpdate.Name += " UPDATED"; - var result = await DataTypeContainerService.UpdateAsync(toUpdate); + var result = await DataTypeContainerService.UpdateAsync(toUpdate, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.Success, result.Status); @@ -107,7 +107,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Get_Container_At_Root() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); var created = await DataTypeContainerService.GetAsync(root.Key); Assert.NotNull(created); @@ -119,10 +119,10 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Get_Child_Container() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - await DataTypeContainerService.CreateAsync(child, root.Key); + await DataTypeContainerService.CreateAsync(child, root.Key, Constants.Security.SuperUserKey); var created = await DataTypeContainerService.GetAsync(child.Key); Assert.IsNotNull(created); @@ -134,9 +134,9 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Delete_Container_At_Root() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); - var result = await DataTypeContainerService.DeleteAsync(root.Key); + var result = await DataTypeContainerService.DeleteAsync(root.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.Success, result.Status); @@ -148,12 +148,12 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Can_Delete_Child_Container() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - await DataTypeContainerService.CreateAsync(child, root.Key); + await DataTypeContainerService.CreateAsync(child, null, root.Key); - var result = await DataTypeContainerService.DeleteAsync(child.Key); + var result = await DataTypeContainerService.DeleteAsync(child.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.Success, result.Status); @@ -168,7 +168,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Cannot_Create_Child_Container_Below_Invalid_Parent() { EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - var result = await DataTypeContainerService.CreateAsync(child, Guid.NewGuid()); + var result = await DataTypeContainerService.CreateAsync(child, Guid.NewGuid(), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.ParentNotFound, result.Status); @@ -181,7 +181,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest { EntityContainer toCreate = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container", Id = 1234 }; - var result = await DataTypeContainerService.CreateAsync(toCreate); + var result = await DataTypeContainerService.CreateAsync(toCreate, null, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.InvalidId, result.Status); @@ -195,7 +195,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest { EntityContainer toCreate = new EntityContainer(new Guid(containedObjectType)) { Name = "Root Container" }; - var result = await DataTypeContainerService.CreateAsync(toCreate); + var result = await DataTypeContainerService.CreateAsync(toCreate, null, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.InvalidObjectType, result.Status); @@ -207,19 +207,19 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Cannot_Update_Container_Parent() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer root2 = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 2" }; - await DataTypeContainerService.CreateAsync(root2); + await DataTypeContainerService.CreateAsync(root2, null, Constants.Security.SuperUserKey); EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - await DataTypeContainerService.CreateAsync(child, root.Key); + await DataTypeContainerService.CreateAsync(child, root.Key, Constants.Security.SuperUserKey); EntityContainer toUpdate = await DataTypeContainerService.GetAsync(child.Key); Assert.IsNotNull(toUpdate); toUpdate.ParentId = root2.Id; - var result = await DataTypeContainerService.UpdateAsync(toUpdate); + var result = await DataTypeContainerService.UpdateAsync(toUpdate, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.ParentNotFound, result.Status); @@ -232,12 +232,12 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Cannot_Delete_Container_With_Child_Container() { EntityContainer root = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(root); + await DataTypeContainerService.CreateAsync(root, null, Constants.Security.SuperUserKey); EntityContainer child = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Child Container" }; - await DataTypeContainerService.CreateAsync(child, root.Key); + await DataTypeContainerService.CreateAsync(child, root.Key, Constants.Security.SuperUserKey); - var result = await DataTypeContainerService.DeleteAsync(root.Key); + var result = await DataTypeContainerService.DeleteAsync(root.Key, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.NotEmpty, result.Status); @@ -249,7 +249,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest public async Task Cannot_Delete_Container_With_Child_DataType() { EntityContainer container = new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }; - await DataTypeContainerService.CreateAsync(container); + await DataTypeContainerService.CreateAsync(container, null, Constants.Security.SuperUserKey); IDataType dataType = new DataType(new TextboxPropertyEditor(DataValueEditorFactory, IOHelper, EditorConfigurationParser), ConfigurationEditorJsonSerializer) @@ -258,9 +258,9 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest DatabaseType = ValueStorageType.Nvarchar, ParentId = container.Id }; - await DataTypeService.CreateAsync(dataType); + await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey); - var result = await DataTypeContainerService.DeleteAsync(container.Key); + var result = await DataTypeContainerService.DeleteAsync(container.Key, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.NotEmpty, result.Status); @@ -274,7 +274,7 @@ public class DataTypeContainerServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Delete_Non_Existing_Container() { - var result = await DataTypeContainerService.DeleteAsync(Guid.NewGuid()); + var result = await DataTypeContainerService.DeleteAsync(Guid.NewGuid(), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeContainerOperationStatus.NotFound, result.Status); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs index a16fa11436..b900f3b02a 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DataTypeServiceTests.cs @@ -46,7 +46,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext }; - var result = await DataTypeService.CreateAsync(dataType); + var result = await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey); Assert.True(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); @@ -67,7 +67,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest // Act dataType.Name += " UPDATED"; - var result = await DataTypeService.UpdateAsync(dataType); + var result = await DataTypeService.UpdateAsync(dataType, Constants.Security.SuperUserKey); Assert.True(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); @@ -89,7 +89,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest Name = Guid.NewGuid().ToString(), DatabaseType = ValueStorageType.Nvarchar }; - var result = await DataTypeService.CreateAsync(dataType); + var result = await DataTypeService.CreateAsync(dataType, Constants.Security.SuperUserKey); Assert.True(result.Success); return result.Result; } @@ -153,7 +153,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest // Act var definition = dataTypeDefinitions.First(); var definitionKey = definition.Key; - var result = await DataTypeService.DeleteAsync(definitionKey); + var result = await DataTypeService.DeleteAsync(definitionKey, Constants.Security.SuperUserKey); Assert.True(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); Assert.NotNull(result.Result); @@ -173,7 +173,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Create_DataType_In_Container() { - var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" })).Result; + var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }, null, Constants.Security.SuperUserKey)).Result; var result = await DataTypeService.CreateAsync( new DataType(new LabelPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) @@ -181,7 +181,8 @@ public class DataTypeServiceTests : UmbracoIntegrationTest Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext, ParentId = container.Id - }); + }, + Constants.Security.SuperUserKey); Assert.True(result.Success); Assert.IsNotNull(result.Result); @@ -200,15 +201,16 @@ public class DataTypeServiceTests : UmbracoIntegrationTest { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext - })).Result; + }, + Constants.Security.SuperUserKey)).Result; - var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" })).Result; + var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }, null, Constants.Security.SuperUserKey)).Result; dataType = await DataTypeService.GetAsync(dataType.Key); Assert.IsNotNull(dataType); Assert.AreEqual(Constants.System.Root, dataType.ParentId); - var result = await DataTypeService.MoveAsync(dataType, container.Key); + var result = await DataTypeService.MoveAsync(dataType, container.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); @@ -220,20 +222,21 @@ public class DataTypeServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Move_DataType_To_Root() { - var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" })).Result; + var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }, null, Constants.Security.SuperUserKey)).Result; var dataType = (await DataTypeService.CreateAsync( new DataType(new LabelPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext, ParentId = container.Id - })).Result; + }, + Constants.Security.SuperUserKey)).Result; dataType = await DataTypeService.GetAsync(dataType.Key); Assert.IsNotNull(dataType); Assert.AreEqual(container.Id, dataType.ParentId); - var result = await DataTypeService.MoveAsync(dataType, null); + var result = await DataTypeService.MoveAsync(dataType, null, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); @@ -250,9 +253,10 @@ public class DataTypeServiceTests : UmbracoIntegrationTest { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext - })).Result; + }, + Constants.Security.SuperUserKey)).Result; - var result = await DataTypeService.CopyAsync(dataType, null); + var result = await DataTypeService.CopyAsync(dataType, null, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); Assert.IsNotNull(result.Result); @@ -267,15 +271,16 @@ public class DataTypeServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Copy_DataType_To_Container() { - var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" })).Result; + var container = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container" }, null, Constants.Security.SuperUserKey)).Result; var dataType = (await DataTypeService.CreateAsync( new DataType(new LabelPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext - })).Result; + }, + Constants.Security.SuperUserKey)).Result; - var result = await DataTypeService.CopyAsync(dataType, container.Key); + var result = await DataTypeService.CopyAsync(dataType, container.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); Assert.IsNotNull(result.Result); @@ -290,17 +295,18 @@ public class DataTypeServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Copy_DataType_Between_Containers() { - var container1 = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 1" })).Result; - var container2 = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 2" })).Result; + var container1 = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 1" }, null, Constants.Security.SuperUserKey)).Result; + var container2 = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 2" }, null, Constants.Security.SuperUserKey)).Result; var dataType = (await DataTypeService.CreateAsync( new DataType(new LabelPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext, ParentId = container1.Id - })).Result; + }, + Constants.Security.SuperUserKey)).Result; - var result = await DataTypeService.CopyAsync(dataType, container2.Key); + var result = await DataTypeService.CopyAsync(dataType, container2.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); Assert.IsNotNull(result.Result); @@ -319,16 +325,17 @@ public class DataTypeServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Copy_DataType_From_Container_To_Root() { - var container1 = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 1" })).Result; + var container1 = (await DataTypeContainerService.CreateAsync(new EntityContainer(Constants.ObjectTypes.DataType) { Name = "Root Container 1" }, null, Constants.Security.SuperUserKey)).Result; var dataType = (await DataTypeService.CreateAsync( new DataType(new LabelPropertyEditor(DataValueEditorFactory, IOHelper), ConfigurationEditorJsonSerializer) { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext, ParentId = container1.Id - })).Result; + }, + Constants.Security.SuperUserKey)).Result; - var result = await DataTypeService.CopyAsync(dataType, null); + var result = await DataTypeService.CopyAsync(dataType, null, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DataTypeOperationStatus.Success, result.Status); Assert.IsNotNull(result.Result); @@ -356,7 +363,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest }; // Act - var result = await DataTypeService.CreateAsync(dataTypeDefinition); + var result = await DataTypeService.CreateAsync(dataTypeDefinition, Constants.Security.SuperUserKey); // Assert Assert.IsFalse(result.Success); @@ -375,7 +382,7 @@ public class DataTypeServiceTests : UmbracoIntegrationTest }; // Act - var result = await DataTypeService.CreateAsync(dataTypeDefinition); + var result = await DataTypeService.CreateAsync(dataTypeDefinition, Constants.Security.SuperUserKey); // Assert Assert.IsFalse(result.Success); @@ -405,13 +412,14 @@ public class DataTypeServiceTests : UmbracoIntegrationTest { Name = "Testing Textfield", DatabaseType = ValueStorageType.Ntext - })).Result; + }, + Constants.Security.SuperUserKey)).Result; dataType = await DataTypeService.GetAsync(dataType.Key); Assert.IsNotNull(dataType); Assert.AreEqual(Constants.System.Root, dataType.ParentId); - var result = await DataTypeService.MoveAsync(dataType, Guid.NewGuid()); + var result = await DataTypeService.MoveAsync(dataType, Guid.NewGuid(), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DataTypeOperationStatus.ParentNotFound, result.Status); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DictionaryItemServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DictionaryItemServiceTests.cs index dfa87ba61c..57f542de79 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DictionaryItemServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/DictionaryItemServiceTests.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.OperationStatus; @@ -120,7 +121,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest new DictionaryTranslation(en, "ChildValue1 " + i), new DictionaryTranslation(dk, "BørnVærdi1 " + i) } - }); + }, + Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); @@ -132,7 +134,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest new DictionaryTranslation(en, "ChildValue2 " + i), new DictionaryTranslation(dk, "BørnVærdi2 " + i) } - }); + }, + Constants.Security.SuperUserKey); currParentId = result.Result!.Key; } @@ -160,7 +163,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest new DictionaryItem("Testing123") { Translations = new List { new DictionaryTranslation(english, "Hello world") } - }); + }, + Constants.Security.SuperUserKey); Assert.True(result.Success); // re-get @@ -183,7 +187,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest new DictionaryItem("Testing123") { Translations = new List { new DictionaryTranslation(english, "Hello parent") } - }); + }, + Constants.Security.SuperUserKey); Assert.True(result.Success); var parentKey = result.Result.Key; @@ -192,7 +197,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest { Translations = new List { new DictionaryTranslation(english, "Hello child") }, ParentId = parentKey - }); + }, + Constants.Security.SuperUserKey); Assert.True(result.Success); // re-get @@ -215,8 +221,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest var translations = allLangs.Select(language => new DictionaryTranslation(language, $"Translation for: {language.IsoCode}")).ToArray(); var result = await DictionaryItemService.CreateAsync( - new DictionaryItem("Testing12345") { Translations = translations } - ); + new DictionaryItem("Testing12345") { Translations = translations }, + Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.Success, result.Status); @@ -246,8 +252,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest var firstLanguage = allLangs.First(); var translations = new[] { new DictionaryTranslation(firstLanguage, $"Translation for: {firstLanguage.IsoCode}") }; var result = await DictionaryItemService.CreateAsync( - new DictionaryItem("Testing12345") { Translations = translations } - ); + new DictionaryItem("Testing12345") { Translations = translations }, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.Success, result.Status); @@ -277,7 +282,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest { Key = key, Translations = new List { new DictionaryTranslation(english, "Hello world") } - }); + }, + Constants.Security.SuperUserKey); Assert.True(result.Success); Assert.AreEqual(key, result.Result.Key); @@ -292,7 +298,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest { var english = await LanguageService.GetAsync("en-US"); - var result = await DictionaryItemService.CreateAsync(new DictionaryItem("Testing12345")); + var result = await DictionaryItemService.CreateAsync(new DictionaryItem("Testing12345"), Constants.Security.SuperUserKey); Assert.True(result.Success); // re-get @@ -301,7 +307,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest item.Translations = new List { new DictionaryTranslation(english, "Hello world") }; - result = await DictionaryItemService.UpdateAsync(item); + result = await DictionaryItemService.UpdateAsync(item, Constants.Security.SuperUserKey); Assert.True(result.Success); Assert.AreEqual(1, item.Translations.Count()); @@ -317,7 +323,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest "My new value") }; - result = await DictionaryItemService.UpdateAsync(item); + result = await DictionaryItemService.UpdateAsync(item, Constants.Security.SuperUserKey); Assert.True(result.Success); // re-get @@ -335,7 +341,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest var item = await DictionaryItemService.GetAsync("Child"); Assert.NotNull(item); - var result = await DictionaryItemService.DeleteAsync(item.Key); + var result = await DictionaryItemService.DeleteAsync(item.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.Success, result.Status); @@ -352,7 +358,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest translation.Value += "UPDATED"; } - var result = await DictionaryItemService.UpdateAsync(item); + var result = await DictionaryItemService.UpdateAsync(item, Constants.Security.SuperUserKey); Assert.True(result.Success); var updatedItem = await DictionaryItemService.GetAsync("Child"); @@ -367,13 +373,13 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Move_DictionaryItem_To_Root() { - var rootOneKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"))).Result.Key; - var childKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = rootOneKey })).Result.Key; + var rootOneKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"), Constants.Security.SuperUserKey)).Result.Key; + var childKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = rootOneKey }, Constants.Security.SuperUserKey)).Result.Key; var child = await DictionaryItemService.GetAsync(childKey); Assert.AreEqual(rootOneKey, child.ParentId); - var result = await DictionaryItemService.MoveAsync(child, null); + var result = await DictionaryItemService.MoveAsync(child, null, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.Success, result.Status); @@ -390,14 +396,14 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Move_DictionaryItem_To_Other_Parent() { - var rootOneKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"))).Result.Key; - var rootTwoKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootTwo"))).Result.Key; - var childKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = rootOneKey })).Result.Key; + var rootOneKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"), Constants.Security.SuperUserKey)).Result.Key; + var rootTwoKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootTwo"), Constants.Security.SuperUserKey)).Result.Key; + var childKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = rootOneKey }, Constants.Security.SuperUserKey)).Result.Key; var child = await DictionaryItemService.GetAsync(childKey); Assert.AreEqual(rootOneKey, child.ParentId); - var result = await DictionaryItemService.MoveAsync(child, rootTwoKey); + var result = await DictionaryItemService.MoveAsync(child, rootTwoKey, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.Success, result.Status); @@ -408,14 +414,14 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Move_DictionaryItem_From_Root() { - var rootOneKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"))).Result.Key; - var rootTwoKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootTwo"))).Result.Key; - var childKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = rootOneKey })).Result.Key; + var rootOneKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"), Constants.Security.SuperUserKey)).Result.Key; + var rootTwoKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootTwo"), Constants.Security.SuperUserKey)).Result.Key; + var childKey = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = rootOneKey }, Constants.Security.SuperUserKey)).Result.Key; var rootTwo = await DictionaryItemService.GetAsync(rootTwoKey); Assert.IsNull(rootTwo.ParentId); - var result = await DictionaryItemService.MoveAsync(rootTwo, childKey); + var result = await DictionaryItemService.MoveAsync(rootTwo, childKey, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.Success, result.Status); @@ -434,7 +440,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest item.ItemKey = "Parent"; - var result = await DictionaryItemService.UpdateAsync(item); + var result = await DictionaryItemService.UpdateAsync(item, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.DuplicateItemKey, result.Status); @@ -448,7 +454,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest { var itemKey = Guid.NewGuid().ToString("N"); - var result = await DictionaryItemService.CreateAsync(new DictionaryItem(Guid.NewGuid(), itemKey)); + var result = await DictionaryItemService.CreateAsync(new DictionaryItem(Guid.NewGuid(), itemKey), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.ParentNotFound, result.Status); @@ -460,11 +466,11 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest public async Task Cannot_Create_Multiple_DictionaryItems_With_Same_ItemKey() { var itemKey = Guid.NewGuid().ToString("N"); - var result = await DictionaryItemService.CreateAsync(new DictionaryItem(itemKey)); + var result = await DictionaryItemService.CreateAsync(new DictionaryItem(itemKey), Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); - result = await DictionaryItemService.CreateAsync(new DictionaryItem(itemKey)); + result = await DictionaryItemService.CreateAsync(new DictionaryItem(itemKey), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.DuplicateItemKey, result.Status); } @@ -472,7 +478,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Update_Non_Existant_DictionaryItem() { - var result = await DictionaryItemService.UpdateAsync(new DictionaryItem("NoSuchItemKey")); + var result = await DictionaryItemService.UpdateAsync(new DictionaryItem("NoSuchItemKey"), Constants.Security.SuperUserKey); Assert.False(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.ItemNotFound, result.Status); } @@ -485,7 +491,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest item = new DictionaryItem(item.ParentId, item.ItemKey) { Key = item.Key, Translations = item.Translations }; - var result = await DictionaryItemService.UpdateAsync(item); + var result = await DictionaryItemService.UpdateAsync(item, Constants.Security.SuperUserKey); Assert.False(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.ItemNotFound, result.Status); } @@ -493,7 +499,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Delete_Non_Existant_DictionaryItem() { - var result = await DictionaryItemService.DeleteAsync(Guid.NewGuid()); + var result = await DictionaryItemService.DeleteAsync(Guid.NewGuid(), Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.ItemNotFound, result.Status); } @@ -509,7 +515,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest { Key = key, Translations = new List { new DictionaryTranslation(english, "Hello world") } - }); + }, + Constants.Security.SuperUserKey); Assert.True(result.Success); result = await DictionaryItemService.CreateAsync( @@ -517,7 +524,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest { Key = key, Translations = new List { new DictionaryTranslation(english, "Hello world") } - }); + }, + Constants.Security.SuperUserKey); Assert.False(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.DuplicateKey, result.Status); @@ -540,7 +548,7 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest childItem.Translations.First().Value = "Something Edited"; childItem.Translations.Last().Value = "Something Also Edited"; - var result = await DictionaryItemService.CreateAsync(childItem); + var result = await DictionaryItemService.CreateAsync(childItem, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.InvalidId, result.Status); } @@ -548,9 +556,9 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Move_DictionaryItem_To_Itself() { - var root = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"))).Result; + var root = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"), Constants.Security.SuperUserKey)).Result; - var result = await DictionaryItemService.MoveAsync(root, root.Key); + var result = await DictionaryItemService.MoveAsync(root, root.Key, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.InvalidParent, result.Status); @@ -561,10 +569,10 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Move_DictionaryItem_To_Child() { - var root = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"))).Result; - var child = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = root.Key })).Result; + var root = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"), Constants.Security.SuperUserKey)).Result; + var child = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = root.Key }, Constants.Security.SuperUserKey)).Result; - var result = await DictionaryItemService.MoveAsync(root, child.Key); + var result = await DictionaryItemService.MoveAsync(root, child.Key, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.InvalidParent, result.Status); @@ -575,11 +583,11 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Move_DictionaryItem_To_Descendant() { - var root = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"))).Result; - var child = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = root.Key })).Result; - var grandChild = (await DictionaryItemService.CreateAsync(new DictionaryItem("GrandChildOne") { ParentId = child.Key })).Result; + var root = (await DictionaryItemService.CreateAsync(new DictionaryItem("RootOne"), Constants.Security.SuperUserKey)).Result; + var child = (await DictionaryItemService.CreateAsync(new DictionaryItem("ChildOne") { ParentId = root.Key }, Constants.Security.SuperUserKey)).Result; + var grandChild = (await DictionaryItemService.CreateAsync(new DictionaryItem("GrandChildOne") { ParentId = child.Key }, Constants.Security.SuperUserKey)).Result; - var result = await DictionaryItemService.MoveAsync(root, grandChild.Key); + var result = await DictionaryItemService.MoveAsync(root, grandChild.Key, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(DictionaryItemOperationStatus.InvalidParent, result.Status); @@ -596,9 +604,9 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest .WithCultureInfo("en-GB") .Build(); - var languageResult = await LanguageService.CreateAsync(languageDaDk, 0); + var languageResult = await LanguageService.CreateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsTrue(languageResult.Success); - languageResult = await LanguageService.CreateAsync(languageEnGb, 0); + languageResult = await LanguageService.CreateAsync(languageEnGb, Constants.Security.SuperUserKey); Assert.IsTrue(languageResult.Success); var dictionaryResult = await DictionaryItemService.CreateAsync( @@ -609,7 +617,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest new DictionaryTranslation(languageEnGb, "ParentValue"), new DictionaryTranslation(languageDaDk, "ForældreVærdi") } - }); + }, + Constants.Security.SuperUserKey); Assert.True(dictionaryResult.Success); IDictionaryItem parentItem = dictionaryResult.Result!; @@ -626,7 +635,8 @@ public class DictionaryItemServiceTests : UmbracoIntegrationTest new DictionaryTranslation(languageEnGb, "ChildValue"), new DictionaryTranslation(languageDaDk, "BørnVærdi") } - }); + }, + Constants.Security.SuperUserKey); Assert.True(dictionaryResult.Success); IDictionaryItem childItem = dictionaryResult.Result!; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityServiceTests.cs index 038c5d3349..b1a35c3707 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityServiceTests.cs @@ -31,8 +31,8 @@ public class EntityServiceTests : UmbracoIntegrationTest { _langFr = new Language("fr-FR", "French (France)"); _langEs = new Language("es-ES", "Spanish (Spain)"); - await LanguageService.CreateAsync(_langFr); - await LanguageService.CreateAsync(_langEs); + await LanguageService.CreateAsync(_langFr, Constants.Security.SuperUserKey); + await LanguageService.CreateAsync(_langEs, Constants.Security.SuperUserKey); } CreateTestData(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs index 3c6a9da17d..2ac479b1b9 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/EntityXmlSerializerTests.cs @@ -90,12 +90,12 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest .WithCultureInfo("nb-NO") .WithCultureName("Norwegian Bokmål (Norway)") .Build(); - await languageService.CreateAsync(languageNbNo); + await languageService.CreateAsync(languageNbNo, Constants.Security.SuperUserKey); var languageEnGb = new LanguageBuilder() .WithCultureInfo("en-GB") .Build(); - await languageService.CreateAsync(languageEnGb); + await languageService.CreateAsync(languageEnGb, Constants.Security.SuperUserKey); var newPackageXml = XElement.Parse(ImportResources.Dictionary_Package); var languageItemsElement = newPackageXml.Elements("Languages").First(); @@ -297,12 +297,12 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest .WithCultureInfo("nb-NO") .WithCultureName("Norwegian") .Build(); - await languageService.CreateAsync(languageNbNo); + await languageService.CreateAsync(languageNbNo, Constants.Security.SuperUserKey); var languageEnGb = new LanguageBuilder() .WithCultureInfo("en-GB") .Build(); - await languageService.CreateAsync(languageEnGb); + await languageService.CreateAsync(languageEnGb, Constants.Security.SuperUserKey); var parentKey = Guid.Parse("28f2e02a-8c66-4fcd-85e3-8524d551c0d3"); var parentItem = new DictionaryItem("Parent") { Key = parentKey }; @@ -312,7 +312,7 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest new DictionaryTranslation(languageEnGb, "ParentValue") }; parentItem.Translations = parentTranslations; - var result = await dictionaryItemService.CreateAsync(parentItem); + var result = await dictionaryItemService.CreateAsync(parentItem, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(parentKey, result.Result.Key); @@ -325,7 +325,7 @@ public class EntityXmlSerializerTests : UmbracoIntegrationTest new DictionaryTranslation(languageEnGb, "ChildValue") }; childItem.Translations = childTranslations; - result = await dictionaryItemService.CreateAsync(childItem); + result = await dictionaryItemService.CreateAsync(childItem, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(childKey, result.Result.Key); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LanguageServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LanguageServiceTests.cs index 3970177f54..043ce3d2f4 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LanguageServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/LanguageServiceTests.cs @@ -1,4 +1,5 @@ using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Services.OperationStatus; @@ -49,13 +50,13 @@ public class LanguageServiceTests : UmbracoIntegrationTest var languageNbNo = new LanguageBuilder() .WithCultureInfo("nb-NO") .Build(); - await LanguageService.CreateAsync(languageNbNo, 0); + await LanguageService.CreateAsync(languageNbNo, Constants.Security.SuperUserKey); Assert.That(languageNbNo.HasIdentity, Is.True); var language = await LanguageService.GetAsync("nb-NO"); Assert.NotNull(language); - var result = await LanguageService.DeleteAsync("nb-NO"); + var result = await LanguageService.DeleteAsync("nb-NO", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); language = await LanguageService.GetAsync("nb-NO"); @@ -71,7 +72,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("nb-NO") .WithFallbackLanguageIsoCode(languageDaDk.IsoCode) .Build(); - var result = await LanguageService.CreateAsync(languageNbNo, 0); + var result = await LanguageService.CreateAsync(languageNbNo, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var language = await LanguageService.GetAsync("nb-NO"); @@ -88,14 +89,14 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("nb-NO") .WithFallbackLanguageIsoCode(languageDaDk.IsoCode) .Build(); - var result = await LanguageService.CreateAsync(languageNbNo, 0); + var result = await LanguageService.CreateAsync(languageNbNo, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var language = await LanguageService.GetAsync("nb-NO"); Assert.NotNull(language); Assert.AreEqual("da-DK", language.FallbackIsoCode); - result = await LanguageService.DeleteAsync("da-DK"); + result = await LanguageService.DeleteAsync("da-DK", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); language = await LanguageService.GetAsync("da-DK"); @@ -126,7 +127,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .Build(); // Act - await LanguageService.CreateAsync(languageEnAu); + await LanguageService.CreateAsync(languageEnAu, Constants.Security.SuperUserKey); var result = await LanguageService.GetAsync(isoCode); // Assert @@ -140,7 +141,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("en-AU") .WithIsDefault(true) .Build(); - await LanguageService.CreateAsync(languageEnAu); + await LanguageService.CreateAsync(languageEnAu, Constants.Security.SuperUserKey); var result = await LanguageService.GetAsync(languageEnAu.IsoCode); Assert.IsTrue(result.IsDefault); @@ -149,7 +150,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("en-NZ") .WithIsDefault(true) .Build(); - await LanguageService.CreateAsync(languageEnNz); + await LanguageService.CreateAsync(languageEnNz, Constants.Security.SuperUserKey); var result2 = await LanguageService.GetAsync(languageEnNz.IsoCode); // re-get @@ -166,10 +167,10 @@ public class LanguageServiceTests : UmbracoIntegrationTest var languageEnAu = new LanguageBuilder() .WithCultureInfo(isoCode) .Build(); - await LanguageService.CreateAsync(languageEnAu); + await LanguageService.CreateAsync(languageEnAu, Constants.Security.SuperUserKey); // Act - var result = await LanguageService.DeleteAsync(languageEnAu.IsoCode); + var result = await LanguageService.DeleteAsync(languageEnAu.IsoCode, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); // Assert @@ -186,7 +187,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest languageDaDk.IsoCode = "da"; languageDaDk.CultureName = "New Culture Name For da-DK"; - var result = await LanguageService.UpdateAsync(languageDaDk); + var result = await LanguageService.UpdateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(LanguageOperationStatus.Success, result.Status); @@ -210,7 +211,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.AreNotEqual(defaultLanguageIsoCode, languageDaDk.IsoCode); languageDaDk.IsDefault = true; - var result = await LanguageService.UpdateAsync(languageDaDk); + var result = await LanguageService.UpdateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); // re-get @@ -226,7 +227,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest public async Task Cannot_Create_Language_With_Invalid_IsoCode() { var invalidLanguage = new Language("no-such-iso-code", "Invalid ISO code"); - var result = await LanguageService.CreateAsync(invalidLanguage); + var result = await LanguageService.CreateAsync(invalidLanguage, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidIsoCode, result.Status); } @@ -238,13 +239,13 @@ public class LanguageServiceTests : UmbracoIntegrationTest var languageEnAu = new LanguageBuilder() .WithCultureInfo(isoCode) .Build(); - var result = await LanguageService.CreateAsync(languageEnAu); + var result = await LanguageService.CreateAsync(languageEnAu, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var duplicateLanguageEnAu = new LanguageBuilder() .WithCultureInfo(isoCode) .Build(); - result = await LanguageService.CreateAsync(duplicateLanguageEnAu); + result = await LanguageService.CreateAsync(duplicateLanguageEnAu, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.DuplicateIsoCode, result.Status); } @@ -257,7 +258,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo(isoCode) .WithFallbackLanguageIsoCode("no-such-ISO-code") .Build(); - var result = await LanguageService.CreateAsync(languageEnAu); + var result = await LanguageService.CreateAsync(languageEnAu, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidFallbackIsoCode, result.Status); } @@ -270,7 +271,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo(isoCode) .WithFallbackLanguageIsoCode("fr-FR") .Build(); - var result = await LanguageService.CreateAsync(languageEnAu); + var result = await LanguageService.CreateAsync(languageEnAu, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidFallback, result.Status); } @@ -279,7 +280,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest public async Task Cannot_Update_Non_Existing_Language() { ILanguage language = new Language("da", "Danish"); - var result = await LanguageService.UpdateAsync(language); + var result = await LanguageService.UpdateAsync(language, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.NotFound, result.Status); } @@ -294,7 +295,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.IsTrue(defaultLanguage.IsDefault); defaultLanguage.IsDefault = false; - var result = await LanguageService.UpdateAsync(defaultLanguage); + var result = await LanguageService.UpdateAsync(defaultLanguage, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.MissingDefault, result.Status); @@ -314,7 +315,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.IsNull(languageDaDk.FallbackIsoCode); languageDaDk.FallbackIsoCode = "fr-FR"; - var result = await LanguageService.UpdateAsync(languageDaDk); + var result = await LanguageService.UpdateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidFallback, result.Status); } @@ -327,7 +328,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.IsNull(languageDaDk.FallbackIsoCode); languageDaDk.FallbackIsoCode = "no-such-iso-code"; - var result = await LanguageService.UpdateAsync(languageDaDk); + var result = await LanguageService.UpdateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidFallbackIsoCode, result.Status); } @@ -343,11 +344,11 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.IsNull(languageEnGb.FallbackIsoCode); languageDaDk.FallbackIsoCode = languageEnGb.IsoCode; - var result = await LanguageService.UpdateAsync(languageDaDk); + var result = await LanguageService.UpdateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); languageEnGb.FallbackIsoCode = languageDaDk.IsoCode; - result = await LanguageService.UpdateAsync(languageEnGb); + result = await LanguageService.UpdateAsync(languageEnGb, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidFallback, result.Status); } @@ -366,15 +367,15 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.IsNull(languageDaDk.FallbackIsoCode); languageEnGb.FallbackIsoCode = languageEnUs.IsoCode; - var result = await LanguageService.UpdateAsync(languageEnGb); + var result = await LanguageService.UpdateAsync(languageEnGb, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); languageDaDk.FallbackIsoCode = languageEnGb.IsoCode; - result = await LanguageService.UpdateAsync(languageDaDk); + result = await LanguageService.UpdateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); languageEnUs.FallbackIsoCode = languageDaDk.IsoCode; - result = await LanguageService.UpdateAsync(languageEnUs); + result = await LanguageService.UpdateAsync(languageEnUs, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidFallback, result.Status); @@ -398,10 +399,10 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("nb-NO") .WithIsDefault(true) .Build(); - var result = await LanguageService.CreateAsync(languageNbNo); + var result = await LanguageService.CreateAsync(languageNbNo, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); - result = await LanguageService.DeleteAsync(languageNbNo.IsoCode); + result = await LanguageService.DeleteAsync(languageNbNo.IsoCode, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.MissingDefault, result.Status); @@ -418,7 +419,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("nb-NO") .Build(); - var result = await LanguageService.DeleteAsync(languageNbNo.IsoCode); + var result = await LanguageService.DeleteAsync(languageNbNo.IsoCode, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.NotFound, result.Status); } @@ -430,7 +431,7 @@ public class LanguageServiceTests : UmbracoIntegrationTest Assert.NotNull(languageDaDk); languageDaDk.IsoCode = "nb-NO"; - var result = await LanguageService.CreateAsync(languageDaDk); + var result = await LanguageService.CreateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(LanguageOperationStatus.InvalidId, result.Status); } @@ -444,9 +445,9 @@ public class LanguageServiceTests : UmbracoIntegrationTest .WithCultureInfo("en-GB") .Build(); - var languageResult = await LanguageService.CreateAsync(languageDaDk, 0); + var languageResult = await LanguageService.CreateAsync(languageDaDk, Constants.Security.SuperUserKey); Assert.IsTrue(languageResult.Success); - languageResult = await LanguageService.CreateAsync(languageEnGb, 0); + languageResult = await LanguageService.CreateAsync(languageEnGb, Constants.Security.SuperUserKey); Assert.IsTrue(languageResult.Success); } } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TemplateServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TemplateServiceTests.cs index 3517de7213..ed2abf5df4 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TemplateServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Services/TemplateServiceTests.cs @@ -23,18 +23,18 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Create_Template_Then_Assign_Child() { - Attempt result = await TemplateService.CreateAsync("Child", "child", "test"); + Attempt result = await TemplateService.CreateAsync("Child", "child", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(TemplateOperationStatus.Success, result.Status); var child = result.Result; - result = await TemplateService.CreateAsync("Parent", "parent", "test"); + result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(TemplateOperationStatus.Success, result.Status); var parent = result.Result; child.Content = "Layout = \"Parent.cshtml\";"; - result = await TemplateService.UpdateAsync(child); + result = await TemplateService.UpdateAsync(child, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); Assert.AreEqual(TemplateOperationStatus.Success, result.Status); @@ -47,11 +47,11 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Create_Template_With_Child_Then_Unassign() { - Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test"); + Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; - result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";"); + result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child = result.Result; @@ -60,7 +60,7 @@ public class TemplateServiceTests : UmbracoIntegrationTest Assert.AreEqual("parent", child.MasterTemplateAlias); child.Content = "test"; - result = await TemplateService.UpdateAsync(child); + result = await TemplateService.UpdateAsync(child, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); child = await TemplateService.GetAsync(child.Key); @@ -71,13 +71,13 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Create_Template_With_Child_Then_Reassign() { - Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test"); + Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); - result = await TemplateService.CreateAsync("Parent2", "parent2", "test"); + result = await TemplateService.CreateAsync("Parent2", "parent2", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); - result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";"); + result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child = result.Result; @@ -86,7 +86,7 @@ public class TemplateServiceTests : UmbracoIntegrationTest Assert.AreEqual("parent", child.MasterTemplateAlias); child.Content = "Layout = \"Parent2.cshtml\";"; - result = await TemplateService.UpdateAsync(child); + result = await TemplateService.UpdateAsync(child, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); child = await TemplateService.GetAsync(child.Key); @@ -97,23 +97,23 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Child_Template_Paths_Are_Updated_When_Reassigning_Master() { - Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test"); + Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; - result = await TemplateService.CreateAsync("Parent2", "parent2", "test"); + result = await TemplateService.CreateAsync("Parent2", "parent2", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent2 = result.Result; - result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";"); + result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child = result.Result; - result = await TemplateService.CreateAsync("Child1", "child1", "Layout = \"Child.cshtml\";"); + result = await TemplateService.CreateAsync("Child1", "child1", "Layout = \"Child.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var childOfChild1 = result.Result; - result = await TemplateService.CreateAsync("Child2", "child2", "Layout = \"Child.cshtml\";"); + result = await TemplateService.CreateAsync("Child2", "child2", "Layout = \"Child.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var childOfChild2 = result.Result; @@ -123,7 +123,7 @@ public class TemplateServiceTests : UmbracoIntegrationTest Assert.AreEqual($"{parent.Path},{child.Id},{childOfChild2.Id}", childOfChild2.Path); child.Content = "Layout = \"Parent2.cshtml\";"; - result = await TemplateService.UpdateAsync(child); + result = await TemplateService.UpdateAsync(child, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); childOfChild1 = await TemplateService.GetAsync(childOfChild1.Key); @@ -141,15 +141,15 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Query_Template_Children() { - Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test"); + Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; - result = await TemplateService.CreateAsync("Child1", "child1", "Layout = \"Parent.cshtml\";"); + result = await TemplateService.CreateAsync("Child1", "child1", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child1 = result.Result; - result = await TemplateService.CreateAsync("Child2", "child2", "Layout = \"Parent.cshtml\";"); + result = await TemplateService.CreateAsync("Child2", "child2", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child2 = result.Result; @@ -163,13 +163,13 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Update_Template() { - var result = await TemplateService.CreateAsync("Parent", "parent", "test"); + var result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; parent.Name = "Parent Updated"; - result = await TemplateService.UpdateAsync(parent); + result = await TemplateService.UpdateAsync(parent, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); @@ -182,12 +182,12 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Can_Delete_Template() { - var result = await TemplateService.CreateAsync("Parent", "parent", "test"); + var result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; - result = await TemplateService.DeleteAsync(parent.Key); + result = await TemplateService.DeleteAsync(parent.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); parent = await TemplateService.GetAsync(parent.Key); @@ -197,16 +197,16 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Deleting_Master_Template_Also_Deletes_Children() { - Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test"); + Attempt result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; - result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";"); + result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child = result.Result; Assert.AreEqual("parent", child.MasterTemplateAlias); - result = await TemplateService.DeleteAsync(parent.Key); + result = await TemplateService.DeleteAsync(parent.Key, Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); child = await TemplateService.GetAsync(child.Key); @@ -216,17 +216,17 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Update_Non_Existing_Template() { - var result = await TemplateService.CreateAsync("Parent", "parent", "test"); + var result = await TemplateService.CreateAsync("Parent", "parent", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var parent = result.Result; - result = await TemplateService.DeleteAsync("parent"); + result = await TemplateService.DeleteAsync("parent", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); parent.Name = "Parent Updated"; - result = await TemplateService.UpdateAsync(parent); + result = await TemplateService.UpdateAsync(parent, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(TemplateOperationStatus.TemplateNotFound, result.Status); } @@ -234,7 +234,7 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Create_Child_Template_Without_Master_Template() { - var result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";"); + var result = await TemplateService.CreateAsync("Child", "child", "Layout = \"Parent.cshtml\";", Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(TemplateOperationStatus.MasterTemplateNotFound, result.Status); } @@ -242,13 +242,13 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Update_Child_Template_Without_Master_Template() { - var result = await TemplateService.CreateAsync("Child", "child", "test"); + var result = await TemplateService.CreateAsync("Child", "child", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child = result.Result; child.Content = "Layout = \"Parent.cshtml\";"; - result = await TemplateService.UpdateAsync(child); + result = await TemplateService.UpdateAsync(child, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(TemplateOperationStatus.MasterTemplateNotFound, result.Status); } @@ -257,7 +257,7 @@ public class TemplateServiceTests : UmbracoIntegrationTest public async Task Cannot_Create_Template_With_Invalid_Alias() { var invalidAlias = new string('a', 256); - var result = await TemplateService.CreateAsync("Child", invalidAlias, "test"); + var result = await TemplateService.CreateAsync("Child", invalidAlias, "test", Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(TemplateOperationStatus.InvalidAlias, result.Status); } @@ -265,14 +265,14 @@ public class TemplateServiceTests : UmbracoIntegrationTest [Test] public async Task Cannot_Update_Template_With_Invalid_Alias() { - var result = await TemplateService.CreateAsync("Child", "child", "test"); + var result = await TemplateService.CreateAsync("Child", "child", "test", Constants.Security.SuperUserKey); Assert.IsTrue(result.Success); var child = result.Result; var invalidAlias = new string('a', 256); child.Alias = invalidAlias; - result = await TemplateService.UpdateAsync(child); + result = await TemplateService.UpdateAsync(child, Constants.Security.SuperUserKey); Assert.IsFalse(result.Success); Assert.AreEqual(TemplateOperationStatus.InvalidAlias, result.Status); } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs index 08ca19f249..b28cd17b62 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Controllers/ContentControllerTests.cs @@ -31,10 +31,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase var languageService = GetRequiredService(); // Add another language - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var url = PrepareApiControllerUrl(x => x.PostSave(null)); @@ -87,10 +89,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase var languageService = GetRequiredService(); // Add another language - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var url = PrepareApiControllerUrl(x => x.PostSave(null)); @@ -155,10 +159,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase var languageService = GetRequiredService(); // Add another language - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var url = PrepareApiControllerUrl(x => x.PostSave(null)); @@ -218,10 +224,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase var languageService = GetRequiredService(); // Add another language - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var url = PrepareApiControllerUrl(x => x.PostSave(null)); @@ -277,10 +285,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase var languageService = GetRequiredService(); // Add another language - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var url = PrepareApiControllerUrl(x => x.PostSave(null)); @@ -339,10 +349,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase var languageService = GetRequiredService(); // Add another language - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var url = PrepareApiControllerUrl(x => x.PostSave(null)); @@ -399,10 +411,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase public async Task PostSave_Validates_Domains_Exist() { var languageService = GetRequiredService(); - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var contentTypeService = GetRequiredService(); var contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); @@ -448,15 +462,19 @@ public class ContentControllerTests : UmbracoTestServerTestBase var sweIso = "sv-SE"; var languageService = GetRequiredService(); //Create 2 new languages - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(sweIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var contentTypeService = GetRequiredService(); var contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); @@ -543,10 +561,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase public async Task PostSave_Validates_All_Cultures_Has_Domains() { var languageService = GetRequiredService(); - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var contentTypeService = GetRequiredService(); var contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); @@ -604,10 +624,12 @@ public class ContentControllerTests : UmbracoTestServerTestBase public async Task PostSave_Checks_Ancestors_For_Domains() { var languageService = GetRequiredService(); - await languageService.CreateAsync(new LanguageBuilder() + await languageService.CreateAsync( + new LanguageBuilder() .WithCultureInfo(DkIso) .WithIsDefault(false) - .Build()); + .Build(), + Constants.Security.SuperUserKey); var contentTypeService = GetRequiredService(); var contentType = new ContentTypeBuilder().WithContentVariation(ContentVariation.Culture).Build(); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventFilterTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventFilterTests.cs index 1d6042d980..aafa54cbe2 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventFilterTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Web.BackOffice/Filters/OutgoingEditorModelEventFilterTests.cs @@ -1,5 +1,6 @@ using System.Net; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Events; using Umbraco.Cms.Core.Models; using Umbraco.Cms.Core.Models.ContentEditing; @@ -88,8 +89,8 @@ public class OutgoingEditorModelEventFilterTests : UmbracoTestServerTestBase .WithIsDefault(false) .Build(); - await languageService.CreateAsync(dkLang); - await languageService.CreateAsync(sweLang); + await languageService.CreateAsync(dkLang, Constants.Security.SuperUserKey); + await languageService.CreateAsync(sweLang, Constants.Security.SuperUserKey); var content = new ContentBuilder() .WithoutIdentity()