From 72031f279d768da9b8e0cee19af6237ed3376a05 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Mon, 4 Nov 2024 15:11:56 +0100 Subject: [PATCH 01/15] Replace obsolete UserGroup Alias consts to key equivalent in tests --- .../Services/ContentServiceTests.cs | 8 +++--- .../Services/UserServiceCrudTests.Filter.cs | 26 +++++++++---------- .../Services/UserServiceCrudTests.Get.cs | 16 ++++++------ .../UserServiceCrudTests.PartialUpdates.cs | 12 ++++----- 4 files changed, 32 insertions(+), 30 deletions(-) diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs index 67612b575683..e31363d08ba9 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs @@ -55,6 +55,8 @@ public class ContentServiceTests : UmbracoIntegrationTestWithContent private IUserService UserService => GetRequiredService(); + private IUserGroupService UserGroupService => GetRequiredService(); + private IRelationService RelationService => GetRequiredService(); private ILocalizedTextService TextService => GetRequiredService(); @@ -2055,11 +2057,11 @@ public async Task Can_Empty_RecycleBin_With_Content_That_Has_All_Related_Data() ContentService.Save(content2); Assert.IsTrue(ContentService.Publish(content2, content2.AvailableCultures.ToArray(), userId: -1).Success); - var editorGroup = UserService.GetUserGroupByAlias(Constants.Security.EditorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); editorGroup.StartContentId = content1.Id; UserService.Save(editorGroup); - var admin = UserService.GetUserById(Constants.Security.SuperUserId); + var admin = await UserService.GetAsync(Constants.Security.SuperUserKey); admin.StartContentIds = new[] { content1.Id }; UserService.Save(admin); @@ -2071,7 +2073,7 @@ public async Task Can_Empty_RecycleBin_With_Content_That_Has_All_Related_Data() new List { new() { RuleType = "test", RuleValue = "test" } })); Assert.IsTrue(PublicAccessService.AddRule(content1, "test2", "test2").Success); - var user = UserService.GetUserById(Constants.Security.SuperUserId); + var user = UserService.GetAsync(Constants.Security.SuperUserKey); var userGroup = UserService.GetUserGroupByAlias(user.Groups.First().Alias); Assert.IsNotNull(NotificationService.CreateNotification(user, content1, "X")); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Filter.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Filter.cs index 82d28c5441c3..71b557d4d2e7 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Filter.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Filter.cs @@ -16,7 +16,7 @@ public partial class UserServiceCrudTests public async Task Cannot_Request_Disabled_If_Hidden(UserState includeState) { var userService = CreateUserService(new SecuritySettings {HideDisabledUsersInBackOffice = true}); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var createModel = new UserCreateModel { @@ -44,8 +44,8 @@ public async Task Cannot_Request_Disabled_If_Hidden(UserState includeState) public async Task Only_Super_User_Can_Filter_Super_user() { var userService = CreateUserService(); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); var nonSuperCreateModel = new UserCreateModel { @@ -78,7 +78,7 @@ public async Task Only_Super_User_Can_Filter_Super_user() public async Task Super_User_Can_Filter_Super_User() { var userService = CreateUserService(); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var nonSuperCreateModel = new UserCreateModel { @@ -107,8 +107,8 @@ public async Task Super_User_Can_Filter_Super_User() public async Task Non_Admins_Cannot_Filter_Admins() { var userService = CreateUserService(); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var editorCreateModel = new UserCreateModel { @@ -146,8 +146,8 @@ public async Task Non_Admins_Cannot_Filter_Admins() public async Task Admins_Can_Filter_Admins() { var userService = CreateUserService(); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var editorCreateModel = new UserCreateModel { @@ -185,10 +185,10 @@ public async Task Admins_Can_Filter_Admins() private async Task CreateTestUsers(IUserService userService) { - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); - var writerGroup = await UserGroupService.GetAsync(Constants.Security.WriterGroupAlias); - var translatorGroup = await UserGroupService.GetAsync(Constants.Security.TranslatorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); + var writerGroup = await UserGroupService.GetAsync(Constants.Security.WriterGroupKey); + var translatorGroup = await UserGroupService.GetAsync(Constants.Security.TranslatorGroupKey); var createModels = new List { @@ -262,7 +262,7 @@ public async Task Can_Exclude_User_Groups() var userService = CreateUserService(); await CreateTestUsers(userService); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var filter = new UserFilter { ExcludeUserGroups = new HashSet { editorGroup!.Key } diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Get.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Get.cs index 69263159e62d..6d33c92a8a75 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Get.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.Get.cs @@ -13,8 +13,8 @@ public partial class UserServiceCrudTests public async Task Only_Super_User_Can_Get_Super_user() { var userService = CreateUserService(); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); var nonSuperCreateModel = new UserCreateModel { @@ -43,7 +43,7 @@ public async Task Only_Super_User_Can_Get_Super_user() public async Task Super_User_Can_See_Super_User() { var userService = CreateUserService(); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var nonSuperCreateModel = new UserCreateModel { @@ -71,8 +71,8 @@ public async Task Super_User_Can_See_Super_User() public async Task Non_Admins_Cannot_Get_admins() { var userService = CreateUserService(); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var editorCreateModel = new UserCreateModel { @@ -107,8 +107,8 @@ public async Task Non_Admins_Cannot_Get_admins() public async Task Admins_Can_See_Admins() { var userService = CreateUserService(); - var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var adminGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var editorCreateModel = new UserCreateModel { @@ -144,7 +144,7 @@ public async Task Admins_Can_See_Admins() public async Task Cannot_See_Disabled_When_HideDisabled_Is_True() { var userService = CreateUserService(securitySettings: new SecuritySettings { HideDisabledUsersInBackOffice = true }); - var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var firstEditorCreateModel = new UserCreateModel { diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.PartialUpdates.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.PartialUpdates.cs index 013e53057e5a..5eaf3b07aed9 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.PartialUpdates.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserServiceCrudTests.PartialUpdates.cs @@ -11,7 +11,7 @@ public partial class UserServiceCrudTests [Test] public async Task Can_Enable_User() { - var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var userCreateModel = new UserCreateModel { @@ -39,7 +39,7 @@ public async Task Can_Enable_User() [Test] public async Task Can_Disable_User() { - var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var userCreateModel = new UserCreateModel { @@ -63,7 +63,7 @@ public async Task Can_Disable_User() [Test] public async Task User_Cannot_Disable_Self() { - var adminUserGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupAlias); + var adminUserGroup = await UserGroupService.GetAsync(Constants.Security.AdminGroupKey); var userCreateModel = new UserCreateModel { @@ -85,7 +85,7 @@ public async Task User_Cannot_Disable_Self() [Test] public async Task Cannot_Disable_Invited_User() { - var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var userInviteModel = new UserInviteModel { @@ -108,7 +108,7 @@ public async Task Cannot_Disable_Invited_User() [Test] public async Task Enable_Missing_User_Fails_With_Not_Found() { - var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var userCreateModel = new UserCreateModel { @@ -132,7 +132,7 @@ public async Task Enable_Missing_User_Fails_With_Not_Found() [Test] public async Task Disable_Missing_User_Fails_With_Not_Found() { - var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupAlias); + var editorUserGroup = await UserGroupService.GetAsync(Constants.Security.EditorGroupKey); var userCreateModel = new UserCreateModel { From 53f57c43c3c9dc863ee7f6f65c52cdd43a1aa94d Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Mon, 4 Nov 2024 15:12:48 +0100 Subject: [PATCH 02/15] Update use of usergroup alias consts to key equivalent in IsSystemgroup extension method --- .../Models/Membership/UserGroupExtensions.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs index 8c5940ac7573..d01f7cc37e6e 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs @@ -30,13 +30,13 @@ public static IReadOnlyUserGroup ToReadOnlyGroup(this IUserGroup group) } public static bool IsSystemUserGroup(this IUserGroup group) => - IsSystemUserGroup(group.Alias); + IsSystemUserGroup(group.Key); public static bool IsSystemUserGroup(this IReadOnlyUserGroup group) => - IsSystemUserGroup(group.Alias); + IsSystemUserGroup(group.Key); - private static bool IsSystemUserGroup(this string? groupAlias) => - groupAlias == Constants.Security.AdminGroupAlias - || groupAlias == Constants.Security.SensitiveDataGroupAlias - || groupAlias == Constants.Security.TranslatorGroupAlias; + private static bool IsSystemUserGroup(this Guid? groupKey) => + groupKey == Constants.Security.AdminGroupKey + || groupKey == Constants.Security.AdminGroupKey + || groupKey == Constants.Security.AdminGroupKey; } From 97407e8e6742f1492d6b5519ff78daa2c4a3d820 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 09:26:57 +0100 Subject: [PATCH 03/15] Obsolete (internally) unused helper function which purpose doesn't even seem true --- src/Umbraco.Core/Services/UserService.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Umbraco.Core/Services/UserService.cs b/src/Umbraco.Core/Services/UserService.cs index 07da9f631ab3..e160a272dc98 100644 --- a/src/Umbraco.Core/Services/UserService.cs +++ b/src/Umbraco.Core/Services/UserService.cs @@ -477,6 +477,7 @@ public void Save(IEnumerable entities) /// This is just the default user group that the membership provider will use /// /// + [Obsolete("No (backend) code path is using this anymore, so it can not be considered the default. Planned for removal in V16.")] public string GetDefaultMemberType() => Constants.Security.WriterGroupAlias; /// From bac856d99ca477a4ac12c77b1f928a58bc9fe54c Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 10:15:40 +0100 Subject: [PATCH 04/15] Prepped EmbedProviders for proper removal of non async methods and unneeded proxy methods --- .../Media/EmbedProviders/DailyMotion.cs | 9 ++++-- .../Media/EmbedProviders/Flickr.cs | 10 ++++--- .../Media/EmbedProviders/GettyImages.cs | 8 ++++-- .../Media/EmbedProviders/Giphy.cs | 8 ++++-- src/Umbraco.Core/Media/EmbedProviders/Hulu.cs | 8 ++++-- .../Media/EmbedProviders/Issuu.cs | 8 ++++-- .../Media/EmbedProviders/Kickstarter.cs | 8 ++++-- .../Media/EmbedProviders/LottieFiles.cs | 18 ++++++++---- .../EmbedProviders/OEmbedProviderBase.cs | 28 ++++++++++++++++++- .../Media/EmbedProviders/Slideshare.cs | 8 ++++-- .../Media/EmbedProviders/SoundCloud.cs | 8 ++++-- src/Umbraco.Core/Media/EmbedProviders/Ted.cs | 8 ++++-- .../Media/EmbedProviders/Twitter.cs | 8 ++++-- .../Media/EmbedProviders/Vimeo.cs | 8 ++++-- src/Umbraco.Core/Media/EmbedProviders/X.cs | 9 +++--- .../Media/EmbedProviders/Youtube.cs | 8 ++++-- src/Umbraco.Core/Media/IEmbedProvider.cs | 1 + 17 files changed, 111 insertions(+), 52 deletions(-) diff --git a/src/Umbraco.Core/Media/EmbedProviders/DailyMotion.cs b/src/Umbraco.Core/Media/EmbedProviders/DailyMotion.cs index 9c75db64e2b8..0f2abd3b8ebc 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/DailyMotion.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/DailyMotion.cs @@ -23,6 +23,11 @@ public DailyMotion(IJsonSerializer jsonSerializer) { "format", "xml" }, }; + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetXmlBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] + public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); @@ -33,7 +38,5 @@ public DailyMotion(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); } diff --git a/src/Umbraco.Core/Media/EmbedProviders/Flickr.cs b/src/Umbraco.Core/Media/EmbedProviders/Flickr.cs index 6838c0f73f2d..0d7d8b3a0f17 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Flickr.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Flickr.cs @@ -22,11 +22,9 @@ public Flickr(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); XmlDocument xmlDocument = await base.GetXmlResponseAsync(requestUrl, cancellationToken); @@ -38,4 +36,8 @@ public Flickr(IJsonSerializer jsonSerializer) return string.Format("\"{3}\"", imageUrl, imageWidth, imageHeight, WebUtility.HtmlEncode(imageTitle)); } + + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] + public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetMarkupAsync(url, maxWidth, maxHeight, cancellationToken); } diff --git a/src/Umbraco.Core/Media/EmbedProviders/GettyImages.cs b/src/Umbraco.Core/Media/EmbedProviders/GettyImages.cs index 02631542d0de..41364111af01 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/GettyImages.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/GettyImages.cs @@ -22,10 +22,12 @@ public GettyImages(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Giphy.cs b/src/Umbraco.Core/Media/EmbedProviders/Giphy.cs index e9938f316401..1e8b2c96c8da 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Giphy.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Giphy.cs @@ -20,10 +20,12 @@ public Giphy(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Hulu.cs b/src/Umbraco.Core/Media/EmbedProviders/Hulu.cs index 5fdd22c667ce..4e4d53e6ad66 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Hulu.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Hulu.cs @@ -20,10 +20,12 @@ public Hulu(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Issuu.cs b/src/Umbraco.Core/Media/EmbedProviders/Issuu.cs index adeb6b45f809..42120b70c5f5 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Issuu.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Issuu.cs @@ -28,10 +28,12 @@ public Issuu(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetXmlBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Kickstarter.cs b/src/Umbraco.Core/Media/EmbedProviders/Kickstarter.cs index 78c50253ec81..a54c03455f60 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Kickstarter.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Kickstarter.cs @@ -20,10 +20,12 @@ public Kickstarter(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/LottieFiles.cs b/src/Umbraco.Core/Media/EmbedProviders/LottieFiles.cs index 56c2c8a1fdd1..8ce00feea793 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/LottieFiles.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/LottieFiles.cs @@ -21,14 +21,12 @@ public LottieFiles(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { - var requestUrl = this.GetEmbedProviderUrl(url, maxWidth, maxHeight); - OEmbedResponse? oembed = await this.GetJsonResponseAsync(requestUrl, cancellationToken); + var requestUrl = GetEmbedProviderUrl(url, maxWidth, maxHeight); + OEmbedResponse? oembed = await GetJsonResponseAsync(requestUrl, cancellationToken); var html = oembed?.GetHtml(); // LottieFiles doesn't seem to support maxwidth and maxheight via oembed @@ -53,4 +51,12 @@ public LottieFiles(IJsonSerializer jsonSerializer) return html; } + + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] + public override async Task GeOEmbedDataAsync( + string url, + int? maxWidth, + int? maxHeight, + CancellationToken cancellationToken) + => await GetMarkupAsync(url, maxWidth, maxHeight, cancellationToken); } diff --git a/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs b/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs index f0b0f3a21723..57c6df4f6d8f 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs @@ -21,9 +21,14 @@ public abstract class OEmbedProviderBase : IEmbedProvider [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public abstract string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0); - public virtual Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) => Task.FromResult(GetMarkup(url, maxWidth ?? 0, maxHeight ?? 0)); + public abstract Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken); + + [Obsolete("Cleanup, only proxied to by GetMarkupAsync implementations. Planned for removal in v16")] + public virtual Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => Task.FromResult(GetMarkup(url, maxWidth ?? 0, maxHeight ?? 0)); public virtual string GetEmbedProviderUrl(string url, int? maxWidth, int? maxHeight) => GetEmbedProviderUrl(url, maxWidth ?? 0, maxHeight ?? 0); + public virtual string GetEmbedProviderUrl(string url, int maxWidth, int maxHeight) { if (Uri.IsWellFormedUriString(url, UriKind.RelativeOrAbsolute) == false) @@ -124,4 +129,25 @@ public virtual string GetXmlProperty(XmlDocument doc, string property) XmlNode? selectSingleNode = doc.SelectSingleNode(property); return selectSingleNode != null ? selectSingleNode.InnerText : string.Empty; } + + public virtual async Task GetJsonBasedMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + { + var requestUrl = GetEmbedProviderUrl(url, maxWidth, maxHeight); + OEmbedResponse? oembed = await GetJsonResponseAsync(requestUrl, cancellationToken); + + return oembed?.GetHtml(); + } + + public virtual async Task GetXmlBasedMarkupAsync( + string url, + int? maxWidth, + int? maxHeight, + CancellationToken cancellationToken, + string property = "/oembed/html") + { + var requestUrl = GetEmbedProviderUrl(url, maxWidth, maxHeight); + XmlDocument xmlDocument = await GetXmlResponseAsync(requestUrl, cancellationToken); + + return GetXmlProperty(xmlDocument, property); + } } diff --git a/src/Umbraco.Core/Media/EmbedProviders/Slideshare.cs b/src/Umbraco.Core/Media/EmbedProviders/Slideshare.cs index c1b4731bfb80..f7b5a0830ce3 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Slideshare.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Slideshare.cs @@ -21,10 +21,12 @@ public Slideshare(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetXmlBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/SoundCloud.cs b/src/Umbraco.Core/Media/EmbedProviders/SoundCloud.cs index 43092dddaa73..ab8e7ab0a570 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/SoundCloud.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/SoundCloud.cs @@ -22,10 +22,12 @@ public Soundcloud(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetXmlBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Ted.cs b/src/Umbraco.Core/Media/EmbedProviders/Ted.cs index 8816382cf882..a68df4f6fb78 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Ted.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Ted.cs @@ -21,10 +21,12 @@ public Ted(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetXmlBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Twitter.cs b/src/Umbraco.Core/Media/EmbedProviders/Twitter.cs index ac5cab8604ce..3b57f0c44d4f 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Twitter.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Twitter.cs @@ -21,10 +21,12 @@ public Twitter(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/Vimeo.cs b/src/Umbraco.Core/Media/EmbedProviders/Vimeo.cs index f4db5b17c932..2f6816f4c1a9 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Vimeo.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Vimeo.cs @@ -21,10 +21,12 @@ public Vimeo(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetXmlBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/EmbedProviders/X.cs b/src/Umbraco.Core/Media/EmbedProviders/X.cs index c4d102e941c9..391796dc5193 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/X.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/X.cs @@ -18,11 +18,10 @@ public X(IJsonSerializer jsonSerializer) public override Dictionary RequestParams => new(); + [Obsolete("Use GetMarkupAsync instead. This will be removed in v16.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); - OEmbedResponse? oembed = base.GetJsonResponse(requestUrl); + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - return oembed?.GetHtml(); - } + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); } diff --git a/src/Umbraco.Core/Media/EmbedProviders/Youtube.cs b/src/Umbraco.Core/Media/EmbedProviders/Youtube.cs index edaf37c0b0c3..4392e6a4dd68 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/Youtube.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/Youtube.cs @@ -24,10 +24,12 @@ public YouTube(IJsonSerializer jsonSerializer) [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] public override string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0) - { - return GeOEmbedDataAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); - } + => GetMarkupAsync(url, maxWidth, maxHeight, CancellationToken.None).GetAwaiter().GetResult(); + + public override async Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) + => await GetJsonBasedMarkupAsync(url, maxWidth, maxHeight, cancellationToken); + [Obsolete("Use GetMarkupAsync instead. Planned for removal in v16")] public override async Task GeOEmbedDataAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) { var requestUrl = base.GetEmbedProviderUrl(url, maxWidth, maxHeight); diff --git a/src/Umbraco.Core/Media/IEmbedProvider.cs b/src/Umbraco.Core/Media/IEmbedProvider.cs index fb27b4bb9b1e..64e0947abdaa 100644 --- a/src/Umbraco.Core/Media/IEmbedProvider.cs +++ b/src/Umbraco.Core/Media/IEmbedProvider.cs @@ -20,5 +20,6 @@ public interface IEmbedProvider [Obsolete("Use GetMarkupAsync instead. This will be removed in Umbraco 15.")] string? GetMarkup(string url, int maxWidth = 0, int maxHeight = 0); + Task GetMarkupAsync(string url, int? maxWidth, int? maxHeight, CancellationToken cancellationToken) => Task.FromResult(GetMarkup(url, maxWidth ?? 0, maxHeight ?? 0)); } From 8020d305ec32e0207c38dd880930a364484a74a0 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 10:24:43 +0100 Subject: [PATCH 05/15] Remove obsoleted UmbracoPath and updated internal references --- .../Configuration/GlobalSettingsExtensions.cs | 6 +++--- .../Configuration/Models/GlobalSettings.cs | 10 ---------- 2 files changed, 3 insertions(+), 13 deletions(-) diff --git a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs index 2f49bfd146cd..67966c984981 100644 --- a/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs +++ b/src/Umbraco.Core/Configuration/GlobalSettingsExtensions.cs @@ -22,7 +22,7 @@ public static string GetBackOfficePath(this GlobalSettings globalSettings, IHost return _backOfficePath; } - _backOfficePath = hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); + _backOfficePath = hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath); return _backOfficePath; } @@ -54,9 +54,9 @@ internal static string GetUmbracoMvcAreaNoCache( this GlobalSettings globalSettings, IHostingEnvironment hostingEnvironment) { - var path = string.IsNullOrEmpty(globalSettings.UmbracoPath) + var path = string.IsNullOrEmpty(Constants.System.DefaultUmbracoPath) ? string.Empty - : hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath); + : hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath); if (path.IsNullOrWhiteSpace()) { diff --git a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs index 58d1bb7134f4..7d2556ea60c3 100644 --- a/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/GlobalSettings.cs @@ -76,16 +76,6 @@ internal const string [DefaultValue(StaticVersionCheckPeriod)] public int VersionCheckPeriod { get; set; } = StaticVersionCheckPeriod; - /// - /// Gets or sets a value for the Umbraco back-office path. - /// - [Obsolete($"UmbracoPath is no longer configurable, use Constants.System.DefaultUmbracoPath instead. This property is scheduled for removal in a future version.")] - public string UmbracoPath - { - get => Constants.System.DefaultUmbracoPath; - set { } - } - /// /// Gets or sets a value for the Umbraco icons path. /// From a0e14c4d82286efbb53a387a7a1cdfcd18f163ac Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 13:26:55 +0100 Subject: [PATCH 06/15] Corrected mistake and updated unittets --- .../Models/Membership/UserGroupExtensions.cs | 4 +-- .../Services/UserGroupServiceTests.cs | 25 +++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs index d01f7cc37e6e..ac6c8ce7656a 100644 --- a/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs +++ b/src/Umbraco.Core/Models/Membership/UserGroupExtensions.cs @@ -37,6 +37,6 @@ public static bool IsSystemUserGroup(this IReadOnlyUserGroup group) => private static bool IsSystemUserGroup(this Guid? groupKey) => groupKey == Constants.Security.AdminGroupKey - || groupKey == Constants.Security.AdminGroupKey - || groupKey == Constants.Security.AdminGroupKey; + || groupKey == Constants.Security.SensitiveDataGroupKey + || groupKey == Constants.Security.TranslatorGroupKey; } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs index 268b3f0659ad..b42a66084b4b 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs @@ -90,21 +90,36 @@ public async Task Filter_Can_Filter_By_Group_Name() }); } - [TestCase(false,UserGroupOperationStatus.Success)] - [TestCase(true,UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] - public async Task Can_Not_Update_SystemGroup_Alias(bool isSystemGroup, UserGroupOperationStatus status) + // Obsoletion will be resolved when they are converted to internal consts. + [TestCase(null, UserGroupOperationStatus.Success)] + [TestCase(Constants.Security.AdminGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] + [TestCase(Constants.Security.SensitiveDataGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] + [TestCase(Constants.Security.TranslatorGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] + public async Task Can_Not_Update_SystemGroup_Alias(string? systemGroupAlias, UserGroupOperationStatus status) { + // prep + var userGroupAlias = systemGroupAlias ?? "someNonSystemAlias"; + Guid userGroupKey = Guid.NewGuid(); + switch (userGroupAlias) + { + case Constants.Security.AdminGroupAlias : userGroupKey = Constants.Security.AdminGroupKey; + break; + case Constants.Security.SensitiveDataGroupAlias : userGroupKey = Constants.Security.SensitiveDataGroupKey; + break; + case Constants.Security.TranslatorGroupAlias : userGroupKey = Constants.Security.TranslatorGroupKey; + break; + } + // Arrange var actingUserKey = Guid.NewGuid(); var mockUser = SetupUserWithGroupAccess(actingUserKey, [Constants.Security.AdminGroupAlias]); var userService = SetupUserServiceWithGetUserByKey(actingUserKey, mockUser); var userGroupRepository = new Mock(); - var userGroupKey = Guid.NewGuid(); var persistedUserGroup = new UserGroup( Mock.Of(), 0, - isSystemGroup ? Constants.Security.AdminGroupAlias : "someNonSystemAlias", + userGroupAlias, "Administrators", null) { From d1506509eaa3d5fdf19cfa14683d3c37e29751ec Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 14:03:23 +0100 Subject: [PATCH 07/15] Update usergroup tests that use aliases for "system" groups --- src/Umbraco.Core/Constants-Security.cs | 18 +++++++++++----- .../Services/ContentServiceTests.cs | 2 +- .../UserGroupServiceValidationTests.cs | 16 ++++++-------- .../Services/UserGroupServiceTests.cs | 21 ++++++------------- 4 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/Umbraco.Core/Constants-Security.cs b/src/Umbraco.Core/Constants-Security.cs index 2f24fa182d4b..df6f26ca1a8f 100644 --- a/src/Umbraco.Core/Constants-Security.cs +++ b/src/Umbraco.Core/Constants-Security.cs @@ -49,27 +49,35 @@ public static class Security /// /// The key of the admin group /// - public static readonly Guid AdminGroupKey = new("E5E7F6C8-7F9C-4B5B-8D5D-9E1E5A4F7E4D"); + public static readonly Guid AdminGroupKey = new(AdminGroupKeyString); + internal const string AdminGroupKeyString = "E5E7F6C8-7F9C-4B5B-8D5D-9E1E5A4F7E4D"; + /// /// The key of the editor group /// - public static readonly Guid EditorGroupKey = new("44DC260E-B4D4-4DD9-9081-EEC5598F1641"); + public static readonly Guid EditorGroupKey = new(EditorGroupKeyString); + internal const string EditorGroupKeyString = "44DC260E-B4D4-4DD9-9081-EEC5598F1641"; + /// /// The key of the sensitive data group /// - public static readonly Guid SensitiveDataGroupKey = new("8C6AD70F-D307-4E4A-AF58-72C2E4E9439D"); + public static readonly Guid SensitiveDataGroupKey = new(SensitiveDataGroupKeyString); + internal const string SensitiveDataGroupKeyString = "8C6AD70F-D307-4E4A-AF58-72C2E4E9439D"; /// /// The key of the translator group /// - public static readonly Guid TranslatorGroupKey = new("F2012E4C-D232-4BD1-8EAE-4384032D97D8"); + public static readonly Guid TranslatorGroupKey = new(TranslatorGroupString); + internal const string TranslatorGroupString = "F2012E4C-D232-4BD1-8EAE-4384032D97D8"; /// /// The key of the writer group /// - public static readonly Guid WriterGroupKey = new("9FC2A16F-528C-46D6-A014-75BF4EC2480C"); + public static readonly Guid WriterGroupKey = new(WriterGroupKeyString); + internal const string WriterGroupKeyString = "9FC2A16F-528C-46D6-A014-75BF4EC2480C"; + public const string BackOfficeAuthenticationType = "UmbracoBackOffice"; public const string BackOfficeExternalAuthenticationType = "UmbracoExternalCookie"; diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs index e31363d08ba9..7767dc8f2eda 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/ContentServiceTests.cs @@ -2073,7 +2073,7 @@ public async Task Can_Empty_RecycleBin_With_Content_That_Has_All_Related_Data() new List { new() { RuleType = "test", RuleValue = "test" } })); Assert.IsTrue(PublicAccessService.AddRule(content1, "test2", "test2").Success); - var user = UserService.GetAsync(Constants.Security.SuperUserKey); + var user = await UserService.GetAsync(Constants.Security.SuperUserKey); var userGroup = UserService.GetUserGroupByAlias(user.Groups.First().Alias); Assert.IsNotNull(NotificationService.CreateNotification(user, content1, "X")); diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserGroupServiceValidationTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserGroupServiceValidationTests.cs index 9d3d8aeee5a5..d14b887b5795 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserGroupServiceValidationTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Core/Services/UserGroupServiceValidationTests.cs @@ -169,11 +169,9 @@ public async Task Can_Update_UserGroup_To_New_Name() Assert.AreEqual(updateName, updatedGroup.Name); } - // these keys are not defined as "const" in Constants.Security but as "static readonly", so we have to hardcode - // them here ("static readonly" can't be used as testcase inputs as they are not constants) - [TestCase("E5E7F6C8-7F9C-4B5B-8D5D-9E1E5A4F7E4D", "admin")] - [TestCase("8C6AD70F-D307-4E4A-AF58-72C2E4E9439D", "sensitiveData")] - [TestCase("F2012E4C-D232-4BD1-8EAE-4384032D97D8", "translator")] + [TestCase(Constants.Security.AdminGroupKeyString, "admin")] + [TestCase(Constants.Security.SensitiveDataGroupKeyString, "sensitiveData")] + [TestCase(Constants.Security.TranslatorGroupString, "translator")] public async Task Cannot_Delete_System_UserGroups(string userGroupKeyAsString, string expectedGroupAlias) { // since we can't use the constants as input, let's make sure we don't get false positives by double checking the group alias @@ -188,10 +186,8 @@ public async Task Cannot_Delete_System_UserGroups(string userGroupKeyAsString, s Assert.AreEqual(UserGroupOperationStatus.CanNotDeleteIsSystemUserGroup, result.Result); } - // these keys are not defined as "const" in Constants.Security but as "static readonly", so we have to hardcode - // them here ("static readonly" can't be used as testcase inputs as they are not constants) - [TestCase("44DC260E-B4D4-4DD9-9081-EEC5598F1641", "editor")] - [TestCase("9FC2A16F-528C-46D6-A014-75BF4EC2480C", "writer")] + [TestCase( Constants.Security.EditorGroupKeyString, "editor")] + [TestCase(Constants.Security.WriterGroupKeyString, "writer")] public async Task Can_Delete_Non_System_UserGroups(string userGroupKeyAsString, string expectedGroupAlias) { // since we can't use the constants as input, let's make sure we don't get false positives by double checking the group alias @@ -203,6 +199,6 @@ public async Task Can_Delete_Non_System_UserGroups(string userGroupKeyAsString, var result = await UserGroupService.DeleteAsync(key); Assert.IsTrue(result.Success); - Assert.AreEqual(UserGroupOperationStatus.Success, result.Result); + Assert.AreEqual(result.Result,UserGroupOperationStatus.Success); } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs index b42a66084b4b..314c38d9bb5f 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Services/UserGroupServiceTests.cs @@ -91,24 +91,15 @@ public async Task Filter_Can_Filter_By_Group_Name() } // Obsoletion will be resolved when they are converted to internal consts. - [TestCase(null, UserGroupOperationStatus.Success)] - [TestCase(Constants.Security.AdminGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] - [TestCase(Constants.Security.SensitiveDataGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] - [TestCase(Constants.Security.TranslatorGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] - public async Task Can_Not_Update_SystemGroup_Alias(string? systemGroupAlias, UserGroupOperationStatus status) + [TestCase(null, null, UserGroupOperationStatus.Success)] + [TestCase(Constants.Security.AdminGroupKeyString, Constants.Security.AdminGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] + [TestCase(Constants.Security.SensitiveDataGroupKeyString, Constants.Security.SensitiveDataGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] + [TestCase(Constants.Security.TranslatorGroupString, Constants.Security.TranslatorGroupAlias, UserGroupOperationStatus.CanNotUpdateAliasIsSystemUserGroup)] + public async Task Can_Not_Update_SystemGroup_Alias(string? systemGroupKey, string? systemGroupAlias, UserGroupOperationStatus status) { // prep var userGroupAlias = systemGroupAlias ?? "someNonSystemAlias"; - Guid userGroupKey = Guid.NewGuid(); - switch (userGroupAlias) - { - case Constants.Security.AdminGroupAlias : userGroupKey = Constants.Security.AdminGroupKey; - break; - case Constants.Security.SensitiveDataGroupAlias : userGroupKey = Constants.Security.SensitiveDataGroupKey; - break; - case Constants.Security.TranslatorGroupAlias : userGroupKey = Constants.Security.TranslatorGroupKey; - break; - } + Guid userGroupKey = systemGroupKey is not null ? new Guid(systemGroupKey) : Guid.NewGuid(); // Arrange var actingUserKey = Guid.NewGuid(); From f1a58f76bde1ff8f2c738ab9ca699adc7dfe18d4 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 14:07:53 +0100 Subject: [PATCH 08/15] Replace more uses of globalsettings.UmbracoPath --- .../Controllers/BackOfficeLoginController.cs | 2 +- src/Umbraco.Core/Services/NotificationService.cs | 4 ++-- src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs | 2 +- src/Umbraco.Web.Common/Mvc/UmbracoMvcConfigureOptions.cs | 2 +- src/Umbraco.Web.Common/Views/UmbracoViewPage.cs | 3 ++- .../Controllers/RenderNoContentController.cs | 3 ++- .../Extensions/HtmlHelperRenderExtensions.cs | 3 ++- .../DependencyInjection/UmbracoBuilderExtensions.cs | 3 ++- .../Umbraco.Core/Configuration/Models/GlobalSettingsTests.cs | 2 +- 9 files changed, 14 insertions(+), 10 deletions(-) diff --git a/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs b/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs index aa8b71125790..c6ff576b93d3 100644 --- a/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs +++ b/src/Umbraco.Cms.Api.Management/Controllers/BackOfficeLoginController.cs @@ -51,7 +51,7 @@ public async Task Index(CancellationToken cancellationToken, Back if (string.IsNullOrEmpty(model.UmbracoUrl)) { - model.UmbracoUrl = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath); + model.UmbracoUrl = _hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath); } if (string.IsNullOrEmpty(model.ReturnUrl)) diff --git a/src/Umbraco.Core/Services/NotificationService.cs b/src/Umbraco.Core/Services/NotificationService.cs index 142738d49f0e..e12183a1a6c5 100644 --- a/src/Umbraco.Core/Services/NotificationService.cs +++ b/src/Umbraco.Core/Services/NotificationService.cs @@ -461,7 +461,7 @@ private NotificationRequest CreateNotificationRequest( var protocol = _globalSettings.UseHttps ? "https" : "http"; var subjectVars = new NotificationEmailSubjectParams( - string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), + string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(Constants.System.DefaultUmbracoPath)), actionName, content.Name); @@ -479,7 +479,7 @@ private NotificationRequest CreateNotificationRequest( string.Concat(content.Id, ".aspx"), protocol), performingUser.Name, - string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(_globalSettings.UmbracoPath)), + string.Concat(siteUri.Authority, _ioHelper.ResolveUrl(Constants.System.DefaultUmbracoPath)), summary.ToString()); var fromMail = _contentSettings.Notifications.Email ?? _globalSettings.Smtp?.From; diff --git a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs index d0f8f7b02b4e..8522ef59c55a 100644 --- a/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs +++ b/src/Umbraco.Web.Common/AspNetCore/AspNetCoreBackOfficeInfo.cs @@ -34,7 +34,7 @@ public string GetAbsoluteUrl _getAbsoluteUrl = WebPath.Combine( _hostingEnvironment.ApplicationMainUrl.ToString(), - _globalSettings.CurrentValue.UmbracoPath.TrimStart(CharArrays.TildeForwardSlash)); + Core.Constants.System.DefaultUmbracoPath.TrimStart(CharArrays.TildeForwardSlash)); } return _getAbsoluteUrl; diff --git a/src/Umbraco.Web.Common/Mvc/UmbracoMvcConfigureOptions.cs b/src/Umbraco.Web.Common/Mvc/UmbracoMvcConfigureOptions.cs index 401e620d4c16..8131a03160e0 100644 --- a/src/Umbraco.Web.Common/Mvc/UmbracoMvcConfigureOptions.cs +++ b/src/Umbraco.Web.Common/Mvc/UmbracoMvcConfigureOptions.cs @@ -32,7 +32,7 @@ public void Configure(MvcOptions options) if (options.Conventions.Any(convention => convention is UmbracoBackofficeToken) is false) { // Replace the BackOfficeToken in routes. - var backofficePath = _globalSettings.UmbracoPath.TrimStart(Core.Constants.CharArrays.TildeForwardSlash); + var backofficePath = Core.Constants.System.DefaultUmbracoPath.TrimStart(Core.Constants.CharArrays.TildeForwardSlash); options.Conventions.Add(new UmbracoBackofficeToken(Core.Constants.Web.AttributeRouting.BackOfficeToken, backofficePath)); } } diff --git a/src/Umbraco.Web.Common/Views/UmbracoViewPage.cs b/src/Umbraco.Web.Common/Views/UmbracoViewPage.cs index f851acab3b34..4fbf5ccde80b 100644 --- a/src/Umbraco.Web.Common/Views/UmbracoViewPage.cs +++ b/src/Umbraco.Web.Common/Views/UmbracoViewPage.cs @@ -7,6 +7,7 @@ using Microsoft.AspNetCore.Razor.TagHelpers; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Models; @@ -140,7 +141,7 @@ public void WriteUmbracoContent(TagHelperOutput tagHelperOutput) markupToInject = string.Format( ContentSettings.PreviewBadge, - HostingEnvironment.ToAbsolute(GlobalSettings.UmbracoPath), + HostingEnvironment.ToAbsolute(Core.Constants.System.DefaultUmbracoPath), Context.Request.GetEncodedUrl(), UmbracoContext.PublishedRequest?.PublishedContent?.Key); } diff --git a/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs b/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs index 06b6d4a8186e..92d1c67ba2a2 100644 --- a/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs +++ b/src/Umbraco.Web.Website/Controllers/RenderNoContentController.cs @@ -1,6 +1,7 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Options; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Hosting; @@ -49,7 +50,7 @@ public ActionResult Index() return Redirect("~/"); } - var model = new NoNodesViewModel { UmbracoPath = _hostingEnvironment.ToAbsolute(_globalSettings.UmbracoPath) }; + var model = new NoNodesViewModel { UmbracoPath = _hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath) }; return View(_globalSettings.NoNodesViewPath, model); } diff --git a/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs b/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs index 3b3a95df2d21..654620322979 100644 --- a/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs +++ b/src/Umbraco.Web.Website/Extensions/HtmlHelperRenderExtensions.cs @@ -10,6 +10,7 @@ using Microsoft.AspNetCore.Mvc.ViewFeatures; using Microsoft.AspNetCore.Routing; using Microsoft.Extensions.DependencyInjection; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Hosting; @@ -85,7 +86,7 @@ public static IHtmlContent PreviewBadge( var htmlBadge = string.Format( contentSettings.PreviewBadge, - hostingEnvironment.ToAbsolute(globalSettings.UmbracoPath), + hostingEnvironment.ToAbsolute(Constants.System.DefaultUmbracoPath), WebUtility.UrlEncode(httpContextAccessor.GetRequiredHttpContext().Request.Path), umbracoContext.PublishedRequest?.PublishedContent?.Key); return new HtmlString(htmlBadge); diff --git a/tests/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs b/tests/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs index 732fc0a38584..e08a72a8a674 100644 --- a/tests/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs +++ b/tests/Umbraco.Tests.Integration/DependencyInjection/UmbracoBuilderExtensions.cs @@ -10,6 +10,7 @@ using Microsoft.Extensions.Options; using Moq; using NUnit.Framework; +using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Composing; using Umbraco.Cms.Core.Configuration.Models; @@ -129,7 +130,7 @@ private static ILocalizedTextService GetLocalizedTextService(IServiceProvider fa uiProject.Create(); } - var mainLangFolder = new DirectoryInfo(Path.Combine(uiProject.FullName, globalSettings.Value.UmbracoPath.TrimStartExact("~/"), "config", "lang")); + var mainLangFolder = new DirectoryInfo(Path.Combine(uiProject.FullName, Constants.System.DefaultUmbracoPath.TrimStartExact("~/"), "config", "lang")); return new LocalizedTextServiceFileSources( loggerFactory.CreateLogger(), diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/GlobalSettingsTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/GlobalSettingsTests.cs index ca38c928f810..fbf1ea75ca20 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/GlobalSettingsTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Configuration/Models/GlobalSettingsTests.cs @@ -28,7 +28,7 @@ public void Umbraco_Mvc_Area( { hostingSettings.CurrentValue.ApplicationVirtualPath = rootPath; - var globalSettings = new GlobalSettings { UmbracoPath = path }; + var globalSettings = new GlobalSettings(); Assert.AreEqual(outcome, globalSettings.GetUmbracoMvcAreaNoCache(hostingEnvironment)); } From bfb56e3b0ccfe670d7b6029f7a0cb1e9ce7e2a74 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 14:11:22 +0100 Subject: [PATCH 09/15] Remove GetDateType by key non async --- src/Umbraco.Core/Cache/DataTypeConfigurationCache.cs | 2 +- src/Umbraco.Core/Services/DataTypeService.cs | 9 --------- src/Umbraco.Core/Services/DateTypeServiceExtensions.cs | 2 +- src/Umbraco.Core/Services/IDataTypeService.cs | 10 ---------- .../Packaging/PackageDataInstallation.cs | 4 ++-- 5 files changed, 4 insertions(+), 23 deletions(-) diff --git a/src/Umbraco.Core/Cache/DataTypeConfigurationCache.cs b/src/Umbraco.Core/Cache/DataTypeConfigurationCache.cs index 78ee17d2f819..70c9b4161be9 100644 --- a/src/Umbraco.Core/Cache/DataTypeConfigurationCache.cs +++ b/src/Umbraco.Core/Cache/DataTypeConfigurationCache.cs @@ -26,7 +26,7 @@ public DataTypeConfigurationCache(IDataTypeService dataTypeService, IMemoryCache var cacheKey = GetCacheKey(key); if (_memoryCache.TryGetValue(cacheKey, out T? configuration) is false) { - IDataType? dataType = _dataTypeService.GetDataType(key); + IDataType? dataType = _dataTypeService.GetAsync(key).GetAwaiter().GetResult(); configuration = dataType?.ConfigurationAs(); // Only cache if data type was found (but still cache null configurations) diff --git a/src/Umbraco.Core/Services/DataTypeService.cs b/src/Umbraco.Core/Services/DataTypeService.cs index 7797a300159a..f22948968a56 100644 --- a/src/Umbraco.Core/Services/DataTypeService.cs +++ b/src/Umbraco.Core/Services/DataTypeService.cs @@ -292,15 +292,6 @@ public Task> FilterAsync(string? name = null, string? edit return dataType; } - /// - /// Gets a by its unique guid Id - /// - /// Unique guid Id of the DataType - /// - [Obsolete("Please use GetAsync. Will be removed in V15.")] - public IDataType? GetDataType(Guid id) - => GetAsync(id).GetAwaiter().GetResult(); - /// public Task GetAsync(Guid id) { diff --git a/src/Umbraco.Core/Services/DateTypeServiceExtensions.cs b/src/Umbraco.Core/Services/DateTypeServiceExtensions.cs index c330a037720e..ac7e8550b2c6 100644 --- a/src/Umbraco.Core/Services/DateTypeServiceExtensions.cs +++ b/src/Umbraco.Core/Services/DateTypeServiceExtensions.cs @@ -13,7 +13,7 @@ public static bool IsDataTypeIgnoringUserStartNodes(this IDataTypeService dataTy return false; // built in ones can never be ignoring start nodes } - IDataType? dataType = dataTypeService.GetDataType(key); + IDataType? dataType = dataTypeService.GetAsync(key).GetAwaiter().GetResult(); if (dataType != null && dataType.ConfigurationObject is IIgnoreUserStartNodesConfig ignoreStartNodesConfig) { diff --git a/src/Umbraco.Core/Services/IDataTypeService.cs b/src/Umbraco.Core/Services/IDataTypeService.cs index e2f808cc7ee9..3a4576552c2f 100644 --- a/src/Umbraco.Core/Services/IDataTypeService.cs +++ b/src/Umbraco.Core/Services/IDataTypeService.cs @@ -76,16 +76,6 @@ public interface IDataTypeService : IService [Obsolete("Please use GetAsync. Will be removed in V15.")] IDataType? GetDataType(int id); - /// - /// Gets a by its unique guid Id - /// - /// Unique guid Id of the DataType - /// - /// - /// - [Obsolete("Please use GetAsync. Will be removed in V15.")] - IDataType? GetDataType(Guid id); - /// /// Gets an by its Name /// diff --git a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs index 4b0ab56f6771..c91ae5f3bd26 100644 --- a/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs +++ b/src/Umbraco.Infrastructure/Packaging/PackageDataInstallation.cs @@ -1093,7 +1093,7 @@ private void UpdateContentTypesProperties(T contentType, XElement? genericPro var dataTypeDefinitionId = new Guid(property.Element("Definition")!.Value); //Unique Id for a DataTypeDefinition - IDataType? dataTypeDefinition = _dataTypeService.GetDataType(dataTypeDefinitionId); + IDataType? dataTypeDefinition = _dataTypeService.GetAsync(dataTypeDefinitionId).GetAwaiter().GetResult(); //If no DataTypeDefinition with the guid from the xml wasn't found OR the ControlId on the DataTypeDefinition didn't match the DataType Id //We look up a DataTypeDefinition that matches @@ -1285,7 +1285,7 @@ public IReadOnlyList ImportDataTypes(IReadOnlyCollection da parentId = importedFolders[dataTypeDefinitionName]; } - IDataType? definition = _dataTypeService.GetDataType(dataTypeDefinitionId); + IDataType? definition = _dataTypeService.GetAsync(dataTypeDefinitionId).GetAwaiter().GetResult(); //If the datatype definition doesn't already exist we create a new according to the one in the package xml if (definition == null) { From 187388e4c72a89cefa01c064a158c46748141d32 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 14:20:18 +0100 Subject: [PATCH 10/15] Cleanup some usages of hostingEnvironment.MapPathContentRoot --- .../ModelsBuilderConfigExtensions.cs | 20 +++++- .../ModelsBuilder/Building/ModelsGenerator.cs | 35 ++++++++-- .../ModelsBuilder/ModelsGenerationError.cs | 33 ++++++++-- .../ModelsBuilder/OutOfDateModelsStatus.cs | 28 ++++++-- .../InMemoryAuto/InMemoryModelFactory.cs | 64 +++++++++++++++++-- 5 files changed, 163 insertions(+), 17 deletions(-) diff --git a/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs b/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs index 294040f41411..0ade116444ea 100644 --- a/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs +++ b/src/Umbraco.Core/Configuration/ModelsBuilderConfigExtensions.cs @@ -1,6 +1,8 @@ +using Microsoft.Extensions.Hosting; using Umbraco.Cms.Core.Configuration.Models; using Umbraco.Cms.Core.Exceptions; -using Umbraco.Cms.Core.Hosting; +using Umbraco.Cms.Core.Extensions; +using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Extensions; @@ -8,6 +10,22 @@ public static class ModelsBuilderConfigExtensions { private static string? _modelsDirectoryAbsolute; + public static string ModelsDirectoryAbsolute( + this ModelsBuilderSettings modelsBuilderConfig, + IHostEnvironment hostEnvironment) + { + if (_modelsDirectoryAbsolute is null) + { + var modelsDirectory = modelsBuilderConfig.ModelsDirectory; + var root = hostEnvironment.MapPathContentRoot("~/"); + + _modelsDirectoryAbsolute = GetModelsDirectory(root, modelsDirectory, modelsBuilderConfig.AcceptUnsafeModelsDirectory); + } + + return _modelsDirectoryAbsolute; + } + + [Obsolete("Use the non obsoleted equivalent instead. Scheduled for removal in v16")] public static string ModelsDirectoryAbsolute( this ModelsBuilderSettings modelsBuilderConfig, IHostingEnvironment hostingEnvironment) diff --git a/src/Umbraco.Infrastructure/ModelsBuilder/Building/ModelsGenerator.cs b/src/Umbraco.Infrastructure/ModelsBuilder/Building/ModelsGenerator.cs index 0a668f2d4585..408d89d143d8 100644 --- a/src/Umbraco.Infrastructure/ModelsBuilder/Building/ModelsGenerator.cs +++ b/src/Umbraco.Infrastructure/ModelsBuilder/Building/ModelsGenerator.cs @@ -1,31 +1,58 @@ using System.Text; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Hosting; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Extensions; +using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Cms.Infrastructure.ModelsBuilder.Building; public class ModelsGenerator : IModelsGenerator { - private readonly IHostingEnvironment _hostingEnvironment; private readonly OutOfDateModelsStatus _outOfDateModels; + private readonly IHostEnvironment _hostEnvironment; private readonly UmbracoServices _umbracoService; private ModelsBuilderSettings _config; + [Obsolete("Use a not obsoleted constructor instead. Scheduled for removal in v16")] public ModelsGenerator(UmbracoServices umbracoService, IOptionsMonitor config, OutOfDateModelsStatus outOfDateModels, IHostingEnvironment hostingEnvironment) { _umbracoService = umbracoService; _config = config.CurrentValue; _outOfDateModels = outOfDateModels; - _hostingEnvironment = hostingEnvironment; + config.OnChange(x => _config = x); + + _hostEnvironment = StaticServiceProvider.Instance.GetRequiredService(); + } + + [Obsolete("Use a not obsoleted constructor instead. Scheduled for removal in v16")] + public ModelsGenerator(UmbracoServices umbracoService, IOptionsMonitor config, + OutOfDateModelsStatus outOfDateModels, IHostingEnvironment hostingEnvironment, IHostEnvironment hostEnvironment) + { + _umbracoService = umbracoService; + _config = config.CurrentValue; + _outOfDateModels = outOfDateModels; + config.OnChange(x => _config = x); + + _hostEnvironment = hostEnvironment; + } + + public ModelsGenerator(UmbracoServices umbracoService, IOptionsMonitor config, + OutOfDateModelsStatus outOfDateModels, IHostEnvironment hostEnvironment) + { + _umbracoService = umbracoService; + _config = config.CurrentValue; + _outOfDateModels = outOfDateModels; + _hostEnvironment = hostEnvironment; config.OnChange(x => _config = x); } public void GenerateModels() { - var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment); + var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostEnvironment); if (!Directory.Exists(modelsDirectory)) { Directory.CreateDirectory(modelsDirectory); diff --git a/src/Umbraco.Infrastructure/ModelsBuilder/ModelsGenerationError.cs b/src/Umbraco.Infrastructure/ModelsBuilder/ModelsGenerationError.cs index 02db02afda02..e7ee821875ca 100644 --- a/src/Umbraco.Infrastructure/ModelsBuilder/ModelsGenerationError.cs +++ b/src/Umbraco.Infrastructure/ModelsBuilder/ModelsGenerationError.cs @@ -1,23 +1,48 @@ using System.Text; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Hosting; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Extensions; +using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Cms.Infrastructure.ModelsBuilder; public sealed class ModelsGenerationError { - private readonly IHostingEnvironment _hostingEnvironment; + private readonly IHostEnvironment _hostEnvironment; private ModelsBuilderSettings _config; /// /// Initializes a new instance of the class. /// + [Obsolete("Use a not obsoleted constructor instead. Scheduled for removal in v16")] public ModelsGenerationError(IOptionsMonitor config, IHostingEnvironment hostingEnvironment) { _config = config.CurrentValue; - _hostingEnvironment = hostingEnvironment; + config.OnChange(x => _config = x); + _hostEnvironment = StaticServiceProvider.Instance.GetRequiredService(); + } + + /// + /// Initializes a new instance of the class. + /// + [Obsolete("Use a not obsoleted constructor instead. Scheduled for removal in v16")] + public ModelsGenerationError( + IOptionsMonitor config, + IHostingEnvironment hostingEnvironment, + IHostEnvironment hostEnvironment) + { + _config = config.CurrentValue; + config.OnChange(x => _config = x); + _hostEnvironment = hostEnvironment; + } + + public ModelsGenerationError(IOptionsMonitor config, IHostEnvironment hostEnvironment) + { + _config = config.CurrentValue; + _hostEnvironment = hostEnvironment; config.OnChange(x => _config = x); } @@ -73,7 +98,7 @@ public void Report(string message, Exception e) private string? GetErrFile() { - var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment); + var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostEnvironment); if (!Directory.Exists(modelsDirectory)) { return null; diff --git a/src/Umbraco.Infrastructure/ModelsBuilder/OutOfDateModelsStatus.cs b/src/Umbraco.Infrastructure/ModelsBuilder/OutOfDateModelsStatus.cs index 4336f8ec7165..e0f4ce5ba0d4 100644 --- a/src/Umbraco.Infrastructure/ModelsBuilder/OutOfDateModelsStatus.cs +++ b/src/Umbraco.Infrastructure/ModelsBuilder/OutOfDateModelsStatus.cs @@ -1,9 +1,12 @@ +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Options; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; using Umbraco.Cms.Core.Events; -using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Notifications; using Umbraco.Extensions; +using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Cms.Infrastructure.ModelsBuilder; @@ -13,8 +16,8 @@ namespace Umbraco.Cms.Infrastructure.ModelsBuilder; public sealed class OutOfDateModelsStatus : INotificationHandler, INotificationHandler { - private readonly IHostingEnvironment _hostingEnvironment; private ModelsBuilderSettings _config; + private readonly IHostEnvironment _hostEnvironment; /// /// Initializes a new instance of the class. @@ -22,7 +25,24 @@ public sealed class OutOfDateModelsStatus : INotificationHandler config, IHostingEnvironment hostingEnvironment) { _config = config.CurrentValue; - _hostingEnvironment = hostingEnvironment; + _hostEnvironment = StaticServiceProvider.Instance.GetRequiredService(); + config.OnChange(x => _config = x); + } + + public OutOfDateModelsStatus( + IOptionsMonitor config, + IHostingEnvironment hostingEnvironment, + IHostEnvironment hostEnvironment) + { + _config = config.CurrentValue; + _hostEnvironment = hostEnvironment; + config.OnChange(x => _config = x); + } + + public OutOfDateModelsStatus(IOptionsMonitor config, IHostEnvironment hostEnvironment) + { + _config = config.CurrentValue; + _hostEnvironment = hostEnvironment; config.OnChange(x => _config = x); } @@ -70,7 +90,7 @@ public void Clear() private string GetFlagPath() { - var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostingEnvironment); + var modelsDirectory = _config.ModelsDirectoryAbsolute(_hostEnvironment); if (!Directory.Exists(modelsDirectory)) { Directory.CreateDirectory(modelsDirectory); diff --git a/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs b/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs index 1da1b32a22f3..fe2718595ccb 100644 --- a/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs +++ b/src/Umbraco.Web.Common/ModelsBuilder/InMemoryAuto/InMemoryModelFactory.cs @@ -5,11 +5,15 @@ using System.Text; using System.Text.RegularExpressions; using Microsoft.AspNetCore.Mvc.Razor; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Configuration; using Umbraco.Cms.Core.Configuration.Models; +using Umbraco.Cms.Core.DependencyInjection; +using Umbraco.Cms.Core.Extensions; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Models.PublishedContent; @@ -17,6 +21,7 @@ using Umbraco.Cms.Infrastructure.ModelsBuilder.Building; using Umbraco.Extensions; using File = System.IO.File; +using IHostingEnvironment = Umbraco.Cms.Core.Hosting.IHostingEnvironment; namespace Umbraco.Cms.Web.Common.ModelsBuilder.InMemoryAuto { @@ -31,7 +36,7 @@ internal class InMemoryModelFactory : IAutoPublishedModelFactory, IRegisteredObj private readonly ILogger _logger; private readonly FileSystemWatcher? _watcher; private readonly Lazy _umbracoServices; // TODO: this is because of circular refs :( - private readonly IHostingEnvironment _hostingEnvironment; + private readonly IHostEnvironment _hostEnvironment; private readonly IApplicationShutdownRegistry _hostingLifetime; private readonly ModelsGenerationError _errors; private readonly IPublishedValueFallback _publishedValueFallback; @@ -48,6 +53,7 @@ internal class InMemoryModelFactory : IAutoPublishedModelFactory, IRegisteredObj private ModelsBuilderSettings _config; private bool _disposedValue; + [Obsolete("Use a not obsoleted constructor instead. Scheduled for removal in v16")] public InMemoryModelFactory( Lazy umbracoServices, IProfilingLogger profilingLogger, @@ -63,12 +69,62 @@ public InMemoryModelFactory( _profilingLogger = profilingLogger; _logger = logger; _config = config.CurrentValue; - _hostingEnvironment = hostingEnvironment; + _hostEnvironment = StaticServiceProvider.Instance.GetRequiredService(); _hostingLifetime = hostingLifetime; _publishedValueFallback = publishedValueFallback; _loadContextManager = loadContextManager; _runtimeCompilationCacheBuster = runtimeCompilationCacheBuster; - _errors = new ModelsGenerationError(config, _hostingEnvironment); + _errors = new ModelsGenerationError(config, _hostEnvironment); + _ver = 1; // zero is for when we had no version + _skipver = -1; // nothing to skip + + if (!hostingEnvironment.IsHosted) + { + return; + } + + config.OnChange(x => _config = x); + _pureLiveDirectory = new Lazy(PureLiveDirectoryAbsolute); + + if (!Directory.Exists(_pureLiveDirectory.Value)) + { + Directory.CreateDirectory(_pureLiveDirectory.Value); + } + + // BEWARE! if the watcher is not properly released then for some reason the + // BuildManager will start confusing types - using a 'registered object' here + // though we should probably plug into Umbraco's MainDom - which is internal + _hostingLifetime.RegisterObject(this); + _watcher = new FileSystemWatcher(_pureLiveDirectory.Value); + _watcher.Changed += WatcherOnChanged; + _watcher.EnableRaisingEvents = true; + + // get it here, this need to be fast + _debugLevel = _config.DebugLevel; + } + + public InMemoryModelFactory( + Lazy umbracoServices, + IProfilingLogger profilingLogger, + ILogger logger, + IOptionsMonitor config, + IHostingEnvironment hostingEnvironment, + IHostEnvironment hostEnvironment, + IApplicationShutdownRegistry hostingLifetime, + IPublishedValueFallback publishedValueFallback, + InMemoryAssemblyLoadContextManager loadContextManager, + RuntimeCompilationCacheBuster runtimeCompilationCacheBuster) + { + _umbracoServices = umbracoServices; + _profilingLogger = profilingLogger; + _logger = logger; + _config = config.CurrentValue; + _hostEnvironment = hostEnvironment; + _hostingLifetime = hostingLifetime; + _publishedValueFallback = publishedValueFallback; + _loadContextManager = loadContextManager; + _runtimeCompilationCacheBuster = runtimeCompilationCacheBuster; + _errors = new ModelsGenerationError(config, _hostEnvironment); _ver = 1; // zero is for when we had no version _skipver = -1; // nothing to skip @@ -359,7 +415,7 @@ internal Infos EnsureModels() } } - public string PureLiveDirectoryAbsolute() => _hostingEnvironment.MapPathContentRoot(Core.Constants.SystemDirectories.TempData + "/InMemoryAuto"); + public string PureLiveDirectoryAbsolute() => _hostEnvironment.MapPathContentRoot(Core.Constants.SystemDirectories.TempData + "/InMemoryAuto"); // This is NOT thread safe but it is only called from within a lock private Assembly ReloadAssembly(string pathToAssembly) From cee72a317ae51159e67ff47ff5f56b7cf9b2ad31 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 14:39:28 +0100 Subject: [PATCH 11/15] More easy obsoletion cleanup --- ...ckOfficeAuthBuilderOpenIddictExtensions.cs | 20 ----- ...mbracoEFCoreServiceCollectionExtensions.cs | 61 --------------- src/Umbraco.Core/Actions/ActionToPublish.cs | 35 --------- .../Implement/ContentCacheRefresher.cs | 10 --- .../Events/UserNotificationsHandler.cs | 5 -- .../UmbracoBuilder.CoreServices.cs | 1 - .../Migrations/Install/DatabaseDataCreator.cs | 1 - .../Umbraco.Core/Components/ComponentTests.cs | 78 +------------------ 8 files changed, 1 insertion(+), 210 deletions(-) delete mode 100644 src/Umbraco.Cms.Persistence.EFCore/Extensions/BackOfficeAuthBuilderOpenIddictExtensions.cs delete mode 100644 src/Umbraco.Core/Actions/ActionToPublish.cs diff --git a/src/Umbraco.Cms.Persistence.EFCore/Extensions/BackOfficeAuthBuilderOpenIddictExtensions.cs b/src/Umbraco.Cms.Persistence.EFCore/Extensions/BackOfficeAuthBuilderOpenIddictExtensions.cs deleted file mode 100644 index 376453798857..000000000000 --- a/src/Umbraco.Cms.Persistence.EFCore/Extensions/BackOfficeAuthBuilderOpenIddictExtensions.cs +++ /dev/null @@ -1,20 +0,0 @@ -using Microsoft.EntityFrameworkCore; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Persistence.EFCore; - -namespace Umbraco.Extensions; - -public static class BackOfficeAuthBuilderOpenIddictExtensions -{ - [Obsolete("This is no longer used and will be removed in V15. Instead use the overload that specifies the DbContext type.")] - public static IUmbracoBuilder AddUmbracoEFCoreDbContext(this IUmbracoBuilder builder) - { - builder.Services.AddUmbracoEFCoreContext((options, connectionString, providerName) => - { - // Register the entity sets needed by OpenIddict. - options.UseOpenIddict(); - }); - - return builder; - } -} diff --git a/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs b/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs index 7694f83dd2e6..d7da8a65fe8c 100644 --- a/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs +++ b/src/Umbraco.Cms.Persistence.EFCore/Extensions/UmbracoEFCoreServiceCollectionExtensions.cs @@ -14,45 +14,6 @@ public static class UmbracoEFCoreServiceCollectionExtensions { public delegate void DefaultEFCoreOptionsAction(DbContextOptionsBuilder options, string? providerName, string? connectionString); - [Obsolete("Use AddUmbracoDbContext(this IServiceCollection services, Action? optionsAction = null) instead.")] - public static IServiceCollection AddUmbracoEFCoreContext(this IServiceCollection services, DefaultEFCoreOptionsAction? defaultEFCoreOptionsAction = null) - where T : DbContext - { - services.AddPooledDbContextFactory((provider, builder) => SetupDbContext(defaultEFCoreOptionsAction, provider, builder)); - services.AddTransient(services => services.GetRequiredService>().CreateDbContext()); - - services.AddUnique, AmbientEFCoreScopeStack>(); - services.AddUnique, EFCoreScopeAccessor>(); - services.AddUnique, EFCoreScopeProvider>(); - services.AddSingleton>(); - services.AddSingleton>(); - - return services; - } - - [Obsolete("Use AddUmbracoDbContext(this IServiceCollection services, Action? optionsAction = null) instead.")] - public static IServiceCollection AddUmbracoEFCoreContext(this IServiceCollection services, string connectionString, string providerName, DefaultEFCoreOptionsAction? defaultEFCoreOptionsAction = null) - where T : DbContext - { - // Replace data directory - string? dataDirectory = AppDomain.CurrentDomain.GetData(Constants.System.DataDirectoryName)?.ToString(); - if (string.IsNullOrEmpty(dataDirectory) is false) - { - connectionString = connectionString.Replace(Constants.System.DataDirectoryPlaceholder, dataDirectory); - } - - services.AddPooledDbContextFactory(options => defaultEFCoreOptionsAction?.Invoke(options, providerName, connectionString)); - services.AddTransient(services => services.GetRequiredService>().CreateDbContext()); - - services.AddUnique, AmbientEFCoreScopeStack>(); - services.AddUnique, EFCoreScopeAccessor>(); - services.AddUnique, EFCoreScopeProvider>(); - services.AddSingleton>(); - services.AddSingleton>(); - - return services; - } - /// /// Adds a EFCore DbContext with all the services needed to integrate with Umbraco scopes. /// @@ -149,26 +110,4 @@ public static void UseUmbracoDatabaseProvider(this DbContextOptionsBuilder build builder.UseDatabaseProvider(connectionStrings.ProviderName, connectionStrings.ConnectionString); } - - [Obsolete] - private static void SetupDbContext(DefaultEFCoreOptionsAction? defaultEFCoreOptionsAction, IServiceProvider provider, DbContextOptionsBuilder builder) - { - ConnectionStrings connectionStrings = GetConnectionStringAndProviderName(provider); - defaultEFCoreOptionsAction?.Invoke(builder, connectionStrings.ConnectionString, connectionStrings.ProviderName); - } - - [Obsolete] - private static ConnectionStrings GetConnectionStringAndProviderName(IServiceProvider serviceProvider) - { - ConnectionStrings connectionStrings = serviceProvider.GetRequiredService>().CurrentValue; - - // Replace data directory - string? dataDirectory = AppDomain.CurrentDomain.GetData(Constants.System.DataDirectoryName)?.ToString(); - if (string.IsNullOrEmpty(dataDirectory) is false) - { - connectionStrings.ConnectionString = connectionStrings.ConnectionString?.Replace(Constants.System.DataDirectoryPlaceholder, dataDirectory); - } - - return connectionStrings; - } } diff --git a/src/Umbraco.Core/Actions/ActionToPublish.cs b/src/Umbraco.Core/Actions/ActionToPublish.cs deleted file mode 100644 index a980d819aa8a..000000000000 --- a/src/Umbraco.Core/Actions/ActionToPublish.cs +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -namespace Umbraco.Cms.Core.Actions; - -/// -/// This action is invoked when children to a document is being sent to published (by an editor without publishrights). -/// -[Obsolete("Scheduled for removal in v13")] -public class ActionToPublish : IAction -{ - /// - public const string ActionLetter = "Umb.Document.SendForApproval"; - - /// - public const string ActionAlias = "sendtopublish"; - - /// - public string Letter => ActionLetter; - - /// - public string Alias => ActionAlias; - - /// - public string Category => Constants.Conventions.PermissionCategories.ContentCategory; - - /// - public string Icon => "icon-outbox"; - - /// - public bool ShowInNotifier => true; - - /// - public bool CanBePermissionAssigned => true; -} diff --git a/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs b/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs index cc224186aacf..759e724c88ea 100644 --- a/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs +++ b/src/Umbraco.Core/Cache/Refreshers/Implement/ContentCacheRefresher.cs @@ -367,16 +367,6 @@ private void HandleRouting(JsonPayload payload) // TODO (V14): Change into a record public class JsonPayload { - public JsonPayload() - { } - - [Obsolete("Use the default constructor and property initializers.")] - public JsonPayload(int id, Guid? key, TreeChangeTypes changeTypes) - { - Id = id; - Key = key; - ChangeTypes = changeTypes; - } public int Id { get; init; } diff --git a/src/Umbraco.Core/Events/UserNotificationsHandler.cs b/src/Umbraco.Core/Events/UserNotificationsHandler.cs index ebc7840fa1df..6356046963a0 100644 --- a/src/Umbraco.Core/Events/UserNotificationsHandler.cs +++ b/src/Umbraco.Core/Events/UserNotificationsHandler.cs @@ -25,7 +25,6 @@ public sealed class UserNotificationsHandler : INotificationHandler, INotificationHandler, INotificationHandler, - INotificationHandler, INotificationHandler, INotificationHandler, INotificationHandler @@ -107,10 +106,6 @@ public void Handle(ContentSavedNotification notification) _notifier.Notify(_actions.GetAction(), updatedEntities.ToArray()); } - [Obsolete("Scheduled for removal in v13")] - public void Handle(ContentSentToPublishNotification notification) => - _notifier.Notify(_actions.GetAction(), notification.Entity); - public void Handle(ContentSortedNotification notification) { var parentId = notification.SortedEntities.Select(x => x.ParentId).Distinct().ToList(); diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index a7a71d33000f..1f8647c41038 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -321,7 +321,6 @@ public static IUmbracoBuilder AddCoreNotifications(this IUmbracoBuilder builder) .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() - .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler() .AddNotificationHandler(); diff --git a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs index d9eefbe76f29..eac8aca1b550 100644 --- a/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs +++ b/src/Umbraco.Infrastructure/Migrations/Install/DatabaseDataCreator.cs @@ -196,7 +196,6 @@ private void CreateUserGroup2PermissionData() var userGroupKeyToPermissions = new Dictionary>() { [Constants.Security.AdminGroupKey] = new[] { ActionNew.ActionLetter, ActionUpdate.ActionLetter, ActionDelete.ActionLetter, ActionMove.ActionLetter, ActionCopy.ActionLetter, ActionSort.ActionLetter, ActionRollback.ActionLetter, ActionProtect.ActionLetter, ActionAssignDomain.ActionLetter, ActionPublish.ActionLetter, ActionRights.ActionLetter, ActionUnpublish.ActionLetter, ActionBrowse.ActionLetter, ActionCreateBlueprintFromContent.ActionLetter, ActionNotify.ActionLetter, ":", "5", "7", "T" }, - [Constants.Security.WriterGroupKey] = new[] { ActionNew.ActionLetter, ActionUpdate.ActionLetter, ActionToPublish.ActionLetter, ActionBrowse.ActionLetter, ActionNotify.ActionLetter, ":" }, [Constants.Security.EditorGroupKey] = new[] { ActionNew.ActionLetter, ActionUpdate.ActionLetter, ActionDelete.ActionLetter, ActionMove.ActionLetter, ActionCopy.ActionLetter, ActionSort.ActionLetter, ActionRollback.ActionLetter, ActionProtect.ActionLetter, ActionPublish.ActionLetter, ActionUnpublish.ActionLetter, ActionBrowse.ActionLetter, ActionCreateBlueprintFromContent.ActionLetter, ActionNotify.ActionLetter, ":", "5", "T" }, [Constants.Security.TranslatorGroupKey] = new[] { ActionUpdate.ActionLetter, ActionBrowse.ActionLetter }, }; diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs index 94bff4a0c904..25bdb0bec740 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs @@ -140,16 +140,6 @@ public async Task Boot1A() return new Composer1(); } - if (type == typeof(Composer5)) - { - return new Composer5(); - } - - if (type == typeof(Component5)) - { - return new Component5(new SomeResource()); - } - if (type == typeof(IProfilingLogger)) { return new ProfilingLogger(Mock.Of>(), Mock.Of()); @@ -297,26 +287,6 @@ public async Task Initialize() return new Composer1(); } - if (type == typeof(Composer5)) - { - return new Composer5(); - } - - if (type == typeof(Composer5a)) - { - return new Composer5a(); - } - - if (type == typeof(Component5)) - { - return new Component5(new SomeResource()); - } - - if (type == typeof(Component5a)) - { - return new Component5a(); - } - if (type == typeof(IProfilingLogger)) { return new ProfilingLogger(Mock.Of>(), Mock.Of()); @@ -337,24 +307,15 @@ public async Task Initialize() }); var composition = new UmbracoBuilder(register, Mock.Of(), TestHelper.GetMockedTypeLoader()); - Type[] types = { typeof(Composer1), typeof(Composer5), typeof(Composer5a) }; + Type[] types = { typeof(Composer1) }; var composers = new ComposerGraph(composition, types, Enumerable.Empty(), Mock.Of>()); Assert.IsEmpty(Composed); composers.Compose(); - AssertTypeArray(TypeArray(), Composed); var builder = composition.WithCollectionBuilder(); builder.RegisterWith(register); var components = builder.CreateCollection(factory); - - Assert.IsEmpty(Initialized); - await components.InitializeAsync(false, default); - AssertTypeArray(TypeArray(), Initialized); - - Assert.IsEmpty(Terminated); - await components.TerminateAsync(false, default); - AssertTypeArray(TypeArray(), Terminated); } [Test] @@ -537,43 +498,6 @@ public class Composer4 : TestComposerBase { } - public class Composer5 : TestComposerBase - { - public override void Compose(IUmbracoBuilder builder) - { - base.Compose(builder); - builder.Components().Append(); - } - } - - [ComposeAfter(typeof(Composer5))] - public class Composer5a : TestComposerBase - { - public override void Compose(IUmbracoBuilder builder) - { - base.Compose(builder); - builder.Components().Append(); - } - } - - public class TestComponentBase : IComponent - { - public virtual void Initialize() => Initialized.Add(GetType()); - - public virtual void Terminate() => Terminated.Add(GetType()); - } - - public class Component5 : TestComponentBase - { - private readonly ISomeResource _resource; - - public Component5(ISomeResource resource) => _resource = resource; - } - - public class Component5a : TestComponentBase - { - } - [Disable] public class Composer6 : TestComposerBase { From a4186d2e78342fb1c8a8ee0621bebb6117b86b90 Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 15:48:29 +0100 Subject: [PATCH 12/15] Small Typeload cleanup --- src/Umbraco.Core/Composing/TypeLoader.cs | 73 ------------------- tests/Umbraco.Tests.Common/TestHelperBase.cs | 7 +- .../DbContext/CustomDbContextTests.cs | 31 -------- .../Umbraco.Core/Components/ComponentTests.cs | 12 +-- .../Composing/ComposingTestBase.cs | 5 -- .../Umbraco.Core/Composing/TypeLoaderTests.cs | 6 -- 6 files changed, 3 insertions(+), 131 deletions(-) diff --git a/src/Umbraco.Core/Composing/TypeLoader.cs b/src/Umbraco.Core/Composing/TypeLoader.cs index 9fc692f778cd..3920e3d38274 100644 --- a/src/Umbraco.Core/Composing/TypeLoader.cs +++ b/src/Umbraco.Core/Composing/TypeLoader.cs @@ -27,39 +27,6 @@ public sealed class TypeLoader private IEnumerable? _assemblies; - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Please use an alternative constructor.")] - public TypeLoader( - ITypeFinder typeFinder, - IRuntimeHash runtimeHash, - IAppPolicyCache runtimeCache, - DirectoryInfo localTempPath, - ILogger logger, - IProfiler profiler, - IEnumerable? assembliesToScan = null) - : this(typeFinder, logger, assembliesToScan) - { - } - - /// - /// Initializes a new instance of the class. - /// - [Obsolete("Please use an alternative constructor.")] - public TypeLoader( - ITypeFinder typeFinder, - IRuntimeHash runtimeHash, - IAppPolicyCache runtimeCache, - DirectoryInfo localTempPath, - ILogger logger, - IProfiler profiler, - bool detectChanges, - IEnumerable? assembliesToScan = null) - : this(typeFinder, logger, assembliesToScan) - { - } - public TypeLoader( ITypeFinder typeFinder, ILogger logger, @@ -100,18 +67,6 @@ public TypeLoader( [Obsolete("This will be removed in a future version.")] public IEnumerable TypeLists => _types.Values; - /// - /// Sets a type list. - /// - /// For unit tests. - // internal for tests - [Obsolete("This will be removed in a future version.")] - public void AddTypeList(TypeList typeList) - { - Type tobject = typeof(object); // CompositeTypeTypeKey does not support null values - _types[new CompositeTypeTypeKey(typeList.BaseType ?? tobject, typeList.AttributeType ?? tobject)] = typeList; - } - #region Get Assembly Attributes /// @@ -136,34 +91,6 @@ public IEnumerable GetAssemblyAttributes(params Type[] attributeTypes #region Cache - // internal for tests - [Obsolete("This will be removed in a future version.")] - public Attempt> TryGetCached(Type baseType, Type attributeType) => - Attempt>.Fail(); - - // internal for tests - [Obsolete("This will be removed in a future version.")] - public Dictionary<(string, string), IEnumerable>? ReadCache() => null; - - // internal for tests - [Obsolete("This will be removed in a future version.")] - public string? GetTypesListFilePath() => null; - - // internal for tests - [Obsolete("This will be removed in a future version.")] - public void WriteCache() - { - } - - /// - /// Clears cache. - /// - /// Generally only used for resetting cache, for example during the install process. - [Obsolete("This will be removed in a future version.")] - public void ClearTypesCache() - { - } - #endregion #region Get Types diff --git a/tests/Umbraco.Tests.Common/TestHelperBase.cs b/tests/Umbraco.Tests.Common/TestHelperBase.cs index 072e20635a70..905d86042f4b 100644 --- a/tests/Umbraco.Tests.Common/TestHelperBase.cs +++ b/tests/Umbraco.Tests.Common/TestHelperBase.cs @@ -197,12 +197,7 @@ public UriUtility UriUtility public TypeLoader GetMockedTypeLoader() => new( Mock.Of(), - new VaryingRuntimeHash(), - Mock.Of(), - new DirectoryInfo(GetHostingEnvironment() - .MapPathContentRoot(Constants.SystemDirectories.TempData)), - Mock.Of>(), - Mock.Of()); + Mock.Of>()); /// /// Some test files are copied to the /bin (/bin/debug) on build, this is a utility to return their physical path based diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Persistence.EFCore/DbContext/CustomDbContextTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Persistence.EFCore/DbContext/CustomDbContextTests.cs index bfa3adb92bbf..9a17df69ad93 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Persistence.EFCore/DbContext/CustomDbContextTests.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Persistence.EFCore/DbContext/CustomDbContextTests.cs @@ -68,34 +68,3 @@ public CustomDbContext(DbContextOptions options) } } -[Obsolete] -[TestFixture] -[UmbracoTest(Database = UmbracoTestOptions.Database.NewSchemaPerTest, Logger = UmbracoTestOptions.Logger.Console)] -public class CustomDbContextLegacyExtensionProviderTests : UmbracoIntegrationTest -{ - [Test] - public void Can_Register_Custom_DbContext_And_Resolve() - { - var dbContext = Services.GetRequiredService(); - - Assert.IsNotNull(dbContext); - Assert.IsNotEmpty(dbContext.Database.GetConnectionString()); - } - - protected override void CustomTestSetup(IUmbracoBuilder builder) - { - builder.Services.AddUmbracoEFCoreContext("Data Source=:memory:;Version=3;New=True;", "Microsoft.Data.Sqlite", (options, connectionString, providerName) => - { - options.UseSqlite(connectionString); - }); - } - - internal class CustomDbContext : Microsoft.EntityFrameworkCore.DbContext - { - public CustomDbContext(DbContextOptions options) - : base(options) - { - } - } -} - diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs index 25bdb0bec740..bc8b8f8a5b81 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Components/ComponentTests.cs @@ -108,11 +108,7 @@ private static IServiceProvider MockFactory(Action> setup private static TypeLoader MockTypeLoader() => new( Mock.Of(), - new VaryingRuntimeHash(), - Mock.Of(), - new DirectoryInfo(TestHelper.GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), - Mock.Of>(), - Mock.Of()); + Mock.Of>()); [Test] public async Task Boot1A() @@ -452,11 +448,7 @@ public void AllComposers() var typeFinder = TestHelper.GetTypeFinder(); var typeLoader = new TypeLoader( typeFinder, - new VaryingRuntimeHash(), - AppCaches.Disabled.RuntimeCache, - new DirectoryInfo(TestHelper.GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), - Mock.Of>(), - Mock.Of()); + Mock.Of>()); var register = MockRegister(); var builder = new UmbracoBuilder(register, Mock.Of(), TestHelper.GetMockedTypeLoader()); diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/ComposingTestBase.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/ComposingTestBase.cs index f3c615e98ec5..aa3ac2a3b8d0 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/ComposingTestBase.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/ComposingTestBase.cs @@ -31,12 +31,7 @@ public void Initialize() var typeFinder = TestHelper.GetTypeFinder(); TypeLoader = new TypeLoader( typeFinder, - new VaryingRuntimeHash(), - NoAppCache.Instance, - new DirectoryInfo(TestHelper.GetHostingEnvironment().MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of>(), - Mock.Of(), - false, AssembliesToScan); } } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs index d02da0dda9da..068bf44db66f 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/Composing/TypeLoaderTests.cs @@ -43,13 +43,7 @@ public void Initialize() }; _typeLoader = new TypeLoader( typeFinder, - new VaryingRuntimeHash(), - NoAppCache.Instance, - new DirectoryInfo(TestHelper.GetHostingEnvironment() - .MapPathContentRoot(Constants.SystemDirectories.TempData)), Mock.Of>(), - Mock.Of(), - false, assemblies); } From fac027673943c64f3d9cd4ef09cef86cc9a4ae0c Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 15:58:02 +0100 Subject: [PATCH 13/15] More obsolete removal --- .../Configuration/Models/NuCacheSettings.cs | 2 +- .../Configuration/Models/SecuritySettings.cs | 7 ------ .../Models/WebRoutingSettings.cs | 4 ---- .../DeliveryApi/IApiRichTextElementParser.cs | 5 +--- .../UmbracoBuilder.Configuration.cs | 14 ----------- .../DependencyInjection/UmbracoBuilder.cs | 23 +++++++++++++++++++ .../Routing/ContentFinderByIdPath.cs | 2 +- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs b/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs index 9b1fde982622..0095a8f165b5 100644 --- a/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/NuCacheSettings.cs @@ -19,7 +19,7 @@ public class NuCacheSettings /// /// Gets or sets a value defining the BTree block size. /// - [Obsolete("This property is no longer used")] + [Obsolete("This property is no longer used. Scheduled for removal in v16")] public int? BTreeBlockSize { get; set; } /// diff --git a/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs index 2a57a0a74c7c..b5d81c1ab3d3 100644 --- a/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs +++ b/src/Umbraco.Core/Configuration/Models/SecuritySettings.cs @@ -95,13 +95,6 @@ public class SecuritySettings [DefaultValue(StaticUserDefaultLockoutTimeInMinutes)] public int UserDefaultLockoutTimeInMinutes { get; set; } = StaticUserDefaultLockoutTimeInMinutes; - /// - /// Gets or sets a value indicating whether to allow editing invariant properties from a non-default language variation. - /// - [Obsolete("Use ContentSettings.AllowEditFromInvariant instead")] - [DefaultValue(StaticAllowEditInvariantFromNonDefault)] - public bool AllowEditInvariantFromNonDefault { get; set; } = StaticAllowEditInvariantFromNonDefault; - /// /// Gets or sets a value indicating whether to allow concurrent logins. /// diff --git a/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs b/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs index 37a39a6c929c..9c96f87c319c 100644 --- a/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs +++ b/src/Umbraco.Core/Configuration/Models/WebRoutingSettings.cs @@ -60,10 +60,6 @@ public class WebRoutingSettings [DefaultValue(StaticValidateAlternativeTemplates)] public bool ValidateAlternativeTemplates { get; set; } = StaticValidateAlternativeTemplates; - [Obsolete("Use DisableFindContentByIdentifierPath instead. This will be removed in Umbraco 15." )] - [DefaultValue(StaticDisableFindContentByIdPath)] - public bool DisableFindContentByIdPath { get; set; } = StaticDisableFindContentByIdPath; - [DefaultValue(StaticDisableFindContentByIdentifierPath)] public bool DisableFindContentByIdentifierPath { get; set; } = StaticDisableFindContentByIdentifierPath; /// diff --git a/src/Umbraco.Core/DeliveryApi/IApiRichTextElementParser.cs b/src/Umbraco.Core/DeliveryApi/IApiRichTextElementParser.cs index 50b9b5d581fc..4b1b1e92d317 100644 --- a/src/Umbraco.Core/DeliveryApi/IApiRichTextElementParser.cs +++ b/src/Umbraco.Core/DeliveryApi/IApiRichTextElementParser.cs @@ -5,9 +5,6 @@ namespace Umbraco.Cms.Core.DeliveryApi; public interface IApiRichTextElementParser { - // NOTE: remember to also remove the default implementation of the method overload when this one is removed. - [Obsolete($"Please use the overload that accepts {nameof(RichTextBlockModel)}. Will be removed in V15.")] - IRichTextElement? Parse(string html); - IRichTextElement? Parse(string html, RichTextBlockModel? richTextBlockModel) => null; + IRichTextElement? Parse(string html, RichTextBlockModel? richTextBlockModel); } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs index a3b3ed763133..f393a9cedb50 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.Configuration.cs @@ -109,20 +109,6 @@ public static IUmbracoBuilder AddConfiguration(this IUmbracoBuilder builder) builder.Services.Configure(Constants.Configuration.NamedOptions.CacheEntry.Document, builder.Config.GetSection($"{Constants.Configuration.ConfigCacheEntry}:{Constants.Configuration.NamedOptions.CacheEntry.Document}")); - // TODO: Remove this in V12 - // This is to make the move of the AllowEditInvariantFromNonDefault setting from SecuritySettings to ContentSettings backwards compatible - // If there is a value in security settings, but no value in content setting we'll use that value, otherwise content settings always wins. - builder.Services.Configure(settings => - { - var securitySettingsValue = builder.Config.GetSection($"{Constants.Configuration.ConfigSecurity}").GetValue(nameof(SecuritySettings.AllowEditInvariantFromNonDefault)); - var contentSettingsValue = builder.Config.GetSection($"{Constants.Configuration.ConfigContent}").GetValue(nameof(ContentSettings.AllowEditInvariantFromNonDefault)); - - if (securitySettingsValue is not null && contentSettingsValue is null) - { - settings.AllowEditInvariantFromNonDefault = securitySettingsValue.Value; - } - }); - return builder; } } diff --git a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs index 9fb195481f77..5e06ea504208 100644 --- a/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs +++ b/src/Umbraco.Core/DependencyInjection/UmbracoBuilder.cs @@ -63,6 +63,7 @@ public class UmbracoBuilder : IUmbracoBuilder public ILoggerFactory BuilderLoggerFactory { get; } /// + [Obsolete("Only here to comply with obsolete implementation. Scheduled for removal in v16")] public IHostingEnvironment? BuilderHostingEnvironment { get; } public IProfiler Profiler { get; } @@ -79,6 +80,7 @@ public UmbracoBuilder(IServiceCollection services, IConfiguration config, TypeLo /// /// Initializes a new instance of the class. /// + [Obsolete("Use a non obsolete constructor instead. Scheduled for removal in v16")] public UmbracoBuilder( IServiceCollection services, IConfiguration config, @@ -99,6 +101,27 @@ public UmbracoBuilder( AddCoreServices(); } + /// + /// Initializes a new instance of the class. + /// + public UmbracoBuilder( + IServiceCollection services, + IConfiguration config, + TypeLoader typeLoader, + ILoggerFactory loggerFactory, + IProfiler profiler, + AppCaches appCaches) + { + Services = services; + Config = config; + BuilderLoggerFactory = loggerFactory; + Profiler = profiler; + AppCaches = appCaches; + TypeLoader = typeLoader; + + AddCoreServices(); + } + /// /// Gets a collection builder (and registers the collection). /// diff --git a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs index 86a559b5dbef..32bca4aa4513 100644 --- a/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs +++ b/src/Umbraco.Core/Routing/ContentFinderByIdPath.cs @@ -53,7 +53,7 @@ public Task TryFindContent(IPublishedRequestBuilder frequest) return Task.FromResult(false); } - if (umbracoContext.InPreviewMode == false && (_webRoutingSettings.DisableFindContentByIdPath || _webRoutingSettings.DisableFindContentByIdentifierPath)) + if (umbracoContext.InPreviewMode == false && _webRoutingSettings.DisableFindContentByIdentifierPath) { return Task.FromResult(false); } From 332ed46f639e9c4b23775e29d0df950752618f9d Mon Sep 17 00:00:00 2001 From: Sven Geusens Date: Tue, 5 Nov 2024 16:17:37 +0100 Subject: [PATCH 14/15] Deploy obsoletion cleanup --- .../Deploy/IDataTypeConfigurationConnector.cs | 42 ++---- src/Umbraco.Core/Deploy/IFileSource.cs | 45 ------ src/Umbraco.Core/Deploy/IFileType.cs | 18 --- src/Umbraco.Core/Deploy/IImageSourceParser.cs | 39 +----- src/Umbraco.Core/Deploy/ILocalLinkParser.cs | 39 +----- src/Umbraco.Core/Deploy/IServiceConnector.cs | 131 +----------------- src/Umbraco.Core/Deploy/IValueConnector.cs | 45 ++---- .../Umbraco.Core/CoreThings/UdiTests.cs | 20 ++- 8 files changed, 41 insertions(+), 338 deletions(-) diff --git a/src/Umbraco.Core/Deploy/IDataTypeConfigurationConnector.cs b/src/Umbraco.Core/Deploy/IDataTypeConfigurationConnector.cs index 052d3df388f7..bfaf32196e48 100644 --- a/src/Umbraco.Core/Deploy/IDataTypeConfigurationConnector.cs +++ b/src/Umbraco.Core/Deploy/IDataTypeConfigurationConnector.cs @@ -19,18 +19,6 @@ public interface IDataTypeConfigurationConnector /// IEnumerable PropertyEditorAliases { get; } - /// - /// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies. - /// - /// The data type. - /// The dependencies. - /// The context cache. - /// - /// The artifact configuration value. - /// - [Obsolete("Use ToArtifactAsync() instead. This method will be removed in a future version.")] - string? ToArtifact(IDataType dataType, ICollection dependencies, IContextCache contextCache); - /// /// Gets the artifact configuration value corresponding to a data type configuration and gather dependencies. /// @@ -41,22 +29,11 @@ public interface IDataTypeConfigurationConnector /// /// A task that represents the asynchronous operation. The task result contains the artifact configuration value. /// - Task ToArtifactAsync(IDataType dataType, ICollection dependencies, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(ToArtifact(dataType, dependencies, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Gets the data type configuration corresponding to an artifact configuration value. - /// - /// The data type. - /// The artifact configuration value. - /// The context cache. - /// - /// The data type configuration. - /// - [Obsolete("Use FromArtifactAsync() instead. This method will be removed in a future version.")] - IDictionary FromArtifact(IDataType dataType, string? configuration, IContextCache contextCache); + Task ToArtifactAsync( + IDataType dataType, + ICollection dependencies, + IContextCache contextCache, + CancellationToken cancellationToken = default); /// /// Gets the data type configuration corresponding to an artifact configuration value. @@ -68,8 +45,9 @@ public interface IDataTypeConfigurationConnector /// /// A task that represents the asynchronous operation. The task result contains the data type configuration. /// - Task> FromArtifactAsync(IDataType dataType, string? configuration, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(FromArtifact(dataType, configuration, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete + Task> FromArtifactAsync( + IDataType dataType, + string? configuration, + IContextCache contextCache, + CancellationToken cancellationToken = default); } diff --git a/src/Umbraco.Core/Deploy/IFileSource.cs b/src/Umbraco.Core/Deploy/IFileSource.cs index 53db3e26e63e..230140c9bf69 100644 --- a/src/Umbraco.Core/Deploy/IFileSource.cs +++ b/src/Umbraco.Core/Deploy/IFileSource.cs @@ -6,19 +6,6 @@ namespace Umbraco.Cms.Core.Deploy; /// public interface IFileSource { - /// - /// Gets the content of a file as a stream. - /// - /// A file entity identifier. - /// - /// A stream with read access to the file content. - /// - /// - /// Returns null if no content could be read. - /// The caller should ensure that the stream is properly closed/disposed. - /// - [Obsolete("Use GetFileStreamAsync() instead. This method will be removed in a future version.")] - Stream GetFileStream(StringUdi udi); /// /// Gets the content of a file as a stream. @@ -34,19 +21,6 @@ public interface IFileSource /// Task GetFileStreamAsync(StringUdi udi, CancellationToken token); - /// - /// Gets the content of a file as a string. - /// - /// A file entity identifier. - /// - /// A string containing the file content. - /// - /// - /// Returns null if no content could be read. - /// - [Obsolete("Use GetFileContentAsync() instead. This method will be removed in a future version.")] - string GetFileContent(StringUdi udi); - /// /// Gets the content of a file as a string. /// @@ -60,16 +34,6 @@ public interface IFileSource /// Task GetFileContentAsync(StringUdi udi, CancellationToken token); - /// - /// Gets the length of a file. - /// - /// A file entity identifier. - /// - /// The length of the file, or -1 if the file does not exist. - /// - [Obsolete("Use GetFileLengthAsync() instead. This method will be removed in a future version.")] - long GetFileLength(StringUdi udi); - /// /// Gets the length of a file. /// @@ -80,15 +44,6 @@ public interface IFileSource /// Task GetFileLengthAsync(StringUdi udi, CancellationToken token); - /// - /// Gets files and store them using a file store. - /// - /// The UDIs of the files to get. - /// A flag indicating whether to continue if a file isn't found or to stop and throw a FileNotFoundException. - /// A collection of file types which can store the files. - [Obsolete("Use GetFilesAsync() instead. This method will be removed in a future version.")] - void GetFiles(IEnumerable udis, bool continueOnFileNotFound, IFileTypeCollection fileTypes); - /// /// Gets files and store them using a file store. /// diff --git a/src/Umbraco.Core/Deploy/IFileType.cs b/src/Umbraco.Core/Deploy/IFileType.cs index a135481eb4cf..f8fa5ba92d25 100644 --- a/src/Umbraco.Core/Deploy/IFileType.cs +++ b/src/Umbraco.Core/Deploy/IFileType.cs @@ -13,16 +13,6 @@ public interface IFileType /// bool CanSetPhysical { get; } - /// - /// Gets the stream. - /// - /// The UDI. - /// - /// The stream. - /// - [Obsolete("Use GetStreamAsync() instead. This method will be removed in a future version.")] - Stream GetStream(StringUdi udi); - /// /// Gets the stream as an asynchronous operation. /// @@ -51,14 +41,6 @@ public interface IFileType /// long GetLength(StringUdi udi); - /// - /// Sets the stream. - /// - /// The UDI. - /// The stream. - [Obsolete("Use SetStreamAsync() instead. This method will be removed in a future version.")] - void SetStream(StringUdi udi, Stream stream); - /// /// Sets the stream as an asynchronous operation. /// diff --git a/src/Umbraco.Core/Deploy/IImageSourceParser.cs b/src/Umbraco.Core/Deploy/IImageSourceParser.cs index 3817dc6fb8ef..dd4124e889db 100644 --- a/src/Umbraco.Core/Deploy/IImageSourceParser.cs +++ b/src/Umbraco.Core/Deploy/IImageSourceParser.cs @@ -5,21 +5,6 @@ namespace Umbraco.Cms.Core.Deploy; /// public interface IImageSourceParser { - /// - /// Parses an Umbraco property value and produces an artifact property value. - /// - /// The property value. - /// A list of dependencies. - /// The context cache. - /// - /// The parsed value. - /// - /// - /// Turns src="/media/..." into src="umb://media/..." and adds the corresponding udi to the dependencies. - /// - [Obsolete("Use ToArtifactAsync() instead. This method will be removed in a future version.")] - string ToArtifact(string value, ICollection dependencies, IContextCache contextCache); - /// /// Parses an Umbraco property value and produces an artifact property value. /// @@ -33,24 +18,7 @@ public interface IImageSourceParser /// /// Turns src="/media/..." into src="umb://media/..." and adds the corresponding udi to the dependencies. /// - Task ToArtifactAsync(string value, ICollection dependencies, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(ToArtifact(value, dependencies, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Parses an artifact property value and produces an Umbraco property value. - /// - /// The artifact property value. - /// The context cache. - /// - /// The parsed value. - /// - /// - /// Turns umb://media/... into /media/.... - /// - [Obsolete("Use FromArtifactAsync() instead. This method will be removed in a future version.")] - string FromArtifact(string value, IContextCache contextCache); + Task ToArtifactAsync(string value, ICollection dependencies, IContextCache contextCache, CancellationToken cancellationToken = default); /// /// Parses an artifact property value and produces an Umbraco property value. @@ -64,8 +32,5 @@ Task ToArtifactAsync(string value, ICollection dependencies, IConte /// /// Turns umb://media/... into /media/.... /// - Task FromArtifactAsync(string value, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(FromArtifact(value, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete + Task FromArtifactAsync(string value, IContextCache contextCache, CancellationToken cancellationToken = default); } diff --git a/src/Umbraco.Core/Deploy/ILocalLinkParser.cs b/src/Umbraco.Core/Deploy/ILocalLinkParser.cs index fcd3405a3caa..357b0ecda6d9 100644 --- a/src/Umbraco.Core/Deploy/ILocalLinkParser.cs +++ b/src/Umbraco.Core/Deploy/ILocalLinkParser.cs @@ -5,21 +5,6 @@ namespace Umbraco.Cms.Core.Deploy; /// public interface ILocalLinkParser { - /// - /// Parses an Umbraco property value and produces an artifact property value. - /// - /// The property value. - /// A list of dependencies. - /// The context cache. - /// - /// The parsed value. - /// - /// - /// Turns {{localLink:1234}} into {{localLink:umb://{type}/{id}}} and adds the corresponding udi to the dependencies. - /// - [Obsolete("Use ToArtifactAsync() instead. This method will be removed in a future version.")] - string ToArtifact(string value, ICollection dependencies, IContextCache contextCache); - /// /// Parses an Umbraco property value and produces an artifact property value. /// @@ -33,24 +18,7 @@ public interface ILocalLinkParser /// /// Turns {{localLink:1234}} into {{localLink:umb://{type}/{id}}} and adds the corresponding udi to the dependencies. /// - Task ToArtifactAsync(string value, ICollection dependencies, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(ToArtifact(value, dependencies, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Parses an artifact property value and produces an Umbraco property value. - /// - /// The artifact property value. - /// The context cache. - /// - /// The parsed value. - /// - /// - /// Turns {{localLink:umb://{type}/{id}}} into {{localLink:1234}}. - /// - [Obsolete("Use FromArtifactAsync() instead. This method will be removed in a future version.")] - string FromArtifact(string value, IContextCache contextCache); + Task ToArtifactAsync(string value, ICollection dependencies, IContextCache contextCache, CancellationToken cancellationToken = default); /// /// Parses an artifact property value and produces an Umbraco property value. @@ -64,8 +32,5 @@ Task ToArtifactAsync(string value, ICollection dependencies, IConte /// /// Turns {{localLink:umb://{type}/{id}}} into {{localLink:1234}}. /// - Task FromArtifactAsync(string value, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(FromArtifact(value, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete + Task FromArtifactAsync(string value, IContextCache contextCache, CancellationToken cancellationToken = default); } diff --git a/src/Umbraco.Core/Deploy/IServiceConnector.cs b/src/Umbraco.Core/Deploy/IServiceConnector.cs index 79666f2fa707..4f8b2bfe5ddb 100644 --- a/src/Umbraco.Core/Deploy/IServiceConnector.cs +++ b/src/Umbraco.Core/Deploy/IServiceConnector.cs @@ -8,17 +8,6 @@ namespace Umbraco.Cms.Core.Deploy; /// public interface IServiceConnector : IDiscoverable { - /// - /// Gets an artifact. - /// - /// The entity identifier of the artifact. - /// The context cache. - /// - /// The corresponding artifact or null. - /// - [Obsolete("Use GetArtifactAsync() instead. This method will be removed in a future version.")] - IArtifact? GetArtifact(Udi udi, IContextCache contextCache); - /// /// Gets an artifact. /// @@ -28,21 +17,7 @@ public interface IServiceConnector : IDiscoverable /// /// A task that represents the asynchronous operation. The task result contains the corresponding artifact or null. /// - Task GetArtifactAsync(Udi udi, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(GetArtifact(udi, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Gets an artifact. - /// - /// The entity. - /// The context cache. - /// - /// The corresponding artifact. - /// - [Obsolete("Use GetArtifactAsync() instead. This method will be removed in a future version.")] - IArtifact GetArtifact(object entity, IContextCache contextCache); + Task GetArtifactAsync(Udi udi, IContextCache contextCache, CancellationToken cancellationToken = default); /// /// Gets an artifact. @@ -53,21 +28,7 @@ public interface IServiceConnector : IDiscoverable /// /// A task that represents the asynchronous operation. The task result contains the corresponding artifact. /// - Task GetArtifactAsync(object entity, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(GetArtifact(entity, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Initializes processing for an artifact. - /// - /// The artifact. - /// The deploy context. - /// - /// The state of an artifact being deployed. - /// - [Obsolete("Use ProcessInitAsync() instead. This method will be removed in a future version.")] - ArtifactDeployState ProcessInit(IArtifact art, IDeployContext context); + Task GetArtifactAsync(object entity, IContextCache contextCache, CancellationToken cancellationToken = default); /// /// Initializes processing for an artifact. @@ -78,19 +39,7 @@ Task GetArtifactAsync(object entity, IContextCache contextCache, Canc /// /// A task that represents the asynchronous operation. The task result contains the state of an artifact being deployed. /// - Task ProcessInitAsync(IArtifact artifact, IDeployContext context, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(ProcessInit(artifact, context)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Processes an artifact. - /// - /// The state of the artifact being deployed. - /// The deploy context. - /// The processing pass number. - [Obsolete("Use ProcessAsync() instead. This method will be removed in a future version.")] - void Process(ArtifactDeployState dart, IDeployContext context, int pass); + Task ProcessInitAsync(IArtifact artifact, IDeployContext context, CancellationToken cancellationToken = default); /// /// Processes an artifact. @@ -102,23 +51,7 @@ Task ProcessInitAsync(IArtifact artifact, IDeployContext co /// /// A task that represents the asynchronous operation. /// - Task ProcessAsync(ArtifactDeployState state, IDeployContext context, int pass, CancellationToken cancellationToken = default) - { - // TODO: Remove default implementation in v15 -#pragma warning disable CS0618 // Type or member is obsolete - Process(state, context, pass); -#pragma warning restore CS0618 // Type or member is obsolete - - return Task.CompletedTask; - } - - /// - /// Explodes/expands an UDI range into UDIs. - /// - /// The UDI range. - /// The list of UDIs where to add the exploded/expanded UDIs. - [Obsolete("Use ExpandRangeAsync() instead. This method will be removed in a future version.")] - void Explode(UdiRange range, List udis); + Task ProcessAsync(ArtifactDeployState state, IDeployContext context, int pass, CancellationToken cancellationToken = default); /// /// Expands an UDI range into UDIs. @@ -128,30 +61,7 @@ Task ProcessAsync(ArtifactDeployState state, IDeployContext context, int pass, C /// /// Returns an which when enumerated will asynchronously expand the UDI range into UDIs. /// - async IAsyncEnumerable ExpandRangeAsync(UdiRange range, [EnumeratorCancellation] CancellationToken cancellationToken = default) - { - // TODO: Remove default implementation in v15 - var udis = new List(); -#pragma warning disable CS0618 // Type or member is obsolete - Explode(range, udis); -#pragma warning restore CS0618 // Type or member is obsolete - - foreach (Udi udi in udis) - { - yield return await ValueTask.FromResult(udi); - } - } - - /// - /// Gets a named range for a specified UDI and selector. - /// - /// The UDI. - /// The selector. - /// - /// The named range for the specified UDI and selector. - /// - [Obsolete("Use GetRangeAsync() instead. This method will be removed in a future version.")] - NamedUdiRange GetRange(Udi udi, string selector); + IAsyncEnumerable ExpandRangeAsync(UdiRange range, CancellationToken cancellationToken = default); /// /// Gets a named range for a specified UDI and selector. @@ -162,31 +72,7 @@ async IAsyncEnumerable ExpandRangeAsync(UdiRange range, [EnumeratorCancella /// /// A task that represents the asynchronous operation. The task result contains the named range for the specified UDI and selector. /// - Task GetRangeAsync(Udi udi, string selector, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(GetRange(udi, selector)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Gets a named range for specified entity type, identifier and selector. - /// - /// The entity type. - /// The identifier. - /// The selector. - /// - /// The named range for the specified entity type, identifier and selector. - /// - /// - /// This is temporary. At least we thought it would be, in sept. 2016. What day is it now? - /// - /// At the moment our UI has a hard time returning proper UDIs, mainly because Core's tree do - /// not manage GUIDs but only integers... so we have to provide a way to support it. The string id here - /// can be either a real string (for string UDIs) or an "integer as a string", using the value "-1" to - /// indicate the "root" i.e. an open UDI. - /// - /// - [Obsolete("Use GetRangeAsync() instead. This method will be removed in a future version.")] - NamedUdiRange GetRange(string entityType, string sid, string selector); + Task GetRangeAsync(Udi udi, string selector, CancellationToken cancellationToken = default); /// /// Gets a named range for specified entity type, identifier and selector. @@ -207,10 +93,7 @@ Task GetRangeAsync(Udi udi, string selector, CancellationToken ca /// indicate the "root" i.e. an open UDI. /// /// - Task GetRangeAsync(string entityType, string sid, string selector, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(GetRange(entityType, sid, selector)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete + Task GetRangeAsync(string entityType, string sid, string selector, CancellationToken cancellationToken = default); /// /// Compares two artifacts. diff --git a/src/Umbraco.Core/Deploy/IValueConnector.cs b/src/Umbraco.Core/Deploy/IValueConnector.cs index 06d37e792e79..663d3bd471cc 100644 --- a/src/Umbraco.Core/Deploy/IValueConnector.cs +++ b/src/Umbraco.Core/Deploy/IValueConnector.cs @@ -20,19 +20,6 @@ public interface IValueConnector /// IEnumerable PropertyEditorAliases { get; } - /// - /// Gets the deploy property value corresponding to a content property value, and gather dependencies. - /// - /// The content property value. - /// The value property type - /// The content dependencies. - /// The context cache. - /// - /// The deploy property value. - /// - [Obsolete("Use ToArtifactAsync() instead. This method will be removed in a future version.")] - string? ToArtifact(object? value, IPropertyType propertyType, ICollection dependencies, IContextCache contextCache); - /// /// Gets the deploy property value corresponding to a content property value, and gather dependencies. /// @@ -44,23 +31,11 @@ public interface IValueConnector /// /// A task that represents the asynchronous operation. The task result contains the deploy property value. /// - Task ToArtifactAsync(object? value, IPropertyType propertyType, ICollection dependencies, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(ToArtifact(value, propertyType, dependencies, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete - - /// - /// Gets the content property value corresponding to a deploy property value. - /// - /// The deploy property value. - /// The value property type - /// The current content property value. - /// The context cache. - /// - /// The content property value. - /// - [Obsolete("Use FromArtifactAsync() instead. This method will be removed in a future version.")] - object? FromArtifact(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache); + Task ToArtifactAsync(object? value, + IPropertyType propertyType, + ICollection dependencies, + IContextCache contextCache, + CancellationToken cancellationToken = default); /// /// Gets the content property value corresponding to a deploy property value. @@ -73,8 +48,10 @@ public interface IValueConnector /// /// A task that represents the asynchronous operation. The task result contains the content property value. /// - Task FromArtifactAsync(string? value, IPropertyType propertyType, object? currentValue, IContextCache contextCache, CancellationToken cancellationToken = default) -#pragma warning disable CS0618 // Type or member is obsolete - => Task.FromResult(FromArtifact(value, propertyType, currentValue, contextCache)); // TODO: Remove default implementation in v15 -#pragma warning restore CS0618 // Type or member is obsolete + Task FromArtifactAsync( + string? value, + IPropertyType propertyType, + object? currentValue, + IContextCache contextCache, + CancellationToken cancellationToken = default); } diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/UdiTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/UdiTests.cs index b7f9e4c4cd87..03d086b4a66d 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/UdiTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/CoreThings/UdiTests.cs @@ -313,24 +313,22 @@ public void KnownTypes() [UdiDefinition("foo", UdiType.GuidUdi)] public class FooConnector : IServiceConnector { - public IArtifact GetArtifact(Udi udi, IContextCache contextCache) => throw new NotImplementedException(); + public Task GetArtifactAsync(Udi udi, IContextCache contextCache, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public IArtifact GetArtifact(object entity, IContextCache contextCache) => throw new NotImplementedException(); + public Task GetArtifactAsync(object entity, IContextCache contextCache, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public ArtifactDeployState ProcessInit(IArtifact art, IDeployContext context) => - throw new NotImplementedException(); + public Task ProcessInitAsync(IArtifact artifact, IDeployContext context, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public void Process(ArtifactDeployState dart, IDeployContext context, int pass) => + public Task ProcessAsync(ArtifactDeployState state, IDeployContext context, int pass, + CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public void Explode(UdiRange range, List udis) => throw new NotImplementedException(); + public IAsyncEnumerable ExpandRangeAsync(UdiRange range, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public NamedUdiRange GetRange(Udi udi, string selector) => throw new NotImplementedException(); + public Task GetRangeAsync(Udi udi, string selector, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public NamedUdiRange GetRange(string entityType, string sid, string selector) => - throw new NotImplementedException(); + public Task GetRangeAsync(string entityType, string sid, string selector, CancellationToken cancellationToken = default) => throw new NotImplementedException(); - public bool Compare(IArtifact art1, IArtifact art2, ICollection differences = null) => - throw new NotImplementedException(); + public bool Compare(IArtifact? art1, IArtifact? art2, ICollection? differences = null) => throw new NotImplementedException(); } } From 998bf4facb527c6adf4a671966f59c59786890ce Mon Sep 17 00:00:00 2001 From: Zeegaan Date: Thu, 7 Nov 2024 10:56:46 +0100 Subject: [PATCH 15/15] Remove obsolete methods from OEmbedProviderBase.cs --- .../EmbedProviders/OEmbedProviderBase.cs | 34 ------------------- 1 file changed, 34 deletions(-) diff --git a/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs b/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs index 57c6df4f6d8f..369b6d7249c4 100644 --- a/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs +++ b/src/Umbraco.Core/Media/EmbedProviders/OEmbedProviderBase.cs @@ -59,22 +59,6 @@ public virtual string GetEmbedProviderUrl(string url, int maxWidth, int maxHeigh return fullUrl.ToString(); } - [Obsolete("Use DownloadResponseAsync instead. This will be removed in Umbraco 15.")] - public virtual string DownloadResponse(string url) - { - if (_httpClient == null) - { - _httpClient = new HttpClient(); - _httpClient.DefaultRequestHeaders.UserAgent.TryParseAdd(Constants.HttpClients.Headers.UserAgentProductName); - } - - using (var request = new HttpRequestMessage(HttpMethod.Get, url)) - { - using HttpResponseMessage response = _httpClient.SendAsync(request).GetAwaiter().GetResult(); - return response.Content.ReadAsStringAsync().Result; - } - } - public virtual async Task DownloadResponseAsync(string url, CancellationToken cancellationToken) { if (_httpClient == null) @@ -90,14 +74,6 @@ public virtual async Task DownloadResponseAsync(string url, Cancellation } } - [Obsolete("Use GetJsonResponseAsync instead. This will be removed in Umbraco 15.")] - public virtual T? GetJsonResponse(string url) - where T : class - { - var response = DownloadResponse(url); - return _jsonSerializer.Deserialize(response); - } - public virtual async Task GetJsonResponseAsync(string url, CancellationToken cancellationToken) where T : class { @@ -114,16 +90,6 @@ public virtual async Task GetXmlResponseAsync(string url, Cancellat return doc; } - [Obsolete("Use GetXmlResponseAsync instead. This will be removed in Umbraco 15.")] - public virtual XmlDocument GetXmlResponse(string url) - { - var response = DownloadResponse(url); - var doc = new XmlDocument(); - doc.LoadXml(response); - - return doc; - } - public virtual string GetXmlProperty(XmlDocument doc, string property) { XmlNode? selectSingleNode = doc.SelectSingleNode(property);