From d8b6ebe48ff78341dcb03cdf39accb4bf925f5d2 Mon Sep 17 00:00:00 2001 From: kjac Date: Fri, 8 Mar 2024 11:34:45 +0100 Subject: [PATCH] Removed unused content editing models --- .../Mapping/Document/DocumentMapDefinition.cs | 8 +- .../Mapping/Media/MediaMapDefinition.cs | 6 +- src/Umbraco.Core/Models/AnchorsModel.cs | 6 - .../AssignedContentPermissions.cs | 19 - .../AssignedUserGroupPermissions.cs | 40 - .../Models/ContentEditing/AuditLog.cs | 34 - .../ContentEditing/BackOfficeNotification.cs | 27 - .../Models/ContentEditing/CodeFileDisplay.cs | 70 -- .../Models/ContentEditing/ContentBaseSave.cs | 56 - .../ContentDomainsAndCulture.cs | 13 - .../Models/ContentEditing/ContentItemBasic.cs | 105 -- .../ContentEditing/ContentItemDisplay.cs | 225 ---- .../ContentEditing/ContentItemDisplayBase.cs | 46 - .../Models/ContentEditing/ContentItemSave.cs | 60 - .../ContentEditing/ContentPropertyBasic.cs | 78 -- .../ContentPropertyCollectionDto.cs | 14 - .../ContentEditing/ContentPropertyDisplay.cs | 36 - .../ContentEditing/ContentPropertyDto.cs | 23 - .../ContentEditing/ContentRedirectUrl.cs | 26 - .../ContentEditing/ContentSaveAction.cs | 69 -- .../ContentEditing/ContentSavedState.cs | 27 - .../Models/ContentEditing/ContentSortOrder.cs | 28 - .../Models/ContentEditing/ContentTypeBasic.cs | 111 -- .../ContentTypeCompositionDisplay.cs | 69 -- .../Models/ContentEditing/ContentTypeSave.cs | 120 -- .../ContentEditing/ContentTypesByAliases.cs | 25 - .../ContentEditing/ContentTypesByKeys.cs | 25 - .../ContentEditing/ContentVariantSave.cs | 69 -- .../ContentEditing/ContentVariationDisplay.cs | 88 -- .../CreatedDocumentTypeCollectionResult.cs | 16 - .../Models/ContentEditing/DataTypeBasic.cs | 22 - .../DataTypeConfigurationFieldDisplay.cs | 16 - .../DataTypeConfigurationFieldSave.cs | 22 - .../Models/ContentEditing/DataTypeDisplay.cs | 32 - .../DataTypeHasValuesDisplay.cs | 19 - .../ContentEditing/DataTypeReferences.cs | 44 - .../Models/ContentEditing/DataTypeSave.cs | 47 - .../ContentEditing/DictionaryDisplay.cs | 38 - .../DictionaryOverviewDisplay.cs | 39 - .../DictionaryOverviewTranslationDisplay.cs | 22 - .../Models/ContentEditing/DictionarySave.cs | 33 - .../DictionaryTranslationDisplay.cs | 23 - .../DictionaryTranslationSave.cs | 28 - .../ContentEditing/DocumentTypeDisplay.cs | 33 - .../Models/ContentEditing/DocumentTypeSave.cs | 42 - .../Models/ContentEditing/DomainDisplay.cs | 25 - .../Models/ContentEditing/DomainSave.cs | 19 - .../Models/ContentEditing/EditorNavigation.cs | 25 - .../Models/ContentEditing/EntityBasic.cs | 68 -- .../ContentEditing/EntitySearchResults.cs | 23 - .../ContentEditing/HistoryCleanupViewModel.cs | 16 - .../ContentEditing/IContentProperties.cs | 7 - .../Models/ContentEditing/IContentSave.cs | 23 - .../Models/ContentEditing/IErrorModel.cs | 14 - .../ContentEditing/INotificationModel.cs | 12 - .../Models/ContentEditing/ITabbedContent.cs | 7 - .../Models/ContentEditing/Language.cs | 32 - .../ListViewAwareContentItemDisplayBase.cs | 27 - .../Models/ContentEditing/MediaItemDisplay.cs | 16 - .../Models/ContentEditing/MediaItemSave.cs | 11 - .../Models/ContentEditing/MediaTypeDisplay.cs | 10 - .../Models/ContentEditing/MediaTypeSave.cs | 11 - .../Models/ContentEditing/MemberBasic.cs | 40 - .../Models/ContentEditing/MemberDisplay.cs | 29 - .../ContentEditing/MemberGroupDisplay.cs | 15 - .../Models/ContentEditing/MemberGroupSave.cs | 8 - .../ContentEditing/MemberListDisplay.cs | 11 - .../ContentEditing/MemberPropertyTypeBasic.cs | 19 - .../MemberPropertyTypeDisplay.cs | 16 - .../Models/ContentEditing/MemberSave.cs | 51 - .../ContentEditing/MemberTypeDisplay.cs | 8 - .../Models/ContentEditing/MemberTypeSave.cs | 8 - .../ContentEditing/MessagesExtensions.cs | 80 -- .../ContentEditing/ModelWithNotifications.cs | 30 - .../Models/ContentEditing/MoveOrCopy.cs | 39 - .../Models/ContentEditing/NamedUrl.cs | 13 - .../ContentEditing/NotificationStyle.cs | 32 - .../Models/ContentEditing/NotifySetting.cs | 19 - .../Models/ContentEditing/ObjectType.cs | 13 - .../Models/ContentEditing/Permission.cs | 33 - .../Models/ContentEditing/PostedFolder.cs | 16 - .../ContentEditing/PropertyEditorBasic.cs | 13 - .../ContentEditing/PropertyGroupBasic.cs | 62 - .../PropertyGroupBasicExtensions.cs | 7 - .../ContentEditing/PropertyGroupDisplay.cs | 37 - .../ContentEditing/PropertyTypeBasic.cs | 68 -- .../ContentEditing/PropertyTypeDisplay.cs | 47 - .../PropertyTypeHasValuesDisplay.cs | 19 - .../ContentEditing/PropertyTypeValidation.cs | 22 - .../Models/ContentEditing/PublicAccess.cs | 19 - .../Models/ContentEditing/PublishContent.cs | 16 - .../RedirectUrlSearchResults.cs | 19 - .../Models/ContentEditing/RelationDisplay.cs | 50 - .../ContentEditing/RelationTypeDisplay.cs | 59 - .../Models/ContentEditing/RelationTypeSave.cs | 31 - .../ContentEditing/RichTextEditorCommand.cs | 23 - .../RichTextEditorCommandMode.cs | 8 + .../RichTextEditorConfiguration.cs | 25 - .../ContentEditing/RichTextEditorPlugin.cs | 10 - .../Models/ContentEditing/RollbackVersion.cs | 19 - .../Models/ContentEditing/SearchResult.cs | 19 - .../ContentEditing/SearchResultEntity.cs | 13 - .../Models/ContentEditing/SearchResults.cs | 18 - .../Models/ContentEditing/Section.cs | 23 - .../ContentEditing/SimpleNotificationModel.cs | 24 - .../Models/ContentEditing/SnippetDisplay.cs | 13 - .../Models/ContentEditing/StyleSheet.cs | 13 - .../Models/ContentEditing/StylesheetRule.cs | 16 - src/Umbraco.Core/Models/ContentEditing/Tab.cs | 37 - .../ContentEditing/TabbedContentItem.cs | 29 - .../Models/ContentEditing/TemplateDisplay.cs | 43 - .../Models/ContentEditing/TreeSearchResult.cs | 32 - .../Models/ContentEditing/UnpublishContent.cs | 16 - .../Models/ContentEditing/UrlAndAnchors.cs | 19 - .../Models/ContentEditing/UserBasic.cs | 65 - .../Models/ContentEditing/UserDetail.cs | 68 -- .../Models/ContentEditing/UserDisplay.cs | 78 -- .../Models/ContentEditing/UserGroupBasic.cs | 47 - .../Models/ContentEditing/UserGroupDisplay.cs | 28 - .../UserGroupPermissionsSave.cs | 25 - .../Models/ContentEditing/UserGroupSave.cs | 98 -- .../Models/ContentEditing/UserInvite.cs | 48 - .../Models/ContentEditing/UserProfile.cs | 21 - .../Models/ContentEditing/UserSave.cs | 56 - .../Models/ContentTypeImportModel.cs | 20 - .../Models/DictionaryImportModel.cs | 14 - .../Models/DictionaryPreviewImportModel.cs | 14 - src/Umbraco.Core/Models/IMigrationEntry.cs | 11 - src/Umbraco.Core/Models/IconModel.cs | 8 - .../Models/Mapping/AuditMapDefinition.cs | 22 - .../Models/Mapping/CodeFileMapDefinition.cs | 98 -- .../Models/Mapping/CommonMapper.cs | 32 +- .../Mapping/ContentPropertyBasicMapper.cs | 96 -- .../Mapping/ContentPropertyDisplayMapper.cs | 76 -- .../Mapping/ContentPropertyDtoMapper.cs | 32 - .../Mapping/ContentPropertyMapDefinition.cs | 171 --- .../Models/Mapping/ContentSavedStateMapper.cs | 83 -- .../Mapping/ContentTypeMapDefinition.cs | 929 -------------- .../Models/Mapping/ContentVariantMapper.cs | 324 ----- .../Models/Mapping/DataTypeMapDefinition.cs | 223 ---- .../Models/Mapping/DictionaryMapDefinition.cs | 105 -- .../Models/Mapping/LanguageMapDefinition.cs | 60 - .../Models/Mapping/MediaMapDefinition.cs | 50 - .../Models/Mapping/MemberMapDefinition.cs | 73 -- .../Mapping/MemberTabsAndPropertiesMapper.cs | 325 ----- .../Models/Mapping/PropertyTypeGroupMapper.cs | 293 ----- .../Mapping/RedirectUrlMapDefinition.cs | 30 - .../Models/Mapping/RelationMapDefinition.cs | 96 -- .../Models/Mapping/TabsAndPropertiesMapper.cs | 156 --- .../Models/Mapping/TemplateMapDefinition.cs | 47 - .../Models/Mapping/UserMapDefinition.cs | 566 --------- src/Umbraco.Core/Models/MigrationEntry.cs | 34 - .../Models/RichTextStylesheetData.cs | 10 - src/Umbraco.Core/Models/SetPasswordModel.cs | 20 - src/Umbraco.Core/Models/TemplateNode.cs | 31 - .../Models/Trees/ActionMenuItem.cs | 52 - .../Models/Trees/CreateChildEntity.cs | 31 - src/Umbraco.Core/Models/Trees/ExportMember.cs | 18 - src/Umbraco.Core/Models/Trees/MenuItem.cs | 208 ---- src/Umbraco.Core/Models/Trees/RefreshNode.cs | 30 - src/Umbraco.Core/Models/UnLinkLoginModel.cs | 15 - .../Models/UpgradeCheckResponse.cs | 29 - .../Models/ValidatePasswordResetCodeModel.cs | 17 - .../SendingAllowedChildrenNotification.cs | 17 - .../SendingContentNotification.cs | 17 - .../Notifications/SendingMediaNotification.cs | 17 - .../SendingMemberNotification.cs | 17 - .../Notifications/SendingUserNotification.cs | 17 - .../Services/IRichTextStylesheetService.cs | 14 - src/Umbraco.Core/Trees/ActionUrlMethod.cs | 10 - src/Umbraco.Core/Trees/CoreTreeAttribute.cs | 12 - .../Trees/IMenuItemCollectionFactory.cs | 13 - src/Umbraco.Core/Trees/ISearchableTree.cs | 24 - .../Trees/ISearchableTreeWithCulture.cs | 21 - src/Umbraco.Core/Trees/ITree.cs | 43 - src/Umbraco.Core/Trees/MenuItemCollection.cs | 33 - .../Trees/MenuItemCollectionFactory.cs | 12 - src/Umbraco.Core/Trees/MenuItemList.cs | 80 -- .../Trees/SearchableApplicationTree.cs | 26 - src/Umbraco.Core/Trees/Tree.cs | 74 -- src/Umbraco.Core/Trees/TreeCollection.cs | 14 - src/Umbraco.Core/Trees/TreeNode.cs | 130 -- src/Umbraco.Core/Trees/TreeNodeCollection.cs | 18 - src/Umbraco.Core/Trees/TreeNodeExtensions.cs | 79 -- src/Umbraco.Core/Trees/TreeUse.cs | 23 - .../UmbracoBuilder.CoreServices.cs | 8 - .../UmbracoBuilder.MappingProfiles.cs | 15 - .../Models/Mapping/EntityMapDefinition.cs | 331 ----- .../Search/UmbracoTreeSearcher.cs | 204 ---- .../Trees/TreeRootNode.cs | 153 --- .../ActionsResults/ValidationErrorResult.cs | 12 - .../Models/DisabledUsersModel.cs | 13 - .../Models/InvitePasswordModel.cs | 18 - .../Models/WebhookLogViewModel.cs | 43 - .../Builders/ContentItemSaveBuilder.cs | 74 -- .../Builders/ContentPropertyBasicBuilder.cs | 47 - .../Builders/ContentVariantSaveBuilder.cs | 76 -- .../ContentItemSaveBuilderExtensions.cs | 51 - .../Builders/TreeBuilder.cs | 81 -- .../Mapping/ContentTypeModelMappingTests.cs | 1077 ----------------- .../Mapping/UmbracoMapperTests.cs | 209 ---- .../Mapping/UserModelMapperTests.cs | 42 - .../Repositories/ContentTypeRepositoryTest.cs | 159 --- .../Umbraco.Core/EnumExtensionsTests.cs | 48 - .../Mapping/MappingTests.cs | 21 - .../ContentModelSerializationTests.cs | 77 -- 206 files changed, 18 insertions(+), 12129 deletions(-) delete mode 100644 src/Umbraco.Core/Models/AnchorsModel.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/AuditLog.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/BackOfficeNotification.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/CodeFileDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentItemBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentItemDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentItemDisplayBase.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentPropertyCollectionDto.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentPropertyDto.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentRedirectUrl.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentSaveAction.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentSavedState.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentTypeBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentTypeCompositionDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentTypeSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentVariantSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/CreatedDocumentTypeCollectionResult.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeHasValuesDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DictionaryDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DictionarySave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DomainDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/DomainSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/EntitySearchResults.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/IContentProperties.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/IContentSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/IErrorModel.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/INotificationModel.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ITabbedContent.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/Language.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MediaItemDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MediaItemSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MediaTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MediaTypeSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberGroupDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberGroupSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MemberTypeSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MessagesExtensions.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ModelWithNotifications.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/MoveOrCopy.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/NamedUrl.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/NotificationStyle.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/ObjectType.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/Permission.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasicExtensions.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyGroupDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyTypeHasValuesDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PropertyTypeValidation.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/PublishContent.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RelationDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RelationTypeDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RelationTypeSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs create mode 100644 src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommandMode.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/SearchResult.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/SearchResultEntity.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/SearchResults.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/Section.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/SimpleNotificationModel.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/Tab.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/TabbedContentItem.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/TemplateDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UrlAndAnchors.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserDetail.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserGroupBasic.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserGroupDisplay.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserGroupPermissionsSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserGroupSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserInvite.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserProfile.cs delete mode 100644 src/Umbraco.Core/Models/ContentEditing/UserSave.cs delete mode 100644 src/Umbraco.Core/Models/ContentTypeImportModel.cs delete mode 100644 src/Umbraco.Core/Models/DictionaryImportModel.cs delete mode 100644 src/Umbraco.Core/Models/DictionaryPreviewImportModel.cs delete mode 100644 src/Umbraco.Core/Models/IMigrationEntry.cs delete mode 100644 src/Umbraco.Core/Models/IconModel.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/AuditMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/CodeFileMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentPropertyBasicMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentPropertyDtoMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentSavedStateMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/DataTypeMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/DictionaryMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/LanguageMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/MediaMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/MemberMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/RedirectUrlMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/RelationMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/TabsAndPropertiesMapper.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/TemplateMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs delete mode 100644 src/Umbraco.Core/Models/MigrationEntry.cs delete mode 100644 src/Umbraco.Core/Models/RichTextStylesheetData.cs delete mode 100644 src/Umbraco.Core/Models/SetPasswordModel.cs delete mode 100644 src/Umbraco.Core/Models/TemplateNode.cs delete mode 100644 src/Umbraco.Core/Models/Trees/ActionMenuItem.cs delete mode 100644 src/Umbraco.Core/Models/Trees/CreateChildEntity.cs delete mode 100644 src/Umbraco.Core/Models/Trees/ExportMember.cs delete mode 100644 src/Umbraco.Core/Models/Trees/MenuItem.cs delete mode 100644 src/Umbraco.Core/Models/Trees/RefreshNode.cs delete mode 100644 src/Umbraco.Core/Models/UnLinkLoginModel.cs delete mode 100644 src/Umbraco.Core/Models/UpgradeCheckResponse.cs delete mode 100644 src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs delete mode 100644 src/Umbraco.Core/Notifications/SendingAllowedChildrenNotification.cs delete mode 100644 src/Umbraco.Core/Notifications/SendingContentNotification.cs delete mode 100644 src/Umbraco.Core/Notifications/SendingMediaNotification.cs delete mode 100644 src/Umbraco.Core/Notifications/SendingMemberNotification.cs delete mode 100644 src/Umbraco.Core/Notifications/SendingUserNotification.cs delete mode 100644 src/Umbraco.Core/Services/IRichTextStylesheetService.cs delete mode 100644 src/Umbraco.Core/Trees/ActionUrlMethod.cs delete mode 100644 src/Umbraco.Core/Trees/CoreTreeAttribute.cs delete mode 100644 src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs delete mode 100644 src/Umbraco.Core/Trees/ISearchableTree.cs delete mode 100644 src/Umbraco.Core/Trees/ISearchableTreeWithCulture.cs delete mode 100644 src/Umbraco.Core/Trees/ITree.cs delete mode 100644 src/Umbraco.Core/Trees/MenuItemCollection.cs delete mode 100644 src/Umbraco.Core/Trees/MenuItemCollectionFactory.cs delete mode 100644 src/Umbraco.Core/Trees/MenuItemList.cs delete mode 100644 src/Umbraco.Core/Trees/SearchableApplicationTree.cs delete mode 100644 src/Umbraco.Core/Trees/Tree.cs delete mode 100644 src/Umbraco.Core/Trees/TreeCollection.cs delete mode 100644 src/Umbraco.Core/Trees/TreeNode.cs delete mode 100644 src/Umbraco.Core/Trees/TreeNodeCollection.cs delete mode 100644 src/Umbraco.Core/Trees/TreeNodeExtensions.cs delete mode 100644 src/Umbraco.Core/Trees/TreeUse.cs delete mode 100644 src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs delete mode 100644 src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs delete mode 100644 src/Umbraco.Infrastructure/Trees/TreeRootNode.cs delete mode 100644 src/Umbraco.Web.Common/Models/DisabledUsersModel.cs delete mode 100644 src/Umbraco.Web.Common/Models/InvitePasswordModel.cs delete mode 100644 src/Umbraco.Web.Common/Models/WebhookLogViewModel.cs delete mode 100644 tests/Umbraco.Tests.Common/Builders/ContentItemSaveBuilder.cs delete mode 100644 tests/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs delete mode 100644 tests/Umbraco.Tests.Common/Builders/ContentVariantSaveBuilder.cs delete mode 100644 tests/Umbraco.Tests.Common/Builders/Extensions/ContentItemSaveBuilderExtensions.cs delete mode 100644 tests/Umbraco.Tests.Common/Builders/TreeBuilder.cs delete mode 100644 tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/ContentTypeModelMappingTests.cs delete mode 100644 tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UmbracoMapperTests.cs delete mode 100644 tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UserModelMapperTests.cs delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs delete mode 100644 tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs diff --git a/src/Umbraco.Cms.Api.Management/Mapping/Document/DocumentMapDefinition.cs b/src/Umbraco.Cms.Api.Management/Mapping/Document/DocumentMapDefinition.cs index 46b5c519ef82..40082f867af3 100644 --- a/src/Umbraco.Cms.Api.Management/Mapping/Document/DocumentMapDefinition.cs +++ b/src/Umbraco.Cms.Api.Management/Mapping/Document/DocumentMapDefinition.cs @@ -16,9 +16,7 @@ public class DocumentMapDefinition : ContentMapDefinition _commonMapper = commonMapper; public void DefineMaps(IUmbracoMapper mapper) { @@ -50,8 +48,8 @@ private void Map(IContent source, DocumentCollectionResponseModel target, Mapper target.Id = source.Key; target.DocumentType = context.Map(source.ContentType)!; target.SortOrder = source.SortOrder; - target.Creator = _commonMapper.GetOwner(source, context)?.Name; - target.Updater = _commonMapper.GetCreator(source, context)?.Name; + target.Creator = _commonMapper.GetOwnerName(source, context); + target.Updater = _commonMapper.GetCreatorName(source, context); // If there's a set of property aliases specified in the collection configuration, we will check if the current property's // value should be mapped. If it isn't one of the ones specified in 'includeProperties', we will just return the result diff --git a/src/Umbraco.Cms.Api.Management/Mapping/Media/MediaMapDefinition.cs b/src/Umbraco.Cms.Api.Management/Mapping/Media/MediaMapDefinition.cs index 534587af6d3b..d4760abe2dc2 100644 --- a/src/Umbraco.Cms.Api.Management/Mapping/Media/MediaMapDefinition.cs +++ b/src/Umbraco.Cms.Api.Management/Mapping/Media/MediaMapDefinition.cs @@ -16,9 +16,7 @@ public class MediaMapDefinition : ContentMapDefinition _commonMapper = commonMapper; public void DefineMaps(IUmbracoMapper mapper) { @@ -42,7 +40,7 @@ private void Map(IMedia source, MediaCollectionResponseModel target, MapperConte target.Id = source.Key; target.MediaType = context.Map(source.ContentType)!; target.SortOrder = source.SortOrder; - target.Creator = _commonMapper.GetOwner(source, context)?.Name; + target.Creator = _commonMapper.GetOwnerName(source, context); // If there's a set of property aliases specified in the collection configuration, we will check if the current property's // value should be mapped. If it isn't one of the ones specified in 'includeProperties', we will just return the result diff --git a/src/Umbraco.Core/Models/AnchorsModel.cs b/src/Umbraco.Core/Models/AnchorsModel.cs deleted file mode 100644 index 90faa01da1e6..000000000000 --- a/src/Umbraco.Core/Models/AnchorsModel.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace Umbraco.Cms.Core.Models; - -public class AnchorsModel -{ - public string? RteContent { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs b/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs deleted file mode 100644 index 18229d2124e9..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/AssignedContentPermissions.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The permissions assigned to a content node -/// -/// -/// The underlying data such as Name, etc... is that of the Content item -/// -[DataContract(Name = "contentPermissions", Namespace = "")] -public class AssignedContentPermissions : EntityBasic -{ - /// - /// The assigned permissions to the content item organized by permission group name - /// - [DataMember(Name = "permissions")] - public IDictionary>? AssignedPermissions { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs b/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs deleted file mode 100644 index 867784d19df2..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/AssignedUserGroupPermissions.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The user group permissions assigned to a content node -/// -/// -/// The underlying data such as Name, etc... is that of the User Group -/// -[DataContract(Name = "userGroupPermissions", Namespace = "")] -public class AssignedUserGroupPermissions : EntityBasic -{ - /// - /// The assigned permissions for the user group organized by permission group name - /// - [DataMember(Name = "permissions")] - public IDictionary>? AssignedPermissions { get; set; } - - /// - /// The default permissions for the user group organized by permission group name - /// - [DataMember(Name = "defaultPermissions")] - public IDictionary>? DefaultPermissions { get; set; } - - public static IDictionary> ClonePermissions( - IDictionary>? permissions) - { - var result = new Dictionary>(); - if (permissions is not null) - { - foreach (KeyValuePair> permission in permissions) - { - result[permission.Key] = new List(permission.Value.Select(x => (Permission)x.Clone())); - } - } - - return result; - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/AuditLog.cs b/src/Umbraco.Core/Models/ContentEditing/AuditLog.cs deleted file mode 100644 index e7b744bd5907..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/AuditLog.cs +++ /dev/null @@ -1,34 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "auditLog", Namespace = "")] -public class AuditLog -{ - [DataMember(Name = "userId")] - public int UserId { get; set; } - - [DataMember(Name = "userName")] - public string? UserName { get; set; } - - [DataMember(Name = "userAvatars")] - public string[]? UserAvatars { get; set; } - - [DataMember(Name = "nodeId")] - public int NodeId { get; set; } - - [DataMember(Name = "timestamp")] - public DateTime Timestamp { get; set; } - - [DataMember(Name = "logType")] - public string? LogType { get; set; } - - [DataMember(Name = "entityType")] - public string? EntityType { get; set; } - - [DataMember(Name = "comment")] - public string? Comment { get; set; } - - [DataMember(Name = "parameters")] - public string? Parameters { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/BackOfficeNotification.cs b/src/Umbraco.Core/Models/ContentEditing/BackOfficeNotification.cs deleted file mode 100644 index 1cf1e60e2552..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/BackOfficeNotification.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "notification", Namespace = "")] -public class BackOfficeNotification -{ - public BackOfficeNotification() - { - } - - public BackOfficeNotification(string header, string message, NotificationStyle notificationType) - { - Header = header; - Message = message; - NotificationType = notificationType; - } - - [DataMember(Name = "header")] - public string? Header { get; set; } - - [DataMember(Name = "message")] - public string? Message { get; set; } - - [DataMember(Name = "type")] - public NotificationStyle NotificationType { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/CodeFileDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/CodeFileDisplay.cs deleted file mode 100644 index b172fccb5a1f..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/CodeFileDisplay.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "scriptFile", Namespace = "")] -public class CodeFileDisplay : INotificationModel, IValidatableObject -{ - public CodeFileDisplay() => Notifications = new List(); - - /// - /// VirtualPath is the path to the file on disk - /// /views/partials/file.cshtml - /// - [DataMember(Name = "virtualPath", IsRequired = true)] - public string? VirtualPath { get; set; } - - /// - /// Path represents the path used by the backoffice tree - /// For files stored on disk, this is a URL encoded, comma separated - /// path to the file, always starting with -1. - /// -1,Partials,Parials%2FFolder,Partials%2FFolder%2FFile.cshtml - /// - [DataMember(Name = "path")] - [ReadOnly(true)] - public string? Path { get; set; } - - [DataMember(Name = "name", IsRequired = true)] - public string? Name { get; set; } - - [DataMember(Name = "content", IsRequired = true)] - public string? Content { get; set; } - - [DataMember(Name = "fileType", IsRequired = true)] - public string? FileType { get; set; } - - [DataMember(Name = "snippet")] - [ReadOnly(true)] - public string? Snippet { get; set; } - - [DataMember(Name = "id")] - [ReadOnly(true)] - public string? Id { get; set; } - - public List Notifications { get; } - - /// - /// Some custom validation is required for valid file names - /// - /// - /// - public IEnumerable Validate(ValidationContext validationContext) - { - var illegalChars = System.IO.Path.GetInvalidFileNameChars(); - if (Name?.ContainsAny(illegalChars) ?? false) - { - yield return new ValidationResult( - "The file name cannot contain illegal characters", - new[] { "Name" }); - } - else if (System.IO.Path.GetFileNameWithoutExtension(Name).IsNullOrWhiteSpace()) - { - yield return new ValidationResult( - "The file name cannot be empty", - new[] { "Name" }); - } - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs b/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs deleted file mode 100644 index a9a95da70a2c..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentBaseSave.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Editors; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a content item to be saved -/// -[DataContract(Name = "content", Namespace = "")] -public abstract class ContentBaseSave : ContentItemBasic, IContentSave - where TPersisted : IContentBase -{ - #region IContentSave - - /// - [DataMember(Name = "action", IsRequired = true)] - [Required] - public ContentSaveAction Action { get; set; } - - [DataMember(Name = "properties")] - public override IEnumerable Properties - { - get => base.Properties; - set => base.Properties = value; - } - - // These need explicit implementation because we are using internal models - - /// - [IgnoreDataMember] - TPersisted IContentSave.PersistedContent { get; set; } = default!; - - // Non explicit internal getter so we don't need to explicitly cast in our own code - [IgnoreDataMember] - public TPersisted PersistedContent - { - get => ((IContentSave)this).PersistedContent; - set => ((IContentSave)this).PersistedContent = value; - } - - /// - /// The property DTO object is used to gather all required property data including data type information etc... for use - /// with validation - used during inbound model binding - /// - /// - /// We basically use this object to hydrate all required data from the database into one object so we can validate - /// everything we need - /// instead of having to look up all the data individually. - /// This is not used for outgoing model information. - /// - [IgnoreDataMember] - public ContentPropertyCollectionDto? PropertyCollectionDto { get; set; } - - #endregion -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs b/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs deleted file mode 100644 index ca24b08567b2..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentDomainsAndCulture.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "ContentDomainsAndCulture")] -public class ContentDomainsAndCulture -{ - [DataMember(Name = "domains")] - public IEnumerable? Domains { get; set; } - - [DataMember(Name = "language")] - public string? Language { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentItemBasic.cs b/src/Umbraco.Core/Models/ContentEditing/ContentItemBasic.cs deleted file mode 100644 index fd277308f74f..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentItemBasic.cs +++ /dev/null @@ -1,105 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a basic content item -/// -[DataContract(Name = "content", Namespace = "")] -public class ContentItemBasic : EntityBasic -{ - [DataMember(Name = "updateDate")] - public DateTime UpdateDate { get; set; } - - [DataMember(Name = "createDate")] - public DateTime CreateDate { get; set; } - - /// - /// Boolean indicating if this item is published or not based on it's - /// - [DataMember(Name = "published")] - public bool Published => State == ContentSavedState.Published || State == ContentSavedState.PublishedPendingChanges; - - /// - /// Determines if the content item is a draft - /// - [DataMember(Name = "edited")] - public bool Edited { get; set; } - - [DataMember(Name = "owner")] - public UserProfile? Owner { get; set; } - - [DataMember(Name = "updater")] - public UserProfile? Updater { get; set; } - - public int ContentTypeId { get; set; } - - [DataMember(Name = "contentTypeAlias", IsRequired = true)] - [Required(AllowEmptyStrings = false)] - public string ContentTypeAlias { get; set; } = null!; - - [DataMember(Name = "sortOrder")] - public int SortOrder { get; set; } - - /// - /// The saved/published state of an item - /// - /// - /// This is nullable since it's only relevant for content (non-content like media + members will be null) - /// - [DataMember(Name = "state")] - public ContentSavedState? State { get; set; } - - [DataMember(Name = "variesByCulture")] - public bool VariesByCulture { get; set; } - - public override bool Equals(object? obj) - { - if (ReferenceEquals(null, obj)) - { - return false; - } - - if (ReferenceEquals(this, obj)) - { - return true; - } - - return obj is ContentItemBasic other && Equals(other); - } - - protected bool Equals(ContentItemBasic other) => Id == other.Id; - - public override int GetHashCode() - { - if (Id is not null) - { - return Id.GetHashCode(); - } - - return base.GetHashCode(); - } -} - -/// -/// A model representing a basic content item with properties -/// -[DataContract(Name = "content", Namespace = "")] -public class ContentItemBasic : ContentItemBasic, IContentProperties - where T : ContentPropertyBasic -{ - private IEnumerable _properties; - - public ContentItemBasic() => - - // ensure its not null - _properties = Enumerable.Empty(); - - [DataMember(Name = "properties")] - public virtual IEnumerable Properties - { - get => _properties; - set => _properties = value; - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentItemDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentItemDisplay.cs deleted file mode 100644 index 045911d7f6df..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentItemDisplay.cs +++ /dev/null @@ -1,225 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using System.Text.Json.Serialization; -using Umbraco.Cms.Core.Routing; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public class ContentItemDisplay : ContentItemDisplay -{ -} - -public class ContentItemDisplayWithSchedule : ContentItemDisplay -{ -} - -/// -/// A model representing a content item to be displayed in the back office -/// -[DataContract(Name = "content", Namespace = "")] -public class ContentItemDisplay : - INotificationModel, - IErrorModel // ListViewAwareContentItemDisplayBase - where TVariant : ContentVariantDisplay -{ - public ContentItemDisplay() - { - AllowPreview = true; - Notifications = new List(); - Errors = new Dictionary(); - Variants = new List(); - } - - [DataMember(Name = "id", IsRequired = true)] - [Required] - public int Id { get; set; } - - [DataMember(Name = "udi")] - [ReadOnly(true)] - public Udi? Udi { get; set; } - - [DataMember(Name = "icon")] - public string? Icon { get; set; } - - [DataMember(Name = "trashed")] - [ReadOnly(true)] - public bool Trashed { get; set; } - - /// - /// This is the unique Id stored in the database - but could also be the unique id for a custom membership provider - /// - [DataMember(Name = "key")] - public Guid? Key { get; set; } - - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int? ParentId { get; set; } - - /// - /// The path of the entity - /// - [DataMember(Name = "path")] - public string? Path { get; set; } - - /// - /// A collection of content variants - /// - /// - /// If a content item is invariant, this collection will only contain one item, else it will contain all culture - /// variants - /// - [DataMember(Name = "variants")] - public IEnumerable Variants { get; set; } - - [DataMember(Name = "owner")] - public UserProfile? Owner { get; set; } - - [DataMember(Name = "updater")] - public UserProfile? Updater { get; set; } - - /// - /// The name of the content type - /// - [DataMember(Name = "contentTypeName")] - public string? ContentTypeName { get; set; } - - /// - /// Indicates if the content is configured as a list view container - /// - [DataMember(Name = "isContainer")] - public bool IsContainer { get; set; } - - /// - /// Indicates if the content is configured as an element - /// - [DataMember(Name = "isElement")] - public bool IsElement { get; set; } - - /// - /// Property indicating if this item is part of a list view parent - /// - [DataMember(Name = "isChildOfListView")] - public bool IsChildOfListView { get; set; } - - /// - /// Property for the entity's individual tree node URL - /// - /// - /// This is required if the item is a child of a list view since the tree won't actually be loaded, - /// so the app will need to go fetch the individual tree node in order to be able to load it's action list (menu) - /// - [DataMember(Name = "treeNodeUrl")] - public string? TreeNodeUrl { get; set; } - - [DataMember(Name = "contentTypeId")] - public int? ContentTypeId { get; set; } - - [DataMember(Name = "contentTypeKey")] - public Guid ContentTypeKey { get; set; } - - [DataMember(Name = "contentTypeAlias", IsRequired = true)] - [Required(AllowEmptyStrings = false)] - public string ContentTypeAlias { get; set; } = null!; - - [DataMember(Name = "sortOrder")] - public int SortOrder { get; set; } - - /// - /// This is the last updated date for the entire content object regardless of variants - /// - /// - /// Each variant has it's own update date assigned as well - /// - [DataMember(Name = "updateDate")] - public DateTime UpdateDate { get; set; } - - [DataMember(Name = "template")] - [JsonPropertyName("template")] - public string? TemplateAlias { get; set; } - - [DataMember(Name = "templateId")] - public int TemplateId { get; set; } - - [DataMember(Name = "allowedTemplates")] - public IDictionary? AllowedTemplates { get; set; } - - [DataMember(Name = "documentType")] - public ContentTypeBasic? DocumentType { get; set; } - - [DataMember(Name = "urls")] - public UrlInfo[]? Urls { get; set; } - - /// - /// Determines whether previewing is allowed for this node - /// - /// - /// By default this is true but by using events developers can toggle this off for certain documents if there is - /// nothing to preview - /// - [DataMember(Name = "allowPreview")] - public bool AllowPreview { get; set; } - - /// - /// The allowed 'actions' based on the user's permissions - Create, Update, Publish, Send to publish - /// - /// - /// Each char represents a button which we can then map on the front-end to the correct actions - /// - [DataMember(Name = "allowedActions")] - public IEnumerable? AllowedActions { get; set; } - - [DataMember(Name = "isBlueprint")] - public bool IsBlueprint { get; set; } - - /// - /// The real persisted content object - used during inbound model binding - /// - /// - /// This is not used for outgoing model information. - /// - [IgnoreDataMember] - public IContent? PersistedContent { get; set; } - - /// - /// The DTO object used to gather all required content data including data type information etc... for use with - /// validation - used during inbound model binding - /// - /// - /// We basically use this object to hydrate all required data from the database into one object so we can validate - /// everything we need - /// instead of having to look up all the data individually. - /// This is not used for outgoing model information. - /// - [IgnoreDataMember] - public ContentPropertyCollectionDto? ContentDto { get; set; } - - /// - /// A collection of extra data that is available for this specific entity/entity type - /// - [DataMember(Name = "metaData")] - [JsonPropertyName("metaData")] - [ReadOnly(true)] - public IDictionary AdditionalData { get; private set; } = new Dictionary(); - - /// - /// This is used for validation of a content item. - /// - /// - /// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will - /// still save the item but it cannot be published. So we need a way of returning validation errors as well as the - /// updated model. - /// NOTE: The ProperCase is important because when we return ModeState normally it will always be proper case. - /// - [DataMember(Name = "ModelState")] - [JsonPropertyName("ModelState")] - [ReadOnly(true)] - public IDictionary Errors { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - [ReadOnly(true)] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentItemDisplayBase.cs b/src/Umbraco.Core/Models/ContentEditing/ContentItemDisplayBase.cs deleted file mode 100644 index 1adf69371b54..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentItemDisplayBase.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public abstract class ContentItemDisplayBase : TabbedContentItem, INotificationModel, IErrorModel - where T : ContentPropertyBasic -{ - protected ContentItemDisplayBase() - { - Notifications = new List(); - Errors = new Dictionary(); - } - - /// - /// The name of the content type - /// - [DataMember(Name = "contentTypeName")] - public string? ContentTypeName { get; set; } - - /// - /// Indicates if the content is configured as a list view container - /// - [DataMember(Name = "isContainer")] - public bool IsContainer { get; set; } - - /// - /// This is used for validation of a content item. - /// - /// - /// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will - /// still save the item but it cannot be published. So we need a way of returning validation errors as well as the - /// updated model. - /// NOTE: The ProperCase is important because when we return ModeState normally it will always be proper case. - /// - [DataMember(Name = "ModelState")] - [ReadOnly(true)] - public IDictionary Errors { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - [ReadOnly(true)] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs b/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs deleted file mode 100644 index c1df9480cb31..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentItemSave.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Editors; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a content item to be saved -/// -[DataContract(Name = "content", Namespace = "")] -public class ContentItemSave : IContentSave -{ - public ContentItemSave() - { - Variants = new List(); - } - - [DataMember(Name = "id", IsRequired = true)] - [Required] - public int Id { get; set; } - - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int ParentId { get; set; } - - [DataMember(Name = "variants", IsRequired = true)] - public IEnumerable Variants { get; set; } - - [DataMember(Name = "contentTypeAlias", IsRequired = true)] - [Required(AllowEmptyStrings = false)] - public string ContentTypeAlias { get; set; } = null!; - - /// - /// The template alias to save - /// - [DataMember(Name = "templateAlias")] - public string? TemplateAlias { get; set; } - - #region IContentSave - - [DataMember(Name = "action", IsRequired = true)] - [Required] - public ContentSaveAction Action { get; set; } - - // These need explicit implementation because we are using internal models - - /// - [IgnoreDataMember] - IContent IContentSave.PersistedContent { get; set; } = null!; - - // Non explicit internal getter so we don't need to explicitly cast in our own code - [IgnoreDataMember] - public IContent PersistedContent - { - get => ((IContentSave)this).PersistedContent; - set => ((IContentSave)this).PersistedContent = value; - } - - #endregion -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs deleted file mode 100644 index c9ac6b2847f6..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyBasic.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a content property to be saved -/// -[DataContract(Name = "property", Namespace = "")] -public class ContentPropertyBasic -{ - /// - /// This is the PropertyData ID - /// - /// - /// This is not really used for anything - /// - [DataMember(Name = "id", IsRequired = true)] - [Required] - public int Id { get; set; } - - [DataMember(Name = "dataTypeKey", IsRequired = false)] - [ReadOnly(true)] - public Guid DataTypeKey { get; set; } - - [DataMember(Name = "value")] - public object? Value { get; set; } - - [DataMember(Name = "alias", IsRequired = true)] - [Required(AllowEmptyStrings = false)] - public string Alias { get; set; } = null!; - - [DataMember(Name = "editor", IsRequired = false)] - public string? Editor { get; set; } - - /// - /// Flags the property to denote that it can contain sensitive data - /// - [DataMember(Name = "isSensitive", IsRequired = false)] - public bool IsSensitive { get; set; } - - /// - /// The culture of the property - /// - /// - /// If this is a variant property then this culture value will be the same as it's variant culture but if this - /// is an invariant property then this will be a null value. - /// - [DataMember(Name = "culture")] - [ReadOnly(true)] - public string? Culture { get; set; } - - /// - /// The segment of the property - /// - /// - /// The segment value of a property can always be null but can only have a non-null value - /// when the property can be varied by segment. - /// - [DataMember(Name = "segment")] - [ReadOnly(true)] - public string? Segment { get; set; } - - /// - /// Used internally during model mapping - /// - [IgnoreDataMember] - public IDataEditor? PropertyEditor { get; set; } - - /// - /// Used internally during model mapping - /// - [DataMember(Name = "supportsReadOnly")] - [ReadOnly(true)] - public bool SupportsReadOnly { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyCollectionDto.cs b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyCollectionDto.cs deleted file mode 100644 index 35423f19a875..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyCollectionDto.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Used to map property values when saving content/media/members -/// -/// -/// This is only used during mapping operations, it is not used for angular purposes -/// -public class ContentPropertyCollectionDto : IContentProperties -{ - public ContentPropertyCollectionDto() => Properties = Enumerable.Empty(); - - public IEnumerable Properties { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs deleted file mode 100644 index 6b7e7a20acf4..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDisplay.cs +++ /dev/null @@ -1,36 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a content property that is displayed in the UI -/// -[DataContract(Name = "property", Namespace = "")] -public class ContentPropertyDisplay : ContentPropertyBasic -{ - public ContentPropertyDisplay() - { - Config = new Dictionary(); - Validation = new PropertyTypeValidation(); - } - - [DataMember(Name = "variations")] - public ContentVariation Variations { get; set; } - - [DataMember(Name = "label", IsRequired = true)] - [Required] - public string? Label { get; set; } - - [DataMember(Name = "description")] - public string? Description { get; set; } - - [DataMember(Name = "config")] - public IDictionary? Config { get; set; } - - [DataMember(Name = "validation")] - public PropertyTypeValidation Validation { get; set; } - - [DataMember(Name = "readonly")] - public bool Readonly { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDto.cs b/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDto.cs deleted file mode 100644 index b0045bb0381c..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentPropertyDto.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a content property from the database -/// -public class ContentPropertyDto : ContentPropertyBasic -{ - public IDataType? DataType { get; set; } - - public string? Label { get; set; } - - public string? Description { get; set; } - - public bool? IsRequired { get; set; } - - public bool? LabelOnTop { get; set; } - - public string? IsRequiredMessage { get; set; } - - public string? ValidationRegExp { get; set; } - - public string? ValidationRegExpMessage { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentRedirectUrl.cs b/src/Umbraco.Core/Models/ContentEditing/ContentRedirectUrl.cs deleted file mode 100644 index eef4e80976fb..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentRedirectUrl.cs +++ /dev/null @@ -1,26 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[Obsolete("Will be replace in new backoffice in V13, RedirectUrlViewModel will be used instead.")] -[DataContract(Name = "contentRedirectUrl", Namespace = "")] -public class ContentRedirectUrl -{ - [DataMember(Name = "redirectId")] - public Guid RedirectId { get; set; } - - [DataMember(Name = "originalUrl")] - public string? OriginalUrl { get; set; } - - [DataMember(Name = "destinationUrl")] - public string? DestinationUrl { get; set; } - - [DataMember(Name = "createDateUtc")] - public DateTime CreateDateUtc { get; set; } - - [DataMember(Name = "contentId")] - public int ContentId { get; set; } - - [DataMember(Name = "culture")] - public string? Culture { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentSaveAction.cs b/src/Umbraco.Core/Models/ContentEditing/ContentSaveAction.cs deleted file mode 100644 index 889b03db6d67..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentSaveAction.cs +++ /dev/null @@ -1,69 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The action associated with saving a content item -/// -public enum ContentSaveAction -{ - /// - /// Saves the content item, no publish - /// - Save = 0, - - /// - /// Creates a new content item - /// - SaveNew = 1, - - /// - /// Saves and publishes the content item - /// - Publish = 2, - - /// - /// Creates and publishes a new content item - /// - PublishNew = 3, - - /// - /// Saves and sends publish notification - /// - SendPublish = 4, - - /// - /// Creates and sends publish notification - /// - SendPublishNew = 5, - - /// - /// Saves and schedules publishing - /// - Schedule = 6, - - /// - /// Creates and schedules publishing - /// - ScheduleNew = 7, - - /// - /// Saves and publishes the content item including all descendants that have a published version - /// - PublishWithDescendants = 8, - - /// - /// Creates and publishes the content item including all descendants that have a published version - /// - PublishWithDescendantsNew = 9, - - /// - /// Saves and publishes the content item including all descendants regardless of whether they have a published version - /// or not - /// - PublishWithDescendantsForce = 10, - - /// - /// Creates and publishes the content item including all descendants regardless of whether they have a published - /// version or not - /// - PublishWithDescendantsForceNew = 11, -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentSavedState.cs b/src/Umbraco.Core/Models/ContentEditing/ContentSavedState.cs deleted file mode 100644 index 163514193485..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentSavedState.cs +++ /dev/null @@ -1,27 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The saved state of a content item -/// -public enum ContentSavedState -{ - /// - /// The item isn't created yet - /// - NotCreated = 1, - - /// - /// The item is saved but isn't published - /// - Draft = 2, - - /// - /// The item is published and there are no pending changes - /// - Published = 3, - - /// - /// The item is published and there are pending changes - /// - PublishedPendingChanges = 4, -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs b/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs deleted file mode 100644 index 17d751760d7a..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentSortOrder.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a new sort order for a content/media item -/// -[DataContract(Name = "content", Namespace = "")] -public class ContentSortOrder -{ - /// - /// The parent Id of the nodes being sorted - /// - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int ParentId { get; set; } - - /// - /// An array of integer Ids representing the sort order - /// - /// - /// Of course all of these Ids should be at the same level in the hierarchy!! - /// - [DataMember(Name = "idSortOrder", IsRequired = true)] - [Required] - public int[]? IdSortOrder { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypeBasic.cs deleted file mode 100644 index 488953d7b342..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypeBasic.cs +++ /dev/null @@ -1,111 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A basic version of a content type -/// -/// -/// Generally used to return the minimal amount of data about a content type -/// -[DataContract(Name = "contentType", Namespace = "")] -public class ContentTypeBasic : EntityBasic -{ - public ContentTypeBasic() - { - Blueprints = new Dictionary(); - Alias = string.Empty; - } - - /// - /// Overridden to apply our own validation attributes since this is not always required for other classes - /// - [Required] - [RegularExpression(@"^([a-zA-Z]\w.*)$", ErrorMessage = "Invalid alias")] - [DataMember(Name = "alias")] - public override string Alias { get; set; } - - [DataMember(Name = "updateDate")] - [ReadOnly(true)] - public DateTime UpdateDate { get; set; } - - [DataMember(Name = "createDate")] - [ReadOnly(true)] - public DateTime CreateDate { get; set; } - - [DataMember(Name = "description")] - public string? Description { get; set; } - - [DataMember(Name = "thumbnail")] - public string? Thumbnail { get; set; } - - [DataMember(Name = "variations")] - public ContentVariation Variations { get; set; } - - /// - /// Returns true if the icon represents a CSS class instead of a file path - /// - [DataMember(Name = "iconIsClass")] - [ReadOnly(true)] - public bool IconIsClass - { - get - { - if (Icon.IsNullOrWhiteSpace()) - { - return true; - } - - // if it starts with a '.' or doesn't contain a '.' at all then it is a class - return (Icon?.StartsWith(".") ?? false) || Icon?.Contains(".") == false; - } - } - - /// - /// Returns the icon file path if the icon is not a class, otherwise returns an empty string - /// - [DataMember(Name = "iconFilePath")] - [ReadOnly(true)] - public string? IconFilePath { get; set; } - - /// - /// Returns true if the icon represents a CSS class instead of a file path - /// - [DataMember(Name = "thumbnailIsClass")] - [ReadOnly(true)] - public bool ThumbnailIsClass - { - get - { - if (Thumbnail.IsNullOrWhiteSpace()) - { - return true; - } - - // if it starts with a '.' or doesn't contain a '.' at all then it is a class - return (Thumbnail?.StartsWith(".") ?? false) || Thumbnail?.Contains(".") == false; - } - } - - /// - /// Returns the icon file path if the icon is not a class, otherwise returns an empty string - /// - [DataMember(Name = "thumbnailFilePath")] - [ReadOnly(true)] - public string? ThumbnailFilePath { get; set; } - - [DataMember(Name = "blueprints")] - [ReadOnly(true)] - public IDictionary Blueprints { get; set; } - - [DataMember(Name = "listView")] - [ReadOnly(true)] - public Guid? ListView { get; set; } - - [DataMember(Name = "isElement")] - [ReadOnly(true)] - public bool IsElement { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypeCompositionDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypeCompositionDisplay.cs deleted file mode 100644 index 030923d29134..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypeCompositionDisplay.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public abstract class ContentTypeCompositionDisplay : ContentTypeBasic, INotificationModel -{ - protected ContentTypeCompositionDisplay() - { - // initialize collections so at least their never null - AllowedContentTypes = new List(); - CompositeContentTypes = new List(); - Notifications = new List(); - } - - // name, alias, icon, thumb, desc, inherited from basic - [DataMember(Name = "listViewEditorName")] - [ReadOnly(true)] - public string? ListViewEditorName { get; set; } - - // Allowed child types - [DataMember(Name = "allowedContentTypes")] - public IEnumerable? AllowedContentTypes { get; set; } - - // Compositions - [DataMember(Name = "compositeContentTypes")] - public IEnumerable CompositeContentTypes { get; set; } - - // Locked compositions - [DataMember(Name = "lockedCompositeContentTypes")] - public IEnumerable? LockedCompositeContentTypes { get; set; } - - [DataMember(Name = "allowAsRoot")] - public bool AllowAsRoot { get; set; } - - /// - /// This is used for validation of a content item. - /// - /// - /// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will - /// still save the item but it cannot be published. So we need a way of returning validation errors as well as the - /// updated model. - /// NOTE: The ProperCase is important because when we return ModeState normally it will always be proper case. - /// - [DataMember(Name = "ModelState")] - [ReadOnly(true)] - public IDictionary? Errors { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - [ReadOnly(true)] - public List Notifications { get; private set; } -} - -[DataContract(Name = "contentType", Namespace = "")] -public abstract class ContentTypeCompositionDisplay : ContentTypeCompositionDisplay - where TPropertyTypeDisplay : PropertyTypeDisplay -{ - protected ContentTypeCompositionDisplay() => - - // initialize collections so at least their never null - Groups = new List>(); - - // Tabs - [DataMember(Name = "groups")] - public IEnumerable> Groups { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypeSave.cs deleted file mode 100644 index d6ad7c7ba227..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypeSave.cs +++ /dev/null @@ -1,120 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Abstract model used to save content types -/// -[DataContract(Name = "contentType", Namespace = "")] -public abstract class ContentTypeSave : ContentTypeBasic, IValidatableObject -{ - protected ContentTypeSave() - { - AllowedContentTypes = new List(); - CompositeContentTypes = new List(); - } - - // Compositions - [DataMember(Name = "compositeContentTypes")] - public IEnumerable CompositeContentTypes { get; set; } - - [DataMember(Name = "allowAsRoot")] - public bool AllowAsRoot { get; set; } - - // Allowed child types - [DataMember(Name = "allowedContentTypes")] - public IEnumerable AllowedContentTypes { get; set; } - - [DataMember(Name = "historyCleanup")] - public HistoryCleanupViewModel? HistoryCleanup { get; set; } - - /// - /// Custom validation - /// - /// - /// - public virtual IEnumerable Validate(ValidationContext validationContext) - { - if (CompositeContentTypes.Any(x => x.IsNullOrWhiteSpace())) - { - yield return new ValidationResult( - "Composite Content Type value cannot be null", - new[] { "CompositeContentTypes" }); - } - } -} - -/// -/// Abstract model used to save content types -/// -/// -[DataContract(Name = "contentType", Namespace = "")] -public abstract class ContentTypeSave : ContentTypeSave - where TPropertyType : PropertyTypeBasic -{ - protected ContentTypeSave() => Groups = new List>(); - - /// - /// A rule for defining how a content type can be varied - /// - /// - /// This is only supported on document types right now but in the future it could be media types too - /// - [DataMember(Name = "allowCultureVariant")] - public bool AllowCultureVariant { get; set; } - - [DataMember(Name = "allowSegmentVariant")] - public bool AllowSegmentVariant { get; set; } - - // Tabs - [DataMember(Name = "groups")] - public IEnumerable> Groups { get; set; } - - /// - /// Custom validation - /// - /// - /// - public override IEnumerable Validate(ValidationContext validationContext) - { - foreach (ValidationResult validationResult in base.Validate(validationContext)) - { - yield return validationResult; - } - - foreach (IGrouping> duplicateGroupAlias in Groups - .GroupBy(x => x.Alias).Where(x => x.Count() > 1)) - { - var lastGroupIndex = Groups.IndexOf(duplicateGroupAlias.Last()); - yield return new ValidationResult("Duplicate aliases are not allowed: " + duplicateGroupAlias.Key, new[] - { - // TODO: We don't display the alias yet, so add the validation message to the name - $"Groups[{lastGroupIndex}].Name", - }); - } - - foreach (IGrouping<(string?, string? Name), PropertyGroupBasic> duplicateGroupName in Groups - .GroupBy(x => (x.GetParentAlias(), x.Name)).Where(x => x.Count() > 1)) - { - var lastGroupIndex = Groups.IndexOf(duplicateGroupName.Last()); - yield return new ValidationResult( - "Duplicate names are not allowed", - new[] { $"Groups[{lastGroupIndex}].Name" }); - } - - foreach (IGrouping duplicatePropertyAlias in Groups.SelectMany(x => x.Properties) - .GroupBy(x => x.Alias).Where(x => x.Count() > 1)) - { - TPropertyType lastProperty = duplicatePropertyAlias.Last(); - PropertyGroupBasic propertyGroup = Groups.Single(x => x.Properties.Contains(lastProperty)); - var lastPropertyIndex = propertyGroup.Properties.IndexOf(lastProperty); - var propertyGroupIndex = Groups.IndexOf(propertyGroup); - - yield return new ValidationResult( - "Duplicate property aliases not allowed: " + duplicatePropertyAlias.Key, - new[] { $"Groups[{propertyGroupIndex}].Properties[{lastPropertyIndex}].Alias" }); - } - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs deleted file mode 100644 index 476e772743a6..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByAliases.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model for retrieving multiple content types based on their aliases. -/// -[DataContract(Name = "contentTypes", Namespace = "")] -public class ContentTypesByAliases -{ - /// - /// Id of the parent of the content type. - /// - [DataMember(Name = "parentId")] - [Required] - public int ParentId { get; set; } - - /// - /// The alias of every content type to get. - /// - [DataMember(Name = "contentTypeAliases")] - [Required] - public string[]? ContentTypeAliases { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs b/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs deleted file mode 100644 index 2b728c04da79..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentTypesByKeys.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model for retrieving multiple content types based on their keys. -/// -[DataContract(Name = "contentTypes", Namespace = "")] -public class ContentTypesByKeys -{ - /// - /// ID of the parent of the content type. - /// - [DataMember(Name = "parentId")] - [Required] - public int ParentId { get; set; } - - /// - /// The id of every content type to get. - /// - [DataMember(Name = "contentTypeKeys")] - [Required] - public Guid[]? ContentTypeKeys { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentVariantSave.cs b/src/Umbraco.Core/Models/ContentEditing/ContentVariantSave.cs deleted file mode 100644 index ed9568590f08..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentVariantSave.cs +++ /dev/null @@ -1,69 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Validation; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "contentVariant", Namespace = "")] -public class ContentVariantSave : IContentProperties -{ - public ContentVariantSave() => Properties = new List(); - - [DataMember(Name = "name", IsRequired = true)] - [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] - [MaxLength(255, ErrorMessage = "Name must be less than 255 characters")] - public string? Name { get; set; } - - /// - /// The culture of this variant, if this is invariant than this is null or empty - /// - [DataMember(Name = "culture")] - public string? Culture { get; set; } - - /// - /// The segment of this variant, if this is invariant than this is null or empty - /// - [DataMember(Name = "segment")] - public string? Segment { get; set; } - - /// - /// Indicates if the variant should be updated - /// - /// - /// If this is false, this variant data will not be updated at all - /// - [DataMember(Name = "save")] - public bool Save { get; set; } - - /// - /// Indicates if the variant should be published - /// - /// - /// This option will have no affect if is false. - /// This is not used to unpublish. - /// - [DataMember(Name = "publish")] - public bool Publish { get; set; } - - [DataMember(Name = "expireDate")] - public DateTime? ExpireDate { get; set; } - - [DataMember(Name = "releaseDate")] - public DateTime? ReleaseDate { get; set; } - - /// - /// The property DTO object is used to gather all required property data including data type information etc... for use - /// with validation - used during inbound model binding - /// - /// - /// We basically use this object to hydrate all required data from the database into one object so we can validate - /// everything we need - /// instead of having to look up all the data individually. - /// This is not used for outgoing model information. - /// - [IgnoreDataMember] - public ContentPropertyCollectionDto? PropertyCollectionDto { get; set; } - - [DataMember(Name = "properties")] - public IEnumerable Properties { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs deleted file mode 100644 index 0d359b640f14..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ContentVariationDisplay.cs +++ /dev/null @@ -1,88 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents the variant info for a content item -/// -[DataContract(Name = "contentVariant", Namespace = "")] -public class ContentVariantDisplay : ITabbedContent, IContentProperties, INotificationModel -{ - public ContentVariantDisplay() - { - Tabs = new List>(); - Notifications = new List(); - AllowedActions = Enumerable.Empty(); - AdditionalPreviewUrls = Enumerable.Empty(); - } - - [DataMember(Name = "allowedActions", IsRequired = true)] - public IEnumerable AllowedActions { get; set; } - - [DataMember(Name = "name", IsRequired = true)] - public string? Name { get; set; } - - [DataMember(Name = "displayName")] - public string? DisplayName { get; set; } - - /// - /// The language/culture assigned to this content variation - /// - /// - /// If this is null it means this content variant is an invariant culture - /// - [DataMember(Name = "language")] - public Language? Language { get; set; } - - [DataMember(Name = "segment")] - public string? Segment { get; set; } - - [DataMember(Name = "state")] - public ContentSavedState State { get; set; } - - [DataMember(Name = "updateDate")] - public DateTime UpdateDate { get; set; } - - [DataMember(Name = "createDate")] - public DateTime CreateDate { get; set; } - - [DataMember(Name = "publishDate")] - public DateTime? PublishDate { get; set; } - - /// - /// Internal property used for tests to get all properties from all tabs - /// - [IgnoreDataMember] - IEnumerable IContentProperties.Properties => - Tabs.Where(x => x.Properties is not null).SelectMany(x => x.Properties!); - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - /// - /// The notifications assigned to a variant are currently only used to show custom messages in the save/publish - /// dialogs. - /// - [DataMember(Name = "notifications")] - [ReadOnly(true)] - public List Notifications { get; private set; } - - /// - /// Defines the tabs containing display properties - /// - [DataMember(Name = "tabs")] - public IEnumerable> Tabs { get; set; } - - [DataMember(Name = "additionalPreviewUrls")] - public IEnumerable AdditionalPreviewUrls { get; set; } -} - -public class ContentVariantScheduleDisplay : ContentVariantDisplay -{ - [DataMember(Name = "releaseDate")] - public DateTime? ReleaseDate { get; set; } - - [DataMember(Name = "expireDate")] - public DateTime? ExpireDate { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/CreatedDocumentTypeCollectionResult.cs b/src/Umbraco.Core/Models/ContentEditing/CreatedDocumentTypeCollectionResult.cs deleted file mode 100644 index a6f99ab58636..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/CreatedDocumentTypeCollectionResult.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The result of creating a content type collection in the UI -/// -[DataContract(Name = "contentTypeCollection", Namespace = "")] -public class CreatedContentTypeCollectionResult -{ - [DataMember(Name = "collectionId")] - public int CollectionId { get; set; } - - [DataMember(Name = "containerId")] - public int ContainerId { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs deleted file mode 100644 index c141ffd7f112..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeBasic.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The basic data type information -/// -[DataContract(Name = "dataType", Namespace = "")] -public class DataTypeBasic : EntityBasic -{ - /// - /// Whether or not this is a system data type, in which case it cannot be deleted - /// - [DataMember(Name = "isSystem")] - [ReadOnly(true)] - public bool IsSystemDataType { get; set; } - - [DataMember(Name = "hasPrevalues")] - [ReadOnly(true)] - public bool HasPrevalues { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs deleted file mode 100644 index edef88f2e7f6..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldDisplay.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a datatype configuration field model for editing. -/// -[DataContract(Name = "preValue", Namespace = "")] -public class DataTypeConfigurationFieldDisplay : DataTypeConfigurationFieldSave -{ - /// - /// This allows for custom configuration to be injected into the pre-value editor - /// - [DataMember(Name = "config")] - public IDictionary? Config { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldSave.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldSave.cs deleted file mode 100644 index 514f9b86187b..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeConfigurationFieldSave.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a datatype configuration field model for editing. -/// -[DataContract(Name = "preValue", Namespace = "")] -public class DataTypeConfigurationFieldSave -{ - /// - /// Gets or sets the configuration field key. - /// - [DataMember(Name = "key", IsRequired = true)] - public string Key { get; set; } = null!; - - /// - /// Gets or sets the configuration field value. - /// - [DataMember(Name = "value", IsRequired = true)] - public object? Value { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeDisplay.cs deleted file mode 100644 index 7f3c93d12653..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeDisplay.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a data type that is being edited -/// -[DataContract(Name = "dataType", Namespace = "")] -public class DataTypeDisplay : DataTypeBasic, INotificationModel -{ - public DataTypeDisplay() => Notifications = new List(); - - /// - /// The alias of the property editor - /// - [DataMember(Name = "selectedEditor", IsRequired = true)] - [Required] - public string? SelectedEditor { get; set; } - - [DataMember(Name = "availableEditors")] - public IEnumerable? AvailableEditors { get; set; } - - [DataMember(Name = "preValues")] - public IEnumerable? PreValues { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeHasValuesDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeHasValuesDisplay.cs deleted file mode 100644 index 4db43ad391eb..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeHasValuesDisplay.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "dataTypeHasValuesDisplay")] -public class DataTypeHasValuesDisplay -{ - public DataTypeHasValuesDisplay(int id, bool hasValues) - { - Id = id; - HasValues = hasValues; - } - - [DataMember(Name = "id")] - public int Id { get; } - - [DataMember(Name = "hasValues")] - public bool HasValues { get; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs deleted file mode 100644 index 3d6f0fabce81..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeReferences.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System.Runtime.Serialization; -using System.Xml.Linq; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "dataTypeReferences", Namespace = "")] -public class DataTypeReferences -{ - [DataMember(Name = "documentTypes")] - public IEnumerable DocumentTypes { get; set; } = Enumerable.Empty(); - - [DataMember(Name = "mediaTypes")] - public IEnumerable MediaTypes { get; set; } = Enumerable.Empty(); - - [DataMember(Name = "memberTypes")] - public IEnumerable MemberTypes { get; set; } = Enumerable.Empty(); - - [DataContract(Name = "contentType", Namespace = "")] - public class ContentTypeReferences : EntityBasic - { - [DataMember(Name = "properties")] - public object? Properties { get; set; } - - [DataMember(Name = "listViews")] - public object? ListViews { get; set; } - - [DataContract(Name = "property", Namespace = "")] - public class PropertyTypeReferences - { - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "alias")] - public string? Alias { get; set; } - } - - [DataContract(Name = "listView", Namespace = "")] - public class ListViewReferences - { - [DataMember(Name = "name")] - public string? Name { get; set; } - } - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs deleted file mode 100644 index 8968fb0795e2..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DataTypeSave.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.PropertyEditors; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a datatype model for editing. -/// -[DataContract(Name = "dataType", Namespace = "")] -public class DataTypeSave : EntityBasic -{ - /// - /// Gets or sets the action to perform. - /// - /// - /// Some values (publish) are illegal here. - /// - [DataMember(Name = "action", IsRequired = true)] - [Required] - public ContentSaveAction Action { get; set; } - - /// - /// Gets or sets the datatype editor. - /// - [DataMember(Name = "selectedEditor", IsRequired = true)] - [Required] - public string? EditorAlias { get; set; } - - /// - /// Gets or sets the datatype configuration fields. - /// - [DataMember(Name = "preValues")] - public IEnumerable? ConfigurationFields { get; set; } - - /// - /// Gets or sets the persisted data type. - /// - [IgnoreDataMember] - public IDataType? PersistedDataType { get; set; } - - /// - /// Gets or sets the property editor. - /// - [IgnoreDataMember] - public IDataEditor? PropertyEditor { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionaryDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DictionaryDisplay.cs deleted file mode 100644 index 91ff3afeb7c9..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DictionaryDisplay.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The dictionary display model -/// -[DataContract(Name = "dictionary", Namespace = "")] -public class DictionaryDisplay : EntityBasic, INotificationModel -{ - /// - /// Initializes a new instance of the class. - /// - public DictionaryDisplay() - { - Notifications = new List(); - Translations = new List(); - } - - /// - /// Gets or sets the parent id. - /// - [DataMember(Name = "parentId")] - public new Guid ParentId { get; set; } - - /// - /// Gets the translations. - /// - [DataMember(Name = "translations")] - public List Translations { get; private set; } - - /// - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewDisplay.cs deleted file mode 100644 index 15aab0c7ef62..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewDisplay.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The dictionary overview display. -/// -[DataContract(Name = "dictionary", Namespace = "")] -public class DictionaryOverviewDisplay -{ - /// - /// Initializes a new instance of the class. - /// - public DictionaryOverviewDisplay() => Translations = new List(); - - /// - /// Gets or sets the key. - /// - [DataMember(Name = "name")] - public string? Name { get; set; } - - /// - /// Gets or sets the id. - /// - [DataMember(Name = "id")] - public int Id { get; set; } - - /// - /// Gets or sets the level. - /// - [DataMember(Name = "level")] - public int Level { get; set; } - - /// - /// Gets or sets the translations. - /// - [DataMember(Name = "translations")] - public List Translations { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs deleted file mode 100644 index 9e534820fa4a..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DictionaryOverviewTranslationDisplay.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The dictionary translation overview display. -/// -[DataContract(Name = "dictionaryTranslation", Namespace = "")] -public class DictionaryOverviewTranslationDisplay -{ - /// - /// Gets or sets the display name. - /// - [DataMember(Name = "displayName")] - public string? DisplayName { get; set; } - - /// - /// Gets or sets a value indicating whether has translation. - /// - [DataMember(Name = "hasTranslation")] - public bool HasTranslation { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionarySave.cs b/src/Umbraco.Core/Models/ContentEditing/DictionarySave.cs deleted file mode 100644 index 85585c45ba16..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DictionarySave.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Dictionary Save model -/// -[DataContract(Name = "dictionary", Namespace = "")] -public class DictionarySave : EntityBasic -{ - /// - /// Initializes a new instance of the class. - /// - public DictionarySave() => Translations = new List(); - - /// - /// Gets or sets a value indicating whether name is dirty. - /// - [DataMember(Name = "nameIsDirty")] - public bool NameIsDirty { get; set; } - - /// - /// Gets the translations. - /// - [DataMember(Name = "translations")] - public List Translations { get; private set; } - - /// - /// Gets or sets the parent id. - /// - [DataMember(Name = "parentId")] - public new Guid ParentId { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationDisplay.cs deleted file mode 100644 index 70ab031538ec..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationDisplay.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// -/// The dictionary translation display model -/// -[DataContract(Name = "dictionaryTranslation", Namespace = "")] -public class DictionaryTranslationDisplay : DictionaryTranslationSave -{ - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "key")] - public Guid Key { get; set; } - - /// - /// Gets or sets the display name. - /// - [DataMember(Name = "displayName")] - public string? DisplayName { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs b/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs deleted file mode 100644 index cf58bcb2ec5a..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DictionaryTranslationSave.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The dictionary translation save model -/// -[DataContract(Name = "dictionaryTranslation", Namespace = "")] -public class DictionaryTranslationSave -{ - /// - /// Gets or sets the ISO code. - /// - [DataMember(Name = "isoCode")] - public string? IsoCode { get; set; } - - /// - /// Gets or sets the translation. - /// - [DataMember(Name = "translation")] - public string Translation { get; set; } = null!; - - /// - /// Gets or sets the language id. - /// - [DataMember(Name = "languageId")] - public int LanguageId { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs deleted file mode 100644 index 1029846b1c19..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeDisplay.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "contentType", Namespace = "")] -public class DocumentTypeDisplay : ContentTypeCompositionDisplay -{ - public DocumentTypeDisplay() => - - // initialize collections so at least their never null - AllowedTemplates = new List(); - - // name, alias, icon, thumb, desc, inherited from the content type - - // Templates - [DataMember(Name = "allowedTemplates")] - public IEnumerable AllowedTemplates { get; set; } - - [DataMember(Name = "variations")] - public ContentVariation Variations { get; set; } - - [DataMember(Name = "defaultTemplate")] - public EntityBasic? DefaultTemplate { get; set; } - - [DataMember(Name = "allowCultureVariant")] - public bool AllowCultureVariant { get; set; } - - [DataMember(Name = "allowSegmentVariant")] - public bool AllowSegmentVariant { get; set; } - - [DataMember(Name = "historyCleanup")] - public HistoryCleanupViewModel? HistoryCleanup { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs deleted file mode 100644 index af13e88f9b14..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DocumentTypeSave.cs +++ /dev/null @@ -1,42 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Model used to save a document type -/// -[DataContract(Name = "contentType", Namespace = "")] -public class DocumentTypeSave : ContentTypeSave -{ - /// - /// The list of allowed templates to assign (template alias) - /// - [DataMember(Name = "allowedTemplates")] - public IEnumerable? AllowedTemplates { get; set; } - - /// - /// The default template to assign (template alias) - /// - [DataMember(Name = "defaultTemplate")] - public string? DefaultTemplate { get; set; } - - /// - /// Custom validation - /// - /// - /// - public override IEnumerable Validate(ValidationContext validationContext) - { - if (AllowedTemplates?.Any(x => x.IsNullOrWhiteSpace()) ?? false) - { - yield return new ValidationResult("Template value cannot be null", new[] { "AllowedTemplates" }); - } - - foreach (ValidationResult v in base.Validate(validationContext)) - { - yield return v; - } - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DomainDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/DomainDisplay.cs deleted file mode 100644 index 7a6a58443858..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DomainDisplay.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "DomainDisplay")] -public class DomainDisplay -{ - public DomainDisplay(string name, int lang) - { - Name = name; - Lang = lang; - } - - [DataMember(Name = "name")] - public string Name { get; } - - [DataMember(Name = "lang")] - public int Lang { get; } - - [DataMember(Name = "duplicate")] - public bool Duplicate { get; set; } - - [DataMember(Name = "other")] - public string? Other { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs b/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs deleted file mode 100644 index 391616b8dcd5..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/DomainSave.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "DomainSave")] -public class DomainSave -{ - [DataMember(Name = "valid")] - public bool Valid { get; set; } - - [DataMember(Name = "nodeId")] - public int NodeId { get; set; } - - [DataMember(Name = "language")] - public int Language { get; set; } - - [DataMember(Name = "domains")] - public DomainDisplay[]? Domains { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs b/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs deleted file mode 100644 index 0920e45f2970..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/EditorNavigation.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing the navigation ("apps") inside an editor in the back office -/// -[DataContract(Name = "user", Namespace = "")] -public class EditorNavigation -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "alias")] - public string? Alias { get; set; } - - [DataMember(Name = "icon")] - public string? Icon { get; set; } - - [DataMember(Name = "view")] - public string? View { get; set; } - - [DataMember(Name = "active")] - public bool Active { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs b/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs deleted file mode 100644 index 62bce70f865a..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/EntityBasic.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Validation; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "entity", Namespace = "")] -public class EntityBasic -{ - public EntityBasic() - { - AdditionalData = new Dictionary(); - Alias = string.Empty; - Path = string.Empty; - } - - [DataMember(Name = "name", IsRequired = true)] - [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] - public string? Name { get; set; } - - [DataMember(Name = "id", IsRequired = true)] - [Required] - public object? Id { get; set; } - - [DataMember(Name = "udi")] - [ReadOnly(true)] - public Udi? Udi { get; set; } - - [DataMember(Name = "icon")] - public string? Icon { get; set; } - - [DataMember(Name = "trashed")] - [ReadOnly(true)] - public bool Trashed { get; set; } - - /// - /// This is the unique Id stored in the database - but could also be the unique id for a custom membership provider - /// - [DataMember(Name = "key")] - public Guid Key { get; set; } - - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int ParentId { get; set; } - - /// - /// This will only be populated for some entities - /// - /// - /// It is possible to override this to specify different validation attributes if required - /// - [DataMember(Name = "alias")] - public virtual string Alias { get; set; } - - /// - /// The path of the entity - /// - [DataMember(Name = "path")] - public string Path { get; set; } - - /// - /// A collection of extra data that is available for this specific entity/entity type - /// - [DataMember(Name = "metaData")] - [ReadOnly(true)] - public IDictionary AdditionalData { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/EntitySearchResults.cs b/src/Umbraco.Core/Models/ContentEditing/EntitySearchResults.cs deleted file mode 100644 index f345d881b6ba..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/EntitySearchResults.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Collections; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "searchResults", Namespace = "")] -public class EntitySearchResults : IEnumerable -{ - private readonly IEnumerable _results; - - public EntitySearchResults(IEnumerable results, long totalFound) - { - _results = results; - TotalResults = totalFound; - } - - [DataMember(Name = "totalResults")] - public long TotalResults { get; set; } - - public IEnumerator GetEnumerator() => _results.GetEnumerator(); - - IEnumerator IEnumerable.GetEnumerator() => ((IEnumerable)_results).GetEnumerator(); -} diff --git a/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs b/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs deleted file mode 100644 index 1860dc8feb3d..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/HistoryCleanupViewModel.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "historyCleanup", Namespace = "")] -public class HistoryCleanupViewModel : HistoryCleanup -{ - [DataMember(Name = "globalEnableCleanup")] - public bool GlobalEnableCleanup { get; set; } - - [DataMember(Name = "globalKeepAllVersionsNewerThanDays")] - public int? GlobalKeepAllVersionsNewerThanDays { get; set; } - - [DataMember(Name = "globalKeepLatestVersionPerDayForDays")] - public int? GlobalKeepLatestVersionPerDayForDays { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/IContentProperties.cs b/src/Umbraco.Core/Models/ContentEditing/IContentProperties.cs deleted file mode 100644 index 3520c078b19d..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/IContentProperties.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public interface IContentProperties - where T : ContentPropertyBasic -{ - IEnumerable Properties { get; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/IContentSave.cs b/src/Umbraco.Core/Models/ContentEditing/IContentSave.cs deleted file mode 100644 index d0dee2931d75..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/IContentSave.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// An interface exposes the shared parts of content, media, members that we use during model binding in order to share -/// logic -/// -/// -public interface IContentSave - where TPersisted : IContentBase -{ - /// - /// The action to perform when saving this content item - /// - ContentSaveAction Action { get; set; } - - /// - /// The real persisted content object - used during inbound model binding - /// - /// - /// This is not used for outgoing model information. - /// - TPersisted PersistedContent { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/IErrorModel.cs b/src/Umbraco.Core/Models/ContentEditing/IErrorModel.cs deleted file mode 100644 index 9607146eda43..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/IErrorModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public interface IErrorModel -{ - /// - /// This is used for validation of a content item. - /// - /// - /// A content item can be invalid but still be saved. This occurs when there's property validation errors, we will - /// still save the item but it cannot be published. So we need a way of returning validation errors as well as the - /// updated model. - /// - IDictionary Errors { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/INotificationModel.cs b/src/Umbraco.Core/Models/ContentEditing/INotificationModel.cs deleted file mode 100644 index 15b75a82cf82..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/INotificationModel.cs +++ /dev/null @@ -1,12 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public interface INotificationModel -{ - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - List? Notifications { get; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ITabbedContent.cs b/src/Umbraco.Core/Models/ContentEditing/ITabbedContent.cs deleted file mode 100644 index 13f7375c3d5a..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ITabbedContent.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public interface ITabbedContent - where T : ContentPropertyBasic -{ - IEnumerable> Tabs { get; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/Language.cs b/src/Umbraco.Core/Models/ContentEditing/Language.cs deleted file mode 100644 index 3c58dea942b9..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/Language.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using System.Text.Json.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "language", Namespace = "")] -public class Language -{ - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "culture", IsRequired = true)] - [JsonPropertyName("culture")] - [Required(AllowEmptyStrings = false)] - public string IsoCode { get; set; } = null!; - - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "isDefault")] - [JsonPropertyName("isDefault")] - public bool IsDefault { get; set; } - - [DataMember(Name = "isMandatory")] - [JsonPropertyName("isMandatory")] - public bool IsMandatory { get; set; } - - [DataMember(Name = "fallbackIsoCode")] - [JsonPropertyName("fallbackIsoCode")] - public string? FallbackIsoCode { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs b/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs deleted file mode 100644 index 1add8da7d851..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ListViewAwareContentItemDisplayBase.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// An abstract model representing a content item that can be contained in a list view -/// -/// -public abstract class ListViewAwareContentItemDisplayBase : ContentItemDisplayBase - where T : ContentPropertyBasic -{ - /// - /// Property indicating if this item is part of a list view parent - /// - [DataMember(Name = "isChildOfListView")] - public bool IsChildOfListView { get; set; } - - /// - /// Property for the entity's individual tree node URL - /// - /// - /// This is required if the item is a child of a list view since the tree won't actually be loaded, - /// so the app will need to go fetch the individual tree node in order to be able to load it's action list (menu) - /// - [DataMember(Name = "treeNodeUrl")] - public string? TreeNodeUrl { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MediaItemDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MediaItemDisplay.cs deleted file mode 100644 index 6ff449eec706..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MediaItemDisplay.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a media item to be displayed in the back office -/// -[DataContract(Name = "content", Namespace = "")] -public class MediaItemDisplay : ListViewAwareContentItemDisplayBase -{ - [DataMember(Name = "contentType")] - public ContentTypeBasic? ContentType { get; set; } - - [DataMember(Name = "mediaLink")] - public string? MediaLink { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MediaItemSave.cs b/src/Umbraco.Core/Models/ContentEditing/MediaItemSave.cs deleted file mode 100644 index 7bac43b25dcd..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MediaItemSave.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a media item to be saved -/// -[DataContract(Name = "content", Namespace = "")] -public class MediaItemSave : ContentBaseSave -{ -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MediaTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MediaTypeDisplay.cs deleted file mode 100644 index 899be9504057..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MediaTypeDisplay.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "contentType", Namespace = "")] -public class MediaTypeDisplay : ContentTypeCompositionDisplay -{ - [DataMember(Name = "isSystemMediaType")] - public bool IsSystemMediaType { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MediaTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/MediaTypeSave.cs deleted file mode 100644 index b3fdeea1e251..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MediaTypeSave.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Model used to save a media type -/// -[DataContract(Name = "contentType", Namespace = "")] -public class MediaTypeSave : ContentTypeSave -{ -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs b/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs deleted file mode 100644 index 49eaf51eb534..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberBasic.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Used for basic member information -/// -public class MemberBasic : ContentItemBasic -{ - [DataMember(Name = "username")] - public string? Username { get; set; } - - [DataMember(Name = "email")] - public string? Email { get; set; } - - [DataMember(Name = "failedPasswordAttempts")] - public int FailedPasswordAttempts { get; set; } - - [DataMember(Name = "approved")] - public bool Approved { get; set; } - - [DataMember(Name = "lockedOut")] - public bool LockedOut { get; set; } - - [DataMember(Name = "lastLockoutDate")] - public DateTime? LastLockoutDate { get; set; } - - [DataMember(Name = "lastLoginDate")] - public DateTime? LastLoginDate { get; set; } - - [DataMember(Name = "lastPasswordChangeDate")] - public DateTime? LastPasswordChangeDate { get; set; } - - [DataMember(Name = "properties")] - public override IEnumerable Properties - { - get => base.Properties; - set => base.Properties = value; - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MemberDisplay.cs deleted file mode 100644 index d4e95c343848..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberDisplay.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a member to be displayed in the back office -/// -[DataContract(Name = "content", Namespace = "")] -public class MemberDisplay : ListViewAwareContentItemDisplayBase -{ - - [DataMember(Name = "contentType")] - public ContentTypeBasic? ContentType { get; set; } - - [DataMember(Name = "username")] - public string? Username { get; set; } - - [DataMember(Name = "email")] - public string? Email { get; set; } - - [DataMember(Name = "isLockedOut")] - public bool IsLockedOut { get; set; } - - [DataMember(Name = "isApproved")] - public bool IsApproved { get; set; } - - [DataMember(Name = "membershipProperties")] - public IEnumerable? MembershipProperties { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberGroupDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MemberGroupDisplay.cs deleted file mode 100644 index 0804fd53d74e..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberGroupDisplay.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "memberGroup", Namespace = "")] -public class MemberGroupDisplay : EntityBasic, INotificationModel -{ - public MemberGroupDisplay() => Notifications = new List(); - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberGroupSave.cs b/src/Umbraco.Core/Models/ContentEditing/MemberGroupSave.cs deleted file mode 100644 index 292d410625d7..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberGroupSave.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "memberGroup", Namespace = "")] -public class MemberGroupSave : EntityBasic -{ -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs deleted file mode 100644 index e5cdcc404605..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberListDisplay.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a member list to be displayed in the back office -/// -[DataContract(Name = "content", Namespace = "")] -public class MemberListDisplay : ContentItemDisplayBase -{ -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeBasic.cs deleted file mode 100644 index 9ef0ebf3b987..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeBasic.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Basic member property type -/// -[DataContract(Name = "contentType", Namespace = "")] -public class MemberPropertyTypeBasic : PropertyTypeBasic -{ - [DataMember(Name = "showOnMemberProfile")] - public bool MemberCanViewProperty { get; set; } - - [DataMember(Name = "memberCanEdit")] - public bool MemberCanEditProperty { get; set; } - - [DataMember(Name = "isSensitiveData")] - public bool IsSensitiveData { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeDisplay.cs deleted file mode 100644 index 1038440974e8..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberPropertyTypeDisplay.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "propertyType")] -public class MemberPropertyTypeDisplay : PropertyTypeDisplay -{ - [DataMember(Name = "showOnMemberProfile")] - public bool MemberCanViewProperty { get; set; } - - [DataMember(Name = "memberCanEdit")] - public bool MemberCanEditProperty { get; set; } - - [DataMember(Name = "isSensitiveData")] - public bool IsSensitiveData { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs b/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs deleted file mode 100644 index a610b0f5757f..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberSave.cs +++ /dev/null @@ -1,51 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Validation; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -public class MemberSave : ContentBaseSave -{ - [DataMember(Name = "username", IsRequired = true)] - [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] - public string Username { get; set; } = null!; - - [DataMember(Name = "email", IsRequired = true)] - [RequiredForPersistence(AllowEmptyStrings = false, ErrorMessage = "Required")] - [EmailAddress] - public string Email { get; set; } = null!; - - [DataMember(Name = "password")] - public ChangingPasswordModel? Password { get; set; } - - [DataMember(Name = "memberGroups")] - public IEnumerable? Groups { get; set; } - - /// - /// Returns the value from the Comments property - /// - public string? Comments => GetPropertyValue(Constants.Conventions.Member.Comments); - - [DataMember(Name = "isLockedOut")] - public bool IsLockedOut { get; set; } - - [DataMember(Name = "isApproved")] - public bool IsApproved { get; set; } - - [DataMember(Name = "isTwoFactorEnabled")] - public bool IsTwoFactorEnabled { get; set; } - - private T? GetPropertyValue(string alias) - { - ContentPropertyBasic? prop = Properties.FirstOrDefault(x => x.Alias == alias); - if (prop == null) - { - return default; - } - - Attempt converted = prop.Value.TryConvertTo(); - return converted.Result ?? default; - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/MemberTypeDisplay.cs deleted file mode 100644 index ea8aa5c1e365..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberTypeDisplay.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "contentType", Namespace = "")] -public class MemberTypeDisplay : ContentTypeCompositionDisplay -{ -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MemberTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/MemberTypeSave.cs deleted file mode 100644 index 59a604749461..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MemberTypeSave.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Model used to save a member type -/// -public class MemberTypeSave : ContentTypeSave -{ -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MessagesExtensions.cs b/src/Umbraco.Core/Models/ContentEditing/MessagesExtensions.cs deleted file mode 100644 index 5a6511134570..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MessagesExtensions.cs +++ /dev/null @@ -1,80 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Extensions; - -public static class MessagesExtensions -{ - public static void AddNotification(this INotificationModel model, string header, string msg, NotificationStyle type) - { - if (model.Exists(header, msg, type)) - { - return; - } - - model.Notifications?.Add(new BackOfficeNotification { Header = header, Message = msg, NotificationType = type }); - } - - public static void AddSuccessNotification(this INotificationModel model, string header, string msg) - { - if (model.Exists(header, msg, NotificationStyle.Success)) - { - return; - } - - model.Notifications?.Add(new BackOfficeNotification - { - Header = header, - Message = msg, - NotificationType = NotificationStyle.Success, - }); - } - - public static void AddErrorNotification(this INotificationModel model, string? header, string msg) - { - if (model.Exists(header, msg, NotificationStyle.Error)) - { - return; - } - - model.Notifications?.Add(new BackOfficeNotification - { - Header = header, - Message = msg, - NotificationType = NotificationStyle.Error, - }); - } - - public static void AddWarningNotification(this INotificationModel model, string header, string msg) - { - if (model.Exists(header, msg, NotificationStyle.Warning)) - { - return; - } - - model.Notifications?.Add(new BackOfficeNotification - { - Header = header, - Message = msg, - NotificationType = NotificationStyle.Warning, - }); - } - - public static void AddInfoNotification(this INotificationModel model, string header, string msg) - { - if (model.Exists(header, msg, NotificationStyle.Info)) - { - return; - } - - model.Notifications?.Add(new BackOfficeNotification - { - Header = header, - Message = msg, - NotificationType = NotificationStyle.Info, - }); - } - - private static bool Exists(this INotificationModel model, string? header, string message, NotificationStyle notificationType) => model.Notifications?.Any(x => - (x.Header?.InvariantEquals(header) ?? false) && (x.Message?.InvariantEquals(message) ?? false) && - x.NotificationType == notificationType) ?? false; -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ModelWithNotifications.cs b/src/Umbraco.Core/Models/ContentEditing/ModelWithNotifications.cs deleted file mode 100644 index 56275bfb6cbe..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ModelWithNotifications.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A generic model supporting notifications, this is useful for returning any model type to include notifications from -/// api controllers -/// -/// -[DataContract(Name = "model", Namespace = "")] -public class ModelWithNotifications : INotificationModel -{ - public ModelWithNotifications(T value) - { - Value = value; - Notifications = new List(); - } - - /// - /// The generic value - /// - [DataMember(Name = "value")] - public T Value { get; private set; } - - /// - /// The notifications - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/MoveOrCopy.cs b/src/Umbraco.Core/Models/ContentEditing/MoveOrCopy.cs deleted file mode 100644 index ecbcc027f47b..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/MoveOrCopy.cs +++ /dev/null @@ -1,39 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A model representing a model for moving or copying -/// -[DataContract(Name = "content", Namespace = "")] -public class MoveOrCopy -{ - /// - /// The Id of the node to move or copy to - /// - [DataMember(Name = "parentId", IsRequired = true)] - [Required] - public int ParentId { get; set; } - - /// - /// The id of the node to move or copy - /// - [DataMember(Name = "id", IsRequired = true)] - [Required] - public int Id { get; set; } - - /// - /// Boolean indicating whether copying the object should create a relation to it's original - /// - [DataMember(Name = "relateToOriginal", IsRequired = true)] - [Required] - public bool RelateToOriginal { get; set; } - - /// - /// Boolean indicating whether copying the object should be recursive - /// - [DataMember(Name = "recursive", IsRequired = true)] - [Required] - public bool Recursive { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/NamedUrl.cs b/src/Umbraco.Core/Models/ContentEditing/NamedUrl.cs deleted file mode 100644 index 8c71f86cbfdf..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/NamedUrl.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "namedUrl", Namespace = "")] -public class NamedUrl -{ - [DataMember(Name = "name")] - public required string Name { get; set; } - - [DataMember(Name = "url")] - public required string Url { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/NotificationStyle.cs b/src/Umbraco.Core/Models/ContentEditing/NotificationStyle.cs deleted file mode 100644 index 1fe9e9b525eb..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/NotificationStyle.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract] -public enum NotificationStyle -{ - /// - /// Save icon - /// - Save = 0, - - /// - /// Info icon - /// - Info = 1, - - /// - /// Error icon - /// - Error = 2, - - /// - /// Success icon - /// - Success = 3, - - /// - /// Warning icon - /// - Warning = 4, -} diff --git a/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs b/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs deleted file mode 100644 index 603ec953b078..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/NotifySetting.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "notifySetting", Namespace = "")] -public class NotifySetting -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "checked")] - public bool Checked { get; set; } - - /// - /// The letter from the IAction - /// - [DataMember(Name = "notifyCode")] - public string? NotifyCode { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs b/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs deleted file mode 100644 index c2f69218b3b0..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/ObjectType.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "objectType", Namespace = "")] -public class ObjectType -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "id")] - public Guid Id { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/Permission.cs b/src/Umbraco.Core/Models/ContentEditing/Permission.cs deleted file mode 100644 index 9bdb664579f7..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/Permission.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "permission", Namespace = "")] -public class Permission : ICloneable -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "description")] - public string? Description { get; set; } - - [DataMember(Name = "checked")] - public bool Checked { get; set; } - - [DataMember(Name = "icon")] - public string? Icon { get; set; } - - /// - /// We'll use this to map the categories but it wont' be returned in the json - /// - [IgnoreDataMember] - public string Category { get; set; } = null!; - - /// - /// The letter from the IAction - /// - [DataMember(Name = "permissionCode")] - public string? PermissionCode { get; set; } - - public object Clone() => MemberwiseClone(); -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs b/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs deleted file mode 100644 index 79769559db24..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PostedFolder.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Used to create a folder with the MediaController -/// -[DataContract] -public class PostedFolder -{ - [DataMember(Name = "parentId")] - public string? ParentId { get; set; } - - [DataMember(Name = "name")] - public string? Name { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs deleted file mode 100644 index 3c132c0a840f..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyEditorBasic.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Defines an available property editor to be able to select for a data type -/// -[DataContract(Name = "propertyEditor", Namespace = "")] -public class PropertyEditorBasic -{ - [DataMember(Name = "alias")] - public string? Alias { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs deleted file mode 100644 index 5b45776a8e4a..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasic.cs +++ /dev/null @@ -1,62 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "propertyGroup", Namespace = "")] -public abstract class PropertyGroupBasic -{ - /// - /// Gets the special generic properties tab identifier. - /// - public const int GenericPropertiesGroupId = -666; - - /// - /// Gets a value indicating whether this tab is the generic properties tab. - /// - [IgnoreDataMember] - public bool IsGenericProperties => Id == GenericPropertiesGroupId; - - /// - /// Gets a value indicating whether the property group is inherited through - /// content types composition. - /// - /// - /// A property group can be inherited and defined on the content type - /// currently being edited, at the same time. Inherited is true when there exists at least - /// one property group higher in the composition, with the same alias. - /// - [DataMember(Name = "inherited")] - public bool Inherited { get; set; } - - // needed - so we can handle alias renames - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "key")] - public Guid Key { get; set; } - - [DataMember(Name = "type")] - public PropertyGroupType Type { get; set; } - - [Required] - [DataMember(Name = "name")] - public string? Name { get; set; } - - [Required] - [DataMember(Name = "alias")] - public string Alias { get; set; } = null!; - - [DataMember(Name = "sortOrder")] - public int SortOrder { get; set; } -} - -[DataContract(Name = "propertyGroup", Namespace = "")] -public class PropertyGroupBasic : PropertyGroupBasic - where TPropertyType : PropertyTypeBasic -{ - public PropertyGroupBasic() => Properties = new List(); - - [DataMember(Name = "properties")] - public IEnumerable Properties { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasicExtensions.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasicExtensions.cs deleted file mode 100644 index 4e3b530f99d4..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupBasicExtensions.cs +++ /dev/null @@ -1,7 +0,0 @@ -namespace Umbraco.Cms.Core.Models.ContentEditing; - -internal static class PropertyGroupBasicExtensions -{ - public static string? GetParentAlias(this PropertyGroupBasic propertyGroup) - => PropertyGroupExtensions.GetParentAlias(propertyGroup.Alias); -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyGroupDisplay.cs deleted file mode 100644 index 67a200cf65ee..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyGroupDisplay.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "propertyGroup", Namespace = "")] -public class PropertyGroupDisplay : PropertyGroupBasic - where TPropertyTypeDisplay : PropertyTypeDisplay -{ - public PropertyGroupDisplay() - { - Properties = new List(); - ParentTabContentTypeNames = new List(); - ParentTabContentTypes = new List(); - } - - /// - /// Gets the context content type. - /// - [DataMember(Name = "contentTypeId")] - [ReadOnly(true)] - public int ContentTypeId { get; set; } - - /// - /// Gets the identifiers of the content types that define this group. - /// - [DataMember(Name = "parentTabContentTypes")] - [ReadOnly(true)] - public IEnumerable ParentTabContentTypes { get; set; } - - /// - /// Gets the name of the content types that define this group. - /// - [DataMember(Name = "parentTabContentTypeNames")] - [ReadOnly(true)] - public IEnumerable ParentTabContentTypeNames { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs deleted file mode 100644 index 92eaf0007ea9..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeBasic.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "propertyType")] -public class PropertyTypeBasic -{ - /// - /// Gets a value indicating whether the property type is inherited through - /// content types composition. - /// - /// - /// Inherited is true when the property is defined by a content type - /// higher in the composition, and not by the content type currently being - /// edited. - /// - [DataMember(Name = "inherited")] - public bool Inherited { get; set; } - - // needed - so we can handle alias renames - [DataMember(Name = "id")] - public int Id { get; set; } - - [Required] - [RegularExpression(@"^([a-zA-Z]\w.*)$", ErrorMessage = "Invalid alias")] - [DataMember(Name = "alias")] - public string Alias { get; set; } = null!; - - [DataMember(Name = "description")] - public string? Description { get; set; } - - [DataMember(Name = "validation")] - public PropertyTypeValidation? Validation { get; set; } - - [DataMember(Name = "label")] - [Required] - public string Label { get; set; } = null!; - - [DataMember(Name = "sortOrder")] - public int SortOrder { get; set; } - - [DataMember(Name = "dataTypeId")] - [Required] - public int DataTypeId { get; set; } - - [DataMember(Name = "dataTypeKey")] - [ReadOnly(true)] - public Guid DataTypeKey { get; set; } - - [DataMember(Name = "dataTypeName")] - [ReadOnly(true)] - public string? DataTypeName { get; set; } - - // SD: Is this really needed ? - [DataMember(Name = "groupId")] - public int GroupId { get; set; } - - [DataMember(Name = "allowCultureVariant")] - public bool AllowCultureVariant { get; set; } - - [DataMember(Name = "allowSegmentVariant")] - public bool AllowSegmentVariant { get; set; } - - [DataMember(Name = "labelOnTop")] - public bool LabelOnTop { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeDisplay.cs deleted file mode 100644 index 926ea50106fa..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeDisplay.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "propertyType")] -public class PropertyTypeDisplay : PropertyTypeBasic -{ - [DataMember(Name = "editor")] - [ReadOnly(true)] - public string? Editor { get; set; } - - [DataMember(Name = "view")] - [ReadOnly(true)] - public string? View { get; set; } - - [DataMember(Name = "config")] - [ReadOnly(true)] - public IDictionary? Config { get; set; } - - /// - /// Gets a value indicating whether this property should be locked when editing. - /// - /// - /// This is used for built in properties like the default MemberType - /// properties that should not be editable from the backoffice. - /// - [DataMember(Name = "locked")] - [ReadOnly(true)] - public bool Locked { get; set; } - - /// - /// This is required for the UI editor to know if this particular property belongs to - /// an inherited item or the current item. - /// - [DataMember(Name = "contentTypeId")] - [ReadOnly(true)] - public int ContentTypeId { get; set; } - - /// - /// This is required for the UI editor to know which content type name this property belongs - /// to based on the property inheritance structure - /// - [DataMember(Name = "contentTypeName")] - [ReadOnly(true)] - public string? ContentTypeName { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeHasValuesDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeHasValuesDisplay.cs deleted file mode 100644 index 6b5094ab1cfd..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeHasValuesDisplay.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "propertyTypeHasValuesDisplay")] -public class PropertyTypeHasValuesDisplay -{ - public PropertyTypeHasValuesDisplay(string propertyTypeAlias, bool hasValues) - { - PropertyTypeAlias = propertyTypeAlias; - HasValues = hasValues; - } - - [DataMember(Name = "propertyTypeAlias")] - public string PropertyTypeAlias { get; } - - [DataMember(Name = "hasValues")] - public bool HasValues { get; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeValidation.cs b/src/Umbraco.Core/Models/ContentEditing/PropertyTypeValidation.cs deleted file mode 100644 index 76e9547c0769..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PropertyTypeValidation.cs +++ /dev/null @@ -1,22 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// An object representing the property type validation settings -/// -[DataContract(Name = "propertyValidation", Namespace = "")] -public class PropertyTypeValidation -{ - [DataMember(Name = "mandatory")] - public bool Mandatory { get; set; } - - [DataMember(Name = "mandatoryMessage")] - public string? MandatoryMessage { get; set; } - - [DataMember(Name = "pattern")] - public string? Pattern { get; set; } - - [DataMember(Name = "patternMessage")] - public string? PatternMessage { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs b/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs deleted file mode 100644 index 1c21aec0339e..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PublicAccess.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "publicAccess", Namespace = "")] -public class PublicAccess -{ - [DataMember(Name = "groups")] - public MemberGroupDisplay[]? Groups { get; set; } - - [DataMember(Name = "loginPage")] - public EntityBasic? LoginPage { get; set; } - - [DataMember(Name = "errorPage")] - public EntityBasic? ErrorPage { get; set; } - - [DataMember(Name = "members")] - public MemberDisplay[]? Members { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/PublishContent.cs b/src/Umbraco.Core/Models/ContentEditing/PublishContent.cs deleted file mode 100644 index ba6d8d2f6f74..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/PublishContent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Used to publish content and variants -/// -[DataContract(Name = "publish", Namespace = "")] -public class PublishContent -{ - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "cultures")] - public string[]? Cultures { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs b/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs deleted file mode 100644 index 8a1a8d91c924..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RedirectUrlSearchResults.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "redirectUrlSearchResult", Namespace = "")] -public class RedirectUrlSearchResult -{ - [DataMember(Name = "searchResults")] - public IEnumerable? SearchResults { get; set; } - - [DataMember(Name = "totalCount")] - public long TotalCount { get; set; } - - [DataMember(Name = "pageCount")] - public int PageCount { get; set; } - - [DataMember(Name = "currentPage")] - public int CurrentPage { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RelationDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/RelationDisplay.cs deleted file mode 100644 index d4cb9602517f..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RelationDisplay.cs +++ /dev/null @@ -1,50 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "relation", Namespace = "")] -public class RelationDisplay -{ - /// - /// Gets or sets the Parent Id of the Relation (Source). - /// - [DataMember(Name = "parentId")] - [ReadOnly(true)] - public int ParentId { get; set; } - - /// - /// Gets or sets the Parent Name of the relation (Source). - /// - [DataMember(Name = "parentName")] - [ReadOnly(true)] - public string? ParentName { get; set; } - - /// - /// Gets or sets the Child Id of the Relation (Destination). - /// - [DataMember(Name = "childId")] - [ReadOnly(true)] - public int ChildId { get; set; } - - /// - /// Gets or sets the Child Name of the relation (Destination). - /// - [DataMember(Name = "childName")] - [ReadOnly(true)] - public string? ChildName { get; set; } - - /// - /// Gets or sets the date when the Relation was created. - /// - [DataMember(Name = "createDate")] - [ReadOnly(true)] - public DateTime CreateDate { get; set; } - - /// - /// Gets or sets a comment for the Relation. - /// - [DataMember(Name = "comment")] - [ReadOnly(true)] - public string? Comment { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RelationTypeDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/RelationTypeDisplay.cs deleted file mode 100644 index b6168e13d501..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RelationTypeDisplay.cs +++ /dev/null @@ -1,59 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "relationType", Namespace = "")] -public class RelationTypeDisplay : EntityBasic, INotificationModel -{ - public RelationTypeDisplay() => Notifications = new List(); - - [DataMember(Name = "isSystemRelationType")] - public bool IsSystemRelationType { get; set; } - - /// - /// Gets or sets a boolean indicating whether the RelationType is Bidirectional (true) or Parent to Child (false) - /// - [DataMember(Name = "isBidirectional", IsRequired = true)] - public bool IsBidirectional { get; set; } - - /// - /// Gets or sets the Parents object type id - /// - /// Corresponds to the NodeObjectType in the umbracoNode table - [DataMember(Name = "parentObjectType", IsRequired = true)] - public Guid? ParentObjectType { get; set; } - - /// - /// Gets or sets the Parent's object type name. - /// - [DataMember(Name = "parentObjectTypeName")] - [ReadOnly(true)] - public string? ParentObjectTypeName { get; set; } - - /// - /// Gets or sets the Child's object type id - /// - /// Corresponds to the NodeObjectType in the umbracoNode table - [DataMember(Name = "childObjectType", IsRequired = true)] - public Guid? ChildObjectType { get; set; } - - /// - /// Gets or sets the Child's object type name. - /// - [DataMember(Name = "childObjectTypeName")] - [ReadOnly(true)] - public string? ChildObjectTypeName { get; set; } - - /// - /// Gets or sets a boolean indicating whether the RelationType should be returned in "Used by"-queries. - /// - [DataMember(Name = "isDependency", IsRequired = true)] - public bool IsDependency { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RelationTypeSave.cs b/src/Umbraco.Core/Models/ContentEditing/RelationTypeSave.cs deleted file mode 100644 index 910d2827f7d4..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RelationTypeSave.cs +++ /dev/null @@ -1,31 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "relationType", Namespace = "")] -public class RelationTypeSave : EntityBasic -{ - /// - /// Gets or sets a boolean indicating whether the RelationType is Bidirectional (true) or Parent to Child (false) - /// - [DataMember(Name = "isBidirectional", IsRequired = true)] - public bool IsBidirectional { get; set; } - - /// - /// Gets or sets the parent object type ID. - /// - [DataMember(Name = "parentObjectType", IsRequired = false)] - public Guid? ParentObjectType { get; set; } - - /// - /// Gets or sets the child object type ID. - /// - [DataMember(Name = "childObjectType", IsRequired = false)] - public Guid? ChildObjectType { get; set; } - - /// - /// Gets or sets a boolean indicating whether the RelationType should be returned in "Used by"-queries. - /// - [DataMember(Name = "isDependency", IsRequired = true)] - public bool IsDependency { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs deleted file mode 100644 index 782f34c88ced..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommand.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public enum RichTextEditorCommandMode -{ - Insert, - Selection, - All, -} - -[DataContract(Name = "richtexteditorcommand", Namespace = "")] -public class RichTextEditorCommand -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "alias")] - public string? Alias { get; set; } - - [DataMember(Name = "mode")] - public RichTextEditorCommandMode Mode { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommandMode.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommandMode.cs new file mode 100644 index 000000000000..fecbe62641a7 --- /dev/null +++ b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorCommandMode.cs @@ -0,0 +1,8 @@ +namespace Umbraco.Cms.Core.Models.ContentEditing; + +public enum RichTextEditorCommandMode +{ + Insert, + Selection, + All, +} diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs deleted file mode 100644 index b0e858136bfd..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorConfiguration.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "richtexteditorconfiguration", Namespace = "")] -public class RichTextEditorConfiguration -{ - [DataMember(Name = "plugins")] - public IEnumerable? Plugins { get; set; } - - [DataMember(Name = "commands")] - public IEnumerable? Commands { get; set; } - - [DataMember(Name = "validElements")] - public string? ValidElements { get; set; } - - [DataMember(Name = "inValidElements")] - public string? InvalidElements { get; set; } - - [DataMember(Name = "customConfig")] - public IDictionary? CustomConfig { get; set; } - - [DataMember(Name = "cloudApiKey")] - public string? CloudApiKey { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs b/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs deleted file mode 100644 index c35eb1e18c95..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RichTextEditorPlugin.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "richtexteditorplugin", Namespace = "")] -public class RichTextEditorPlugin -{ - [DataMember(Name = "name")] - public string? Name { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs b/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs deleted file mode 100644 index dfd4511aa168..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/RollbackVersion.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "rollbackVersion", Namespace = "")] -public class RollbackVersion -{ - [DataMember(Name = "versionId")] - public int VersionId { get; set; } - - [DataMember(Name = "versionDate")] - public DateTime? VersionDate { get; set; } - - [DataMember(Name = "versionAuthorId")] - public int VersionAuthorId { get; set; } - - [DataMember(Name = "versionAuthorName")] - public string? VersionAuthorName { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs b/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs deleted file mode 100644 index 8a7fc5360597..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/SearchResult.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "result", Namespace = "")] -public class SearchResult -{ - [DataMember(Name = "id")] - public string? Id { get; set; } - - [DataMember(Name = "score")] - public float Score { get; set; } - - [DataMember(Name = "fieldCount")] - public int FieldCount => Values?.Count ?? 0; - - [DataMember(Name = "values")] - public IReadOnlyDictionary>? Values { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/SearchResultEntity.cs b/src/Umbraco.Core/Models/ContentEditing/SearchResultEntity.cs deleted file mode 100644 index f86ffc232a95..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/SearchResultEntity.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "searchResult", Namespace = "")] -public class SearchResultEntity : EntityBasic -{ - /// - /// The score of the search result - /// - [DataMember(Name = "score")] - public float Score { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs b/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs deleted file mode 100644 index f847e6922e96..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/SearchResults.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "results", Namespace = "")] -public class SearchResults -{ - [DataMember(Name = "pageSize")] - public int PageSize { get; set; } - - [DataMember(Name = "totalRecords")] - public long TotalRecords { get; set; } - - [DataMember(Name = "results")] - public IEnumerable? Results { get; set; } - - public static SearchResults Empty() => new() { Results = Enumerable.Empty(), TotalRecords = 0 }; -} diff --git a/src/Umbraco.Core/Models/ContentEditing/Section.cs b/src/Umbraco.Core/Models/ContentEditing/Section.cs deleted file mode 100644 index 68d34822c389..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/Section.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a section (application) in the back office -/// -[DataContract(Name = "section", Namespace = "")] -public class Section -{ - [DataMember(Name = "name")] - public string Name { get; set; } = null!; - - [DataMember(Name = "alias")] - public string Alias { get; set; } = null!; - - /// - /// In some cases a custom route path can be specified so that when clicking on a section it goes to this - /// path instead of the normal dashboard path - /// - [DataMember(Name = "routePath")] - public string? RoutePath { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/SimpleNotificationModel.cs b/src/Umbraco.Core/Models/ContentEditing/SimpleNotificationModel.cs deleted file mode 100644 index 9fe429cf3fba..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/SimpleNotificationModel.cs +++ /dev/null @@ -1,24 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "notificationModel", Namespace = "")] -public class SimpleNotificationModel : INotificationModel -{ - public SimpleNotificationModel() => Notifications = new List(); - - public SimpleNotificationModel(params BackOfficeNotification[] notifications) => - Notifications = new List(notifications); - - /// - /// A default message - /// - [DataMember(Name = "message")] - public string? Message { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs deleted file mode 100644 index 48b3d71cacc1..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/SnippetDisplay.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "scriptFile", Namespace = "")] -public class SnippetDisplay -{ - [DataMember(Name = "name", IsRequired = true)] - public string? Name { get; set; } - - [DataMember(Name = "fileName", IsRequired = true)] - public string? FileName { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs b/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs deleted file mode 100644 index 6a8d7c14fe70..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/StyleSheet.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "stylesheet", Namespace = "")] -public class Stylesheet -{ - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "path")] - public string? Path { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs b/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs deleted file mode 100644 index f7af3d984fef..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/StylesheetRule.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "stylesheetRule", Namespace = "")] -public class StylesheetRule -{ - [DataMember(Name = "name")] - public string Name { get; set; } = null!; - - [DataMember(Name = "selector")] - public string Selector { get; set; } = null!; - - [DataMember(Name = "styles")] - public string Styles { get; set; } = null!; -} diff --git a/src/Umbraco.Core/Models/ContentEditing/Tab.cs b/src/Umbraco.Core/Models/ContentEditing/Tab.cs deleted file mode 100644 index ab1e92d340e8..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/Tab.cs +++ /dev/null @@ -1,37 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a tab in the UI -/// -[DataContract(Name = "tab", Namespace = "")] -public class Tab -{ - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "key")] - public Guid Key { get; set; } - - [DataMember(Name = "type")] - public string? Type { get; set; } - - [DataMember(Name = "active")] - public bool IsActive { get; set; } - - [DataMember(Name = "label")] - public string? Label { get; set; } - - [DataMember(Name = "alias")] - public string? Alias { get; set; } - - /// - /// The expanded state of the tab - /// - [DataMember(Name = "open")] - public bool Expanded { get; set; } = true; - - [DataMember(Name = "properties")] - public IEnumerable? Properties { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/TabbedContentItem.cs b/src/Umbraco.Core/Models/ContentEditing/TabbedContentItem.cs deleted file mode 100644 index c47424cdf0f9..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/TabbedContentItem.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -public abstract class TabbedContentItem : ContentItemBasic, ITabbedContent - where T : ContentPropertyBasic -{ - protected TabbedContentItem() => Tabs = new List>(); - - /// - /// Override the properties property to ensure we don't serialize this - /// and to simply return the properties based on the properties in the tabs collection - /// - /// - /// This property cannot be set - /// - [IgnoreDataMember] - public override IEnumerable Properties - { - get => Tabs.Where(x => x.Properties is not null).SelectMany(x => x.Properties!); - set => throw new NotImplementedException(); - } - - /// - /// Defines the tabs containing display properties - /// - [DataMember(Name = "tabs")] - public IEnumerable> Tabs { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/TemplateDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/TemplateDisplay.cs deleted file mode 100644 index b6dadcdc2a34..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/TemplateDisplay.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "template", Namespace = "")] -public class TemplateDisplay : INotificationModel -{ - [DataMember(Name = "id")] - public int Id { get; set; } - - [Required] - [DataMember(Name = "name")] - public string? Name { get; set; } - - [Required] - [DataMember(Name = "alias")] - public string Alias { get; set; } = string.Empty; - - [DataMember(Name = "key")] - public Guid Key { get; set; } - - [DataMember(Name = "content")] - public string? Content { get; set; } - - [DataMember(Name = "path")] - public string? Path { get; set; } - - [DataMember(Name = "virtualPath")] - public string? VirtualPath { get; set; } - - [DataMember(Name = "masterTemplateAlias")] - public string? MasterTemplateAlias { get; set; } - - [DataMember(Name = "isMasterTemplate")] - public bool IsMasterTemplate { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List? Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs b/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs deleted file mode 100644 index f1b3dea9b261..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/TreeSearchResult.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a search result by entity type -/// -[DataContract(Name = "searchResult", Namespace = "")] -public class TreeSearchResult -{ - [DataMember(Name = "appAlias")] - public string? AppAlias { get; set; } - - [DataMember(Name = "treeAlias")] - public string? TreeAlias { get; set; } - - /// - /// This is optional but if specified should be the name of an angular service to format the search result. - /// - [DataMember(Name = "jsSvc")] - public string? JsFormatterService { get; set; } - - /// - /// This is optional but if specified should be the name of a method on the jsSvc angular service to use, if not - /// specified than it will expect the method to be called `format(searchResult, appAlias, treeAlias)` - /// - [DataMember(Name = "jsMethod")] - public string? JsFormatterMethod { get; set; } - - [DataMember(Name = "results")] - public IEnumerable? Results { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs b/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs deleted file mode 100644 index cc77bf5dbfa1..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UnpublishContent.cs +++ /dev/null @@ -1,16 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Used to unpublish content and variants -/// -[DataContract(Name = "unpublish", Namespace = "")] -public class UnpublishContent -{ - [DataMember(Name = "id")] - public int Id { get; set; } - - [DataMember(Name = "cultures")] - public string[]? Cultures { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UrlAndAnchors.cs b/src/Umbraco.Core/Models/ContentEditing/UrlAndAnchors.cs deleted file mode 100644 index 1a732ed01762..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UrlAndAnchors.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "urlAndAnchors", Namespace = "")] -public class UrlAndAnchors -{ - public UrlAndAnchors(string url, IEnumerable anchorValues) - { - Url = url; - AnchorValues = anchorValues; - } - - [DataMember(Name = "url")] - public string Url { get; } - - [DataMember(Name = "anchorValues")] - public IEnumerable AnchorValues { get; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserBasic.cs b/src/Umbraco.Core/Models/ContentEditing/UserBasic.cs deleted file mode 100644 index 6d20e54bfa0e..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserBasic.cs +++ /dev/null @@ -1,65 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Membership; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// The user model used for paging and listing users in the UI -/// -[DataContract(Name = "user", Namespace = "")] -[ReadOnly(true)] -public class UserBasic : EntityBasic, INotificationModel -{ - public UserBasic() - { - Notifications = new List(); - UserGroups = new List(); - } - - [DataMember(Name = "username")] - public string? Username { get; set; } - - /// - /// The MD5 lowercase hash of the email which can be used by gravatar - /// - [DataMember(Name = "emailHash")] - public string? EmailHash { get; set; } - - [DataMember(Name = "lastLoginDate")] - public DateTime? LastLoginDate { get; set; } - - /// - /// Returns a list of different size avatars - /// - [DataMember(Name = "avatars")] - public string[]? Avatars { get; set; } - - [DataMember(Name = "userState")] - public UserState UserState { get; set; } - - [DataMember(Name = "culture", IsRequired = true)] - public string? Culture { get; set; } - - [DataMember(Name = "email", IsRequired = true)] - public string? Email { get; set; } - - /// - /// The list of group aliases assigned to the user - /// - [DataMember(Name = "userGroups")] - public IEnumerable UserGroups { get; set; } - - /// - /// This is an info flag to denote if this object is the equivalent of the currently logged in user - /// - [DataMember(Name = "isCurrentUser")] - [ReadOnly(true)] - public bool IsCurrentUser { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs b/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs deleted file mode 100644 index 38ec7281a4f8..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserDetail.cs +++ /dev/null @@ -1,68 +0,0 @@ -using System.ComponentModel; -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents information for the current user -/// -[DataContract(Name = "user", Namespace = "")] -public class UserDetail : UserProfile -{ - [DataMember(Name = "email", IsRequired = true)] - [Required] - public string? Email { get; set; } - - [DataMember(Name = "locale", IsRequired = true)] - [Required] - public string? Culture { get; set; } - - /// - /// The MD5 lowercase hash of the email which can be used by gravatar - /// - [DataMember(Name = "emailHash")] - public string? EmailHash { get; set; } - - [ReadOnly(true)] - [DataMember(Name = "userGroups")] - public string?[]? UserGroups { get; set; } - - /// - /// Gets/sets the number of seconds for the user's auth ticket to expire - /// - [DataMember(Name = "remainingAuthSeconds")] - public double SecondsUntilTimeout { get; set; } - - /// - /// The user's calculated start nodes based on the start nodes they have assigned directly to them and via the groups - /// they're assigned to - /// - [DataMember(Name = "startContentIds")] - public int[]? StartContentIds { get; set; } - - /// - /// The user's calculated start nodes based on the start nodes they have assigned directly to them and via the groups - /// they're assigned to - /// - [DataMember(Name = "startMediaIds")] - public int[]? StartMediaIds { get; set; } - - /// - /// Returns a list of different size avatars - /// - [DataMember(Name = "avatars")] - public string[]? Avatars { get; set; } - - /// - /// A list of sections the user is allowed to view. - /// - [DataMember(Name = "allowedSections")] - public IEnumerable? AllowedSections { get; set; } - - /// - /// A list of language culcure codes the user is allowed to view. - /// - [DataMember(Name = "allowedLanguageIds")] - public IEnumerable? AllowedLanguageIds { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/UserDisplay.cs deleted file mode 100644 index 4b300c17a928..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserDisplay.cs +++ /dev/null @@ -1,78 +0,0 @@ -using System.ComponentModel; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents a user that is being edited -/// -[DataContract(Name = "user", Namespace = "")] -[ReadOnly(true)] -public class UserDisplay : UserBasic -{ - public UserDisplay() - { - AvailableCultures = new Dictionary(); - StartContentIds = new List(); - StartMediaIds = new List(); - Navigation = new List(); - } - - [DataMember(Name = "navigation")] - [ReadOnly(true)] - public IEnumerable Navigation { get; set; } - - /// - /// Gets the available cultures (i.e. to populate a drop down) - /// The key is the culture stored in the database, the value is the Name - /// - [DataMember(Name = "availableCultures")] - public IDictionary AvailableCultures { get; set; } - - [DataMember(Name = "startContentIds")] - public IEnumerable StartContentIds { get; set; } - - [DataMember(Name = "startMediaIds")] - public IEnumerable StartMediaIds { get; set; } - - /// - /// If the password is reset on save, this value will be populated - /// - [DataMember(Name = "resetPasswordValue")] - [ReadOnly(true)] - public string? ResetPasswordValue { get; set; } - - /// - /// A readonly value showing the user's current calculated start content ids - /// - [DataMember(Name = "calculatedStartContentIds")] - [ReadOnly(true)] - public IEnumerable? CalculatedStartContentIds { get; set; } - - /// - /// A readonly value showing the user's current calculated start media ids - /// - [DataMember(Name = "calculatedStartMediaIds")] - [ReadOnly(true)] - public IEnumerable? CalculatedStartMediaIds { get; set; } - - [DataMember(Name = "failedPasswordAttempts")] - [ReadOnly(true)] - public int FailedPasswordAttempts { get; set; } - - [DataMember(Name = "lastLockoutDate")] - [ReadOnly(true)] - public DateTime? LastLockoutDate { get; set; } - - [DataMember(Name = "lastPasswordChangeDate")] - [ReadOnly(true)] - public DateTime? LastPasswordChangeDate { get; set; } - - [DataMember(Name = "createDate")] - [ReadOnly(true)] - public DateTime CreateDate { get; set; } - - [DataMember(Name = "updateDate")] - [ReadOnly(true)] - public DateTime UpdateDate { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserGroupBasic.cs b/src/Umbraco.Core/Models/ContentEditing/UserGroupBasic.cs deleted file mode 100644 index 578021447617..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserGroupBasic.cs +++ /dev/null @@ -1,47 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "userGroup", Namespace = "")] -public class UserGroupBasic : EntityBasic, INotificationModel -{ - public UserGroupBasic() - { - Notifications = new List(); - Languages = Enumerable.Empty(); - Sections = Enumerable.Empty
(); - } - - [DataMember(Name = "languages")] - public IEnumerable Languages { get; set; } - - [DataMember(Name = "sections")] - public IEnumerable
Sections { get; set; } - - [DataMember(Name = "contentStartNode")] - public EntityBasic? ContentStartNode { get; set; } - - [DataMember(Name = "mediaStartNode")] - public EntityBasic? MediaStartNode { get; set; } - - [DataMember(Name = "hasAccessToAllLanguages")] - public bool HasAccessToAllLanguages { get; set; } - - /// - /// The number of users assigned to this group - /// - [DataMember(Name = "userCount")] - public int UserCount { get; set; } - - /// - /// Is the user group a system group e.g. "Administrators", "Sensitive data" or "Translators" - /// - [DataMember(Name = "isSystemUserGroup")] - public bool IsSystemUserGroup { get; set; } - - /// - /// This is used to add custom localized messages/strings to the response for the app to use for localized UI purposes. - /// - [DataMember(Name = "notifications")] - public List Notifications { get; private set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserGroupDisplay.cs b/src/Umbraco.Core/Models/ContentEditing/UserGroupDisplay.cs deleted file mode 100644 index 30cca62c4a44..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserGroupDisplay.cs +++ /dev/null @@ -1,28 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "userGroup", Namespace = "")] -public class UserGroupDisplay : UserGroupBasic -{ - public UserGroupDisplay() - { - Users = Enumerable.Empty(); - AssignedPermissions = Enumerable.Empty(); - } - - [DataMember(Name = "users")] - public IEnumerable Users { get; set; } - - /// - /// The default permissions for the user group organized by permission group name - /// - [DataMember(Name = "defaultPermissions")] - public IDictionary>? DefaultPermissions { get; set; } - - /// - /// The assigned permissions for the user group organized by permission group name - /// - [DataMember(Name = "assignedPermissions")] - public IEnumerable AssignedPermissions { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserGroupPermissionsSave.cs b/src/Umbraco.Core/Models/ContentEditing/UserGroupPermissionsSave.cs deleted file mode 100644 index 1e648f949f35..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserGroupPermissionsSave.cs +++ /dev/null @@ -1,25 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Used to assign user group permissions to a content node -/// -[DataContract(Name = "contentPermission", Namespace = "")] -public class UserGroupPermissionsSave -{ - public UserGroupPermissionsSave() => AssignedPermissions = new Dictionary>(); - - // TODO: we should have an option to clear the permissions assigned to this node and instead just have them inherit - yes once we actually have inheritance! - [DataMember(Name = "contentId", IsRequired = true)] - [Required] - public int ContentId { get; set; } - - /// - /// A dictionary of permissions to assign, the key is the user group id - /// - [DataMember(Name = "permissions")] - public IDictionary> AssignedPermissions { get; set; } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserGroupSave.cs b/src/Umbraco.Core/Models/ContentEditing/UserGroupSave.cs deleted file mode 100644 index 72eadd3130c4..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserGroupSave.cs +++ /dev/null @@ -1,98 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.Membership; -using Umbraco.Cms.Core.Models.Membership.Permissions; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -[DataContract(Name = "userGroup", Namespace = "")] -public class UserGroupSave : EntityBasic, IValidatableObject -{ - /// - /// The action to perform when saving this user group - /// - /// - /// If either of the Publish actions are specified an exception will be thrown. - /// - [DataMember(Name = "action", IsRequired = true)] - [Required] - public ContentSaveAction Action { get; set; } - - [DataMember(Name = "alias", IsRequired = true)] - [Required] - public override string Alias { get; set; } = string.Empty; - - [DataMember(Name = "sections")] - public IEnumerable? Sections { get; set; } - - [DataMember(Name = "users")] - public IEnumerable? Users { get; set; } - - [DataMember(Name = "startContentId")] - public int? StartContentId { get; set; } - - [DataMember(Name = "startMediaId")] - public int? StartMediaId { get; set; } - - [DataMember(Name = "hasAccessToAllLanguages")] - public bool HasAccessToAllLanguages { get; set; } - - /// - /// A set of ad-hoc permissions provided by the frontend. - /// - /// - /// By default the server has no concept of what all of these strings mean, we simple store them and return them to the UI. - /// - public required ISet Permissions { get; set; } - - /// - /// A set of granular permissions - /// - public required ISet GranularPermissions { get; set; } - - /// - /// The assigned permissions for content - /// - /// - /// The key is the content id and the list is the list of letters (permission codes) to assign - /// - [DataMember(Name = "assignedPermissions")] - public IDictionary>? AssignedPermissions { get; set; } - - /// - /// The ids of allowed languages - /// - [DataMember(Name = "allowedLanguages")] - public IEnumerable? AllowedLanguages { get; set; } - - /// - /// The real persisted user group - /// - [IgnoreDataMember] - public IUserGroup? PersistedUserGroup { get; set; } - - public IEnumerable Validate(ValidationContext validationContext) - { - if (Permissions.Any(x => x.IsNullOrWhiteSpace()) || GranularPermissions.Any(x=>x.Permission.IsNullOrWhiteSpace())) - { - yield return new ValidationResult("A permission value cannot be null or empty", new[] { "Permissions" }); - } - - if (AssignedPermissions is not null) - { - foreach (KeyValuePair> assignedPermission in AssignedPermissions) - { - foreach (var permission in assignedPermission.Value) - { - if (permission.IsNullOrWhiteSpace()) - { - yield return new ValidationResult( - "A permission value cannot be null or empty", - new[] { "AssignedPermissions" }); - } - } - } - } - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs b/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs deleted file mode 100644 index 02a10b45afff..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserInvite.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents the data used to invite a user -/// -[DataContract(Name = "user", Namespace = "")] -public class UserInvite : EntityBasic, IValidatableObject -{ - [DataMember(Name = "userGroups")] - [Required] - public IEnumerable UserGroups { get; set; } = null!; - - [DataMember(Name = "email", IsRequired = true)] - [Required] - [EmailAddress] - public string Email { get; set; } = null!; - - [DataMember(Name = "username")] - public string? Username { get; set; } - - [DataMember(Name = "message")] - public string? Message { get; set; } - - public IEnumerable Validate(ValidationContext validationContext) - { - if (UserGroups.Any() == false) - { - yield return new ValidationResult( - "A user must be assigned to at least one group", - new[] { nameof(UserGroups) }); - } - - IOptionsSnapshot securitySettings = - validationContext.GetRequiredService>(); - - if (securitySettings.Value.UsernameIsEmail == false && Username.IsNullOrWhiteSpace()) - { - yield return new ValidationResult("A username cannot be empty", new[] { nameof(Username) }); - } - } -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserProfile.cs b/src/Umbraco.Core/Models/ContentEditing/UserProfile.cs deleted file mode 100644 index 441972e8bc15..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserProfile.cs +++ /dev/null @@ -1,21 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// A bare minimum structure that represents a user, usually attached to other objects -/// -[DataContract(Name = "user", Namespace = "")] -public class UserProfile : IComparable -{ - [DataMember(Name = "id", IsRequired = true)] - [Required] - public int UserId { get; set; } - - [DataMember(Name = "name", IsRequired = true)] - [Required] - public string? Name { get; set; } - - int IComparable.CompareTo(object? obj) => string.Compare(Name, ((UserProfile?)obj)?.Name, StringComparison.Ordinal); -} diff --git a/src/Umbraco.Core/Models/ContentEditing/UserSave.cs b/src/Umbraco.Core/Models/ContentEditing/UserSave.cs deleted file mode 100644 index e0a3d41d4fd6..000000000000 --- a/src/Umbraco.Core/Models/ContentEditing/UserSave.cs +++ /dev/null @@ -1,56 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models.ContentEditing; - -/// -/// Represents the data used to persist a user -/// -/// -/// This will be different from the model used to display a user and we don't want to "Overpost" data back to the -/// server, -/// and there will most likely be different bits of data required for updating passwords which will be different from -/// the -/// data used to display vs save -/// -[DataContract(Name = "user", Namespace = "")] -public class UserSave : EntityBasic, IValidatableObject -{ - [DataMember(Name = "changePassword", IsRequired = true)] - public ChangingPasswordModel? ChangePassword { get; set; } - - [DataMember(Name = "id", IsRequired = true)] - [Required] - public new int Id { get; set; } - - [DataMember(Name = "username", IsRequired = true)] - [Required] - public string Username { get; set; } = null!; - - [DataMember(Name = "culture", IsRequired = true)] - [Required] - public string Culture { get; set; } = null!; - - [DataMember(Name = "email", IsRequired = true)] - [Required] - [EmailAddress] - public string Email { get; set; } = null!; - - [DataMember(Name = "userGroups")] - [Required] - public IEnumerable UserGroups { get; set; } = null!; - - [DataMember(Name = "startContentIds")] - public int[]? StartContentIds { get; set; } - - [DataMember(Name = "startMediaIds")] - public int[]? StartMediaIds { get; set; } - - public IEnumerable Validate(ValidationContext validationContext) - { - if (UserGroups.Any() == false) - { - yield return new ValidationResult("A user must be assigned to at least one group", new[] { "UserGroups" }); - } - } -} diff --git a/src/Umbraco.Core/Models/ContentTypeImportModel.cs b/src/Umbraco.Core/Models/ContentTypeImportModel.cs deleted file mode 100644 index 5de62fcffa68..000000000000 --- a/src/Umbraco.Core/Models/ContentTypeImportModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Core.Models; - -[DataContract(Name = "contentTypeImportModel")] -public class ContentTypeImportModel : INotificationModel -{ - [DataMember(Name = "alias")] - public string? Alias { get; set; } - - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "tempFileName")] - public string? TempFileName { get; set; } - - [DataMember(Name = "notifications")] - public List Notifications { get; } = new(); -} diff --git a/src/Umbraco.Core/Models/DictionaryImportModel.cs b/src/Umbraco.Core/Models/DictionaryImportModel.cs deleted file mode 100644 index 2507a6a1ec46..000000000000 --- a/src/Umbraco.Core/Models/DictionaryImportModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models -{ - [DataContract(Name = "dictionaryImportModel")] - public class DictionaryImportModel - { - [DataMember(Name = "dictionaryItems")] - public List? DictionaryItems { get; set; } - - [DataMember(Name = "tempFileName")] - public string? TempFileName { get; set; } - } -} diff --git a/src/Umbraco.Core/Models/DictionaryPreviewImportModel.cs b/src/Umbraco.Core/Models/DictionaryPreviewImportModel.cs deleted file mode 100644 index 530d49b0139b..000000000000 --- a/src/Umbraco.Core/Models/DictionaryPreviewImportModel.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models -{ - [DataContract(Name = "dictionaryPreviewImportModel")] - public class DictionaryPreviewImportModel - { - [DataMember(Name = "name")] - public string? Name { get; set; } - - [DataMember(Name = "level")] - public int Level { get; set; } - } -} diff --git a/src/Umbraco.Core/Models/IMigrationEntry.cs b/src/Umbraco.Core/Models/IMigrationEntry.cs deleted file mode 100644 index 392eb17097c8..000000000000 --- a/src/Umbraco.Core/Models/IMigrationEntry.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Umbraco.Cms.Core.Models.Entities; -using Umbraco.Cms.Core.Semver; - -namespace Umbraco.Cms.Core.Models; - -public interface IMigrationEntry : IEntity, IRememberBeingDirty -{ - string? MigrationName { get; set; } - - SemVersion? Version { get; set; } -} diff --git a/src/Umbraco.Core/Models/IconModel.cs b/src/Umbraco.Core/Models/IconModel.cs deleted file mode 100644 index 8fd9005ac3ce..000000000000 --- a/src/Umbraco.Core/Models/IconModel.cs +++ /dev/null @@ -1,8 +0,0 @@ -namespace Umbraco.Cms.Core.Models; - -public class IconModel -{ - public string Name { get; set; } = null!; - - public string SvgString { get; set; } = null!; -} diff --git a/src/Umbraco.Core/Models/Mapping/AuditMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/AuditMapDefinition.cs deleted file mode 100644 index 02095596e779..000000000000 --- a/src/Umbraco.Core/Models/Mapping/AuditMapDefinition.cs +++ /dev/null @@ -1,22 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class AuditMapDefinition : IMapDefinition -{ - public void DefineMaps(IUmbracoMapper mapper) => - mapper.Define((source, context) => new AuditLog(), Map); - - // Umbraco.Code.MapAll -UserAvatars -UserName - private void Map(IAuditItem source, AuditLog target, MapperContext context) - { - target.UserId = source.UserId; - target.NodeId = source.Id; - target.Timestamp = source.CreateDate; - target.LogType = source.AuditType.ToString(); - target.EntityType = source.EntityType; - target.Comment = source.Comment; - target.Parameters = source.Parameters; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/CodeFileMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/CodeFileMapDefinition.cs deleted file mode 100644 index e9ba018f9ce0..000000000000 --- a/src/Umbraco.Core/Models/Mapping/CodeFileMapDefinition.cs +++ /dev/null @@ -1,98 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class CodeFileMapDefinition : IMapDefinition -{ - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new CodeFileDisplay(), Map); - - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new CodeFileDisplay(), Map); - - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new CodeFileDisplay(), Map); - - mapper.Define(Map); - mapper.Define(Map); - } - - // Umbraco.Code.MapAll -Trashed -Udi -Icon - private static void Map(IStylesheet source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = source.Path; - } - - // Umbraco.Code.MapAll -Trashed -Udi -Icon - private static void Map(IScript source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = source.Path; - } - - // Umbraco.Code.MapAll -Trashed -Udi -Icon - private static void Map(IPartialView source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = source.Path; - } - - // Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet - private static void Map(IPartialView source, CodeFileDisplay target, MapperContext context) - { - target.Content = source.Content; - target.Id = source.Id.ToString(); - target.Name = source.Name; - target.VirtualPath = source.VirtualPath; - } - - // Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet - private static void Map(IScript source, CodeFileDisplay target, MapperContext context) - { - target.Content = source.Content; - target.Id = source.Id.ToString(); - target.Name = source.Name; - target.VirtualPath = source.VirtualPath; - } - - // Umbraco.Code.MapAll -FileType -Notifications -Path -Snippet - private static void Map(IStylesheet source, CodeFileDisplay target, MapperContext context) - { - target.Content = source.Content; - target.Id = source.Id.ToString(); - target.Name = source.Name; - target.VirtualPath = source.VirtualPath; - } - - // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate - // Umbraco.Code.MapAll -Id -Key -Alias -Name -OriginalPath -Path - private static void Map(CodeFileDisplay source, IPartialView target, MapperContext context) - { - target.Content = source.Content; - target.VirtualPath = source.VirtualPath; - } - - // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate -GetFileContent - // Umbraco.Code.MapAll -Id -Key -Alias -Name -OriginalPath -Path - private static void Map(CodeFileDisplay source, IScript target, MapperContext context) - { - target.Content = source.Content; - target.VirtualPath = source.VirtualPath; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/CommonMapper.cs b/src/Umbraco.Core/Models/Mapping/CommonMapper.cs index 868b25f73ddb..e78dbabe6fe2 100644 --- a/src/Umbraco.Core/Models/Mapping/CommonMapper.cs +++ b/src/Umbraco.Core/Models/Mapping/CommonMapper.cs @@ -1,44 +1,22 @@ using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; using Umbraco.Cms.Core.Models.Membership; using Umbraco.Cms.Core.Services; using Umbraco.Extensions; -using UserProfile = Umbraco.Cms.Core.Models.ContentEditing.UserProfile; namespace Umbraco.Cms.Core.Models.Mapping; public class CommonMapper { - private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; - private readonly ILocalizedTextService _localizedTextService; private readonly IUserService _userService; - public CommonMapper( - IUserService userService, - IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - ILocalizedTextService localizedTextService) + public CommonMapper(IUserService userService) { _userService = userService; - _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider; - _localizedTextService = localizedTextService; } - public UserProfile? GetOwner(IContentBase source, MapperContext context) - { - IProfile? profile = source.GetCreatorProfile(_userService); - return profile == null ? null : context.Map(profile); - } + public string? GetOwnerName(IContentBase source, MapperContext context) + => source.GetCreatorProfile(_userService)?.Name; - public UserProfile? GetCreator(IContent source, MapperContext context) - { - IProfile? profile = source.GetWriterProfile(_userService); - return profile == null ? null : context.Map(profile); - } - - public ContentTypeBasic? GetContentType(IContentBase source, MapperContext context) - { - IContentTypeComposition? contentType = _contentTypeBaseServiceProvider.GetContentTypeOf(source); - ContentTypeBasic? contentTypeBasic = context.Map(contentType); - return contentTypeBasic; - } + public string? GetCreatorName(IContent source, MapperContext context) + => source.GetWriterProfile(_userService)?.Name; } diff --git a/src/Umbraco.Core/Models/Mapping/ContentPropertyBasicMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentPropertyBasicMapper.cs deleted file mode 100644 index 9cda25fbbb84..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentPropertyBasicMapper.cs +++ /dev/null @@ -1,96 +0,0 @@ -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// Creates a base generic ContentPropertyBasic from a Property -/// -internal class ContentPropertyBasicMapper - where TDestination : ContentPropertyBasic, new() -{ - private readonly IEntityService _entityService; - private readonly ILogger> _logger; - private readonly PropertyEditorCollection _propertyEditors; - - public ContentPropertyBasicMapper( - IDataTypeService dataTypeService, - IEntityService entityService, - ILogger> logger, - PropertyEditorCollection propertyEditors) - { - _logger = logger; - _propertyEditors = propertyEditors; - DataTypeService = dataTypeService; - _entityService = entityService; - } - - protected IDataTypeService DataTypeService { get; } - - /// - /// Assigns the PropertyEditor, Id, Alias and Value to the property - /// - /// - public virtual void Map(IProperty property, TDestination dest, MapperContext context) - { - IDataEditor? editor = property.PropertyType is not null ? _propertyEditors[property.PropertyType.PropertyEditorAlias] : null; - if (editor == null) - { - _logger.LogError( - new NullReferenceException("The property editor with alias " + - property.PropertyType?.PropertyEditorAlias + " does not exist"), - "No property editor '{PropertyEditorAlias}' found, converting to a Label", - property.PropertyType?.PropertyEditorAlias); - - editor = _propertyEditors[Constants.PropertyEditors.Aliases.Label]; - - if (editor == null) - { - throw new InvalidOperationException( - $"Could not resolve the property editor {Constants.PropertyEditors.Aliases.Label}"); - } - } - - dest.Id = property.Id; - dest.Alias = property.Alias; - dest.PropertyEditor = editor; - dest.Editor = editor.Alias; - dest.SupportsReadOnly = editor.SupportsReadOnly; - dest.DataTypeKey = property.PropertyType!.DataTypeKey; - - // if there's a set of property aliases specified, we will check if the current property's value should be mapped. - // if it isn't one of the ones specified in 'includeProperties', we will just return the result without mapping the Value. - var includedProperties = context.GetIncludedProperties(); - if (includedProperties != null && !includedProperties.Contains(property.Alias)) - { - return; - } - - // Get the culture from the context which will be set during the mapping operation for each property - var culture = context.GetCulture(); - - // a culture needs to be in the context for a property type that can vary - if (culture == null && property.PropertyType.VariesByCulture()) - { - throw new InvalidOperationException( - $"No culture found in mapping operation when one is required for the culture variant property type {property.PropertyType.Alias}"); - } - - // set the culture to null if it's an invariant property type - culture = !property.PropertyType.VariesByCulture() ? null : culture; - - dest.Culture = culture; - - // Get the segment, which is always allowed to be null even if the propertyType *can* be varied by segment. - // There is therefore no need to perform the null check like with culture above. - var segment = !property.PropertyType.VariesBySegment() ? null : context.GetSegment(); - dest.Segment = segment; - - // if no 'IncludeProperties' were specified or this property is set to be included - we will map the value and return. - dest.Value = editor.GetValueEditor().ToEditor(property, culture, segment); - } -} diff --git a/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs deleted file mode 100644 index 41e350bf623a..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentPropertyDisplayMapper.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Dictionary; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// Creates a ContentPropertyDisplay from a Property -/// -internal class ContentPropertyDisplayMapper : ContentPropertyBasicMapper -{ - private readonly ICultureDictionary _cultureDictionary; - private readonly ILocalizedTextService _textService; - - public ContentPropertyDisplayMapper( - ICultureDictionary cultureDictionary, - IDataTypeService dataTypeService, - IEntityService entityService, - ILocalizedTextService textService, - ILogger logger, - PropertyEditorCollection propertyEditors) - : base(dataTypeService, entityService, logger, propertyEditors) - { - _cultureDictionary = cultureDictionary; - _textService = textService; - } - - public override void Map(IProperty originalProp, ContentPropertyDisplay dest, MapperContext context) - { - base.Map(originalProp, dest, context); - - // v13 to v14 merge note: because of changes in the IDataType we can not use the optimized IDataTypeConfigurationCache here - // todo: make sure this (possible) performance degradation isn't serious - IDataType? dataType = DataTypeService.GetDataType(originalProp.PropertyType.DataTypeId); - - // TODO: IDataValueEditor configuration - general issue - // GetValueEditor() returns a non-configured IDataValueEditor - // - for richtext and nested, configuration determines HideLabel, so we need to configure the value editor - // - could configuration also determines ValueType, everywhere? - // - does it make any sense to use a IDataValueEditor without configuring it? - - // set the display properties after mapping - dest.Alias = originalProp.Alias; - dest.Description = originalProp.PropertyType?.Description; - dest.Label = originalProp.PropertyType?.Name; - - // Set variation, the frontend needs this to determine if the content varies by segment - dest.Variations = originalProp.PropertyType?.Variations ?? ContentVariation.Nothing; - - // add the validation information - dest.Validation.Mandatory = originalProp.PropertyType?.Mandatory ?? false; - dest.Validation.MandatoryMessage = originalProp.PropertyType?.MandatoryMessage; - dest.Validation.Pattern = originalProp.PropertyType?.ValidationRegExp; - dest.Validation.PatternMessage = originalProp.PropertyType?.ValidationRegExpMessage; - - if (dest.PropertyEditor != null) - { - // let the property editor format the pre-values - if (dataType != null) - { - dest.Config = dest.PropertyEditor.GetConfigurationEditor().ToValueEditor(dataType.ConfigurationData); - } - } - - // Translate - dest.Label = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Label); - dest.Description = _textService.UmbracoDictionaryTranslate(_cultureDictionary, dest.Description); - } -} diff --git a/src/Umbraco.Core/Models/Mapping/ContentPropertyDtoMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentPropertyDtoMapper.cs deleted file mode 100644 index 5836317b5c33..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentPropertyDtoMapper.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// Creates a ContentPropertyDto from a Property -/// -internal class ContentPropertyDtoMapper : ContentPropertyBasicMapper -{ - public ContentPropertyDtoMapper(IDataTypeService dataTypeService, IEntityService entityService, ILogger logger, PropertyEditorCollection propertyEditors) - : base(dataTypeService, entityService, logger, propertyEditors) - { - } - - public override void Map(IProperty property, ContentPropertyDto dest, MapperContext context) - { - base.Map(property, dest, context); - - dest.IsRequired = property.PropertyType.Mandatory; - dest.IsRequiredMessage = property.PropertyType.MandatoryMessage; - dest.ValidationRegExp = property.PropertyType.ValidationRegExp; - dest.ValidationRegExpMessage = property.PropertyType.ValidationRegExpMessage; - dest.Description = property.PropertyType.Description; - dest.Label = property.PropertyType.Name; - dest.DataType = DataTypeService.GetDataType(property.PropertyType.DataTypeId); - dest.LabelOnTop = property.PropertyType.LabelOnTop; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs deleted file mode 100644 index 42eebd29e24a..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentPropertyMapDefinition.cs +++ /dev/null @@ -1,171 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.Dictionary; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// A mapper which declares how to map content properties. These mappings are shared among media (and probably members) -/// which is -/// why they are in their own mapper -/// -public class ContentPropertyMapDefinition : IMapDefinition -{ - private readonly ContentPropertyBasicMapper _contentPropertyBasicConverter; - private readonly ContentPropertyDisplayMapper _contentPropertyDisplayMapper; - private readonly ContentPropertyDtoMapper _contentPropertyDtoConverter; - private readonly CommonMapper _commonMapper; - private readonly ContentBasicSavedStateMapper _basicStateMapper; - - - public ContentPropertyMapDefinition( - ICultureDictionary cultureDictionary, - IDataTypeService dataTypeService, - IEntityService entityService, - ILocalizedTextService textService, - ILoggerFactory loggerFactory, - PropertyEditorCollection propertyEditors, - CommonMapper commonMapper) - { - _commonMapper = commonMapper; - _basicStateMapper = new ContentBasicSavedStateMapper(); - _contentPropertyBasicConverter = new ContentPropertyBasicMapper( - dataTypeService, - entityService, - loggerFactory.CreateLogger>(), - propertyEditors); - _contentPropertyDtoConverter = new ContentPropertyDtoMapper( - dataTypeService, - entityService, - loggerFactory.CreateLogger(), - propertyEditors); - _contentPropertyDisplayMapper = new ContentPropertyDisplayMapper( - cultureDictionary, - dataTypeService, - entityService, - textService, - loggerFactory.CreateLogger(), - propertyEditors); - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define>( - (source, context) => new Tab(), Map); - mapper.Define((source, context) => new ContentPropertyBasic(), Map); - mapper.Define((source, context) => new ContentPropertyDto(), Map); - mapper.Define((source, context) => new ContentPropertyDisplay(), Map); - mapper.Define>((source, context) => new ContentItemBasic(), Map); - mapper.Define((source, context) => new ContentPropertyCollectionDto(), Map); - } - - // Umbraco.Code.MapAll -Properties -Alias -Expanded - private void Map(PropertyGroup source, Tab target, MapperContext mapper) - { - target.Id = source.Id; - target.Key = source.Key; - target.Type = source.Type.ToString(); - target.Label = source.Name; - target.Alias = source.Alias; - target.IsActive = true; - } - - private void Map(IProperty source, ContentPropertyBasic target, MapperContext context) => - - // assume this is mapping everything and no MapAll is required - _contentPropertyBasicConverter.Map(source, target, context); - - private void Map(IProperty source, ContentPropertyDto target, MapperContext context) => - - // assume this is mapping everything and no MapAll is required - _contentPropertyDtoConverter.Map(source, target, context); - - private void Map(IProperty source, ContentPropertyDisplay target, MapperContext context) => - - // assume this is mapping everything and no MapAll is required - _contentPropertyDisplayMapper.Map(source, target, context); - - // Umbraco.Code.MapAll -Alias - private void Map(IContent source, ContentItemBasic target, MapperContext context) - { - target.ContentTypeId = source.ContentType.Id; - target.ContentTypeAlias = source.ContentType.Alias; - target.CreateDate = source.CreateDate; - target.Edited = source.Edited; - target.Icon = source.ContentType.Icon; - target.Id = source.Id; - target.Key = source.Key; - target.Name = GetName(source, context); - target.Owner = _commonMapper.GetOwner(source, context); - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Properties = context.MapEnumerable(source.Properties).WhereNotNull(); - target.SortOrder = source.SortOrder; - target.State = _basicStateMapper.Map(source, context); - target.Trashed = source.Trashed; - target.Udi = - Udi.Create(source.Blueprint ? Constants.UdiEntityType.DocumentBlueprint : Constants.UdiEntityType.Document, source.Key); - target.UpdateDate = GetUpdateDate(source, context); - target.Updater = _commonMapper.GetCreator(source, context); - target.VariesByCulture = source.ContentType.VariesByCulture(); - } - - // Umbraco.Code.MapAll - private static void Map(IContent source, ContentPropertyCollectionDto target, MapperContext context) => - target.Properties = context.MapEnumerable(source.Properties).WhereNotNull(); - - private string? GetName(IContent source, MapperContext context) - { - // invariant = only 1 name - if (!source.ContentType.VariesByCulture()) - { - return source.Name; - } - - // variant = depends on culture - var culture = context.GetCulture(); - - // if there's no culture here, the issue is somewhere else (UI, whatever) - throw! - if (culture == null) - { - throw new InvalidOperationException("Missing culture in mapping options."); - } - - // if we don't have a name for a culture, it means the culture is not available, and - // hey we should probably not be mapping it, but it's too late, return a fallback name - return source.CultureInfos is not null && - source.CultureInfos.TryGetValue(culture, out ContentCultureInfos name) && !name.Name.IsNullOrWhiteSpace() - ? name.Name - : $"({source.Name})"; - } - - private DateTime GetUpdateDate(IContent source, MapperContext context) - { - // invariant = global date - if (!source.ContentType.VariesByCulture()) - { - return source.UpdateDate; - } - - // variant = depends on culture - var culture = context.GetCulture(); - - // if there's no culture here, the issue is somewhere else (UI, whatever) - throw! - if (culture == null) - { - throw new InvalidOperationException("Missing culture in mapping options."); - } - - // if we don't have a date for a culture, it means the culture is not available, and - // hey we should probably not be mapping it, but it's too late, return a fallback date - DateTime? date = source.GetUpdateDate(culture); - return date ?? source.UpdateDate; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/ContentSavedStateMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentSavedStateMapper.cs deleted file mode 100644 index ba06dae711e9..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentSavedStateMapper.cs +++ /dev/null @@ -1,83 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// Returns the for an item -/// -/// -public class ContentBasicSavedStateMapper - where T : ContentPropertyBasic -{ - private readonly ContentSavedStateMapper _inner = new(); - - public ContentSavedState? Map(IContent source, MapperContext context) => _inner.Map(source, context); -} - -/// -/// Returns the for an item -/// -/// -public class ContentSavedStateMapper - where T : ContentPropertyBasic -{ - public ContentSavedState Map(IContent source, MapperContext context) - { - PublishedState publishedState; - bool isEdited; - bool isCreated; - - if (source.ContentType.VariesByCulture()) - { - // Get the culture from the context which will be set during the mapping operation for each variant - var culture = context.GetCulture(); - - // a culture needs to be in the context for a variant content item - if (culture == null) - { - throw new InvalidOperationException( - "No culture found in mapping operation when one is required for a culture variant"); - } - - publishedState = - source.PublishedState == - PublishedState - .Unpublished // if the entire document is unpublished, then flag every variant as unpublished - ? PublishedState.Unpublished - : source.IsCulturePublished(culture) - ? PublishedState.Published - : PublishedState.Unpublished; - - isEdited = source.IsCultureEdited(culture); - isCreated = source.Id > 0 && source.IsCultureAvailable(culture); - } - else - { - publishedState = source.PublishedState == PublishedState.Unpublished - ? PublishedState.Unpublished - : PublishedState.Published; - - isEdited = source.Edited; - isCreated = source.Id > 0; - } - - if (!isCreated) - { - return ContentSavedState.NotCreated; - } - - if (publishedState == PublishedState.Unpublished) - { - return ContentSavedState.Draft; - } - - if (publishedState == PublishedState.Published) - { - return isEdited ? ContentSavedState.PublishedPendingChanges : ContentSavedState.Published; - } - - throw new NotSupportedException($"PublishedState {publishedState} is not supported."); - } -} diff --git a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs deleted file mode 100644 index 81341e7e9e2c..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentTypeMapDefinition.cs +++ /dev/null @@ -1,929 +0,0 @@ -using System.Globalization; -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Exceptions; -using Umbraco.Cms.Core.Hosting; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// Defines mappings for content/media/members type mappings -/// -public class ContentTypeMapDefinition : IMapDefinition -{ - private readonly CommonMapper _commonMapper; - private readonly IContentTypeService _contentTypeService; - private readonly IDataTypeService _dataTypeService; - private readonly IFileService _fileService; - private readonly GlobalSettings _globalSettings; - private readonly IHostingEnvironment _hostingEnvironment; - private readonly ILogger _logger; - private readonly ILoggerFactory _loggerFactory; - private readonly IMediaTypeService _mediaTypeService; - private readonly IMemberTypeService _memberTypeService; - private readonly PropertyEditorCollection _propertyEditors; - private readonly IShortStringHelper _shortStringHelper; - private ContentSettings _contentSettings; - - public ContentTypeMapDefinition(CommonMapper commonMapper, PropertyEditorCollection propertyEditors, - IDataTypeService dataTypeService, IFileService fileService, - IContentTypeService contentTypeService, IMediaTypeService mediaTypeService, - IMemberTypeService memberTypeService, - ILoggerFactory loggerFactory, IShortStringHelper shortStringHelper, IOptions globalSettings, - IHostingEnvironment hostingEnvironment, IOptionsMonitor contentSettings) - { - _commonMapper = commonMapper; - _propertyEditors = propertyEditors; - _dataTypeService = dataTypeService; - _fileService = fileService; - _contentTypeService = contentTypeService; - _mediaTypeService = mediaTypeService; - _memberTypeService = memberTypeService; - _loggerFactory = loggerFactory; - _logger = _loggerFactory.CreateLogger(); - _shortStringHelper = shortStringHelper; - _globalSettings = globalSettings.Value; - _hostingEnvironment = hostingEnvironment; - - _contentSettings = contentSettings.CurrentValue; - contentSettings.OnChange(x => _contentSettings = x); - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define( - (source, context) => new ContentType(_shortStringHelper, source.ParentId), Map); - mapper.Define( - (source, context) => new MediaType(_shortStringHelper, source.ParentId), Map); - mapper.Define( - (source, context) => new MemberType(_shortStringHelper, source.ParentId), Map); - - mapper.Define((source, context) => new DocumentTypeDisplay(), Map); - mapper.Define((source, context) => new MediaTypeDisplay(), Map); - mapper.Define((source, context) => new MemberTypeDisplay(), Map); - - mapper.Define( - (source, context) => - { - IDataType? dataType = _dataTypeService.GetDataType(source.DataTypeId); - if (dataType == null) - { - throw new NullReferenceException("No data type found with id " + source.DataTypeId); - } - - return new PropertyType(_shortStringHelper, dataType, source.Alias); - }, - Map); - - // TODO: isPublishing in ctor? - mapper.Define, PropertyGroup>( - (source, context) => new PropertyGroup(false), Map); - mapper.Define, PropertyGroup>( - (source, context) => new PropertyGroup(false), Map); - - mapper.Define((source, context) => new ContentTypeBasic(), Map); - mapper.Define((source, context) => new ContentTypeBasic(), Map); - mapper.Define((source, context) => new ContentTypeBasic(), Map); - mapper.Define((source, context) => new ContentTypeBasic(), Map); - - mapper.Define((source, context) => new DocumentTypeDisplay(), Map); - mapper.Define((source, context) => new MediaTypeDisplay(), Map); - mapper.Define((source, context) => new MemberTypeDisplay(), Map); - - mapper.Define, PropertyGroupDisplay>( - (source, context) => new PropertyGroupDisplay(), Map); - mapper.Define, PropertyGroupDisplay>( - (source, context) => new PropertyGroupDisplay(), Map); - - mapper.Define((source, context) => new PropertyTypeDisplay(), Map); - mapper.Define( - (source, context) => new MemberPropertyTypeDisplay(), Map); - } - - public static Udi? MapContentTypeUdi(IContentTypeComposition source) - { - if (source == null) - { - return null; - } - - string udiType; - switch (source) - { - case IMemberType _: - udiType = Constants.UdiEntityType.MemberType; - break; - case IMediaType _: - udiType = Constants.UdiEntityType.MediaType; - break; - case IContentType _: - udiType = Constants.UdiEntityType.DocumentType; - break; - default: - throw new PanicException($"Source is of type {source.GetType()} which isn't supported here"); - } - - return Udi.Create(udiType, source.Key); - } - - // no MapAll - take care - private void Map(DocumentTypeSave source, IContentType target, MapperContext context) - { - MapSaveToTypeBase(source, target, context); - MapComposition(source, target, alias => _contentTypeService.Get(alias)); - - MapHistoryCleanup(source, target); - - target.AllowedTemplates = source.AllowedTemplates? - .Where(x => x != null) - .Select(_fileService.GetTemplate) - .WhereNotNull() - .ToArray(); - - target.SetDefaultTemplate(source.DefaultTemplate == null - ? null - : _fileService.GetTemplate(source.DefaultTemplate)); - } - - private static void MapHistoryCleanup(DocumentTypeSave source, IContentType target) - { - // If source history cleanup is null we don't have to map all properties - if (source.HistoryCleanup is null) - { - target.HistoryCleanup = null; - return; - } - - // We need to reset the dirty properties, because it is otherwise true, just because the json serializer has set properties - target.HistoryCleanup!.ResetDirtyProperties(false); - if (target.HistoryCleanup.PreventCleanup != source.HistoryCleanup.PreventCleanup) - { - target.HistoryCleanup.PreventCleanup = source.HistoryCleanup.PreventCleanup; - } - - if (target.HistoryCleanup.KeepAllVersionsNewerThanDays != source.HistoryCleanup.KeepAllVersionsNewerThanDays) - { - target.HistoryCleanup.KeepAllVersionsNewerThanDays = source.HistoryCleanup.KeepAllVersionsNewerThanDays; - } - - if (target.HistoryCleanup.KeepLatestVersionPerDayForDays != - source.HistoryCleanup.KeepLatestVersionPerDayForDays) - { - target.HistoryCleanup.KeepLatestVersionPerDayForDays = source.HistoryCleanup.KeepLatestVersionPerDayForDays; - } - } - - // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate - // Umbraco.Code.MapAll -SupportsPublishing -Key -PropertyEditorAlias -ValueStorageType -Variations - private static void Map(PropertyTypeBasic source, IPropertyType target, MapperContext context) - { - target.Name = source.Label; - target.DataTypeId = source.DataTypeId; - target.DataTypeKey = source.DataTypeKey; - target.Mandatory = source.Validation?.Mandatory ?? false; - target.MandatoryMessage = source.Validation?.MandatoryMessage; - target.ValidationRegExp = source.Validation?.Pattern; - target.ValidationRegExpMessage = source.Validation?.PatternMessage; - target.SetVariesBy(ContentVariation.Culture, source.AllowCultureVariant); - target.SetVariesBy(ContentVariation.Segment, source.AllowSegmentVariant); - - if (source.Id > 0) - { - target.Id = source.Id; - } - - if (source.GroupId > 0) - { - if (target.PropertyGroupId?.Value != source.GroupId) - { - target.PropertyGroupId = new Lazy(() => source.GroupId, false); - } - } - - target.Alias = source.Alias; - target.Description = source.Description; - target.SortOrder = source.SortOrder; - target.LabelOnTop = source.LabelOnTop; - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate -Key -PropertyTypes - private static void Map(PropertyGroupBasic source, PropertyGroup target, MapperContext context) - { - if (source.Id > 0) - { - target.Id = source.Id; - } - - target.Key = source.Key; - target.Type = source.Type; - target.Name = source.Name; - target.Alias = source.Alias; - target.SortOrder = source.SortOrder; - } - - // no MapAll - take care - private void Map(MediaTypeSave source, IMediaType target, MapperContext context) - { - MapSaveToTypeBase(source, target, context); - MapComposition(source, target, alias => _mediaTypeService.Get(alias)); - } - - // no MapAll - take care - private void Map(MemberTypeSave source, IMemberType target, MapperContext context) - { - MapSaveToTypeBase(source, target, context); - MapComposition(source, target, alias => _memberTypeService.Get(alias)); - - foreach (MemberPropertyTypeBasic propertyType in source.Groups.SelectMany(x => x.Properties)) - { - MemberPropertyTypeBasic localCopy = propertyType; - IPropertyType? destProp = - target.PropertyTypes.SingleOrDefault(x => x.Alias?.InvariantEquals(localCopy.Alias) ?? false); - if (destProp == null) - { - continue; - } - - target.SetMemberCanEditProperty(localCopy.Alias, localCopy.MemberCanEditProperty); - target.SetMemberCanViewProperty(localCopy.Alias, localCopy.MemberCanViewProperty); - target.SetIsSensitiveProperty(localCopy.Alias, localCopy.IsSensitiveData); - } - } - - // no MapAll - take care - private void Map(IContentType source, DocumentTypeDisplay target, MapperContext context) - { - MapTypeToDisplayBase(source, target); - - if (source is IContentType sourceWithHistoryCleanup) - { - target.HistoryCleanup = new HistoryCleanupViewModel - { - PreventCleanup = sourceWithHistoryCleanup.HistoryCleanup?.PreventCleanup ?? false, - KeepAllVersionsNewerThanDays = - sourceWithHistoryCleanup.HistoryCleanup?.KeepAllVersionsNewerThanDays, - KeepLatestVersionPerDayForDays = - sourceWithHistoryCleanup.HistoryCleanup?.KeepLatestVersionPerDayForDays, - GlobalKeepAllVersionsNewerThanDays = - _contentSettings.ContentVersionCleanupPolicy.KeepAllVersionsNewerThanDays, - GlobalKeepLatestVersionPerDayForDays = - _contentSettings.ContentVersionCleanupPolicy.KeepLatestVersionPerDayForDays, - GlobalEnableCleanup = _contentSettings.ContentVersionCleanupPolicy.EnableCleanup - }; - } - - target.AllowCultureVariant = source.VariesByCulture(); - target.AllowSegmentVariant = source.VariesBySegment(); - target.Variations = source.Variations; - - // sync templates - if (source.AllowedTemplates is not null) - { - target.AllowedTemplates = - context.MapEnumerable(source.AllowedTemplates).WhereNotNull(); - } - - if (source.DefaultTemplate != null) - { - target.DefaultTemplate = context.Map(source.DefaultTemplate); - } - - // default listview - target.ListViewEditorName = Constants.Conventions.DataTypes.ListViewPrefix + "Content"; - - if (string.IsNullOrEmpty(source.Alias)) - { - return; - } - - var name = Constants.Conventions.DataTypes.ListViewPrefix + source.Alias; - if (_dataTypeService.GetDataType(name) != null) - { - target.ListViewEditorName = name; - } - } - - // no MapAll - take care - private void Map(IMediaType source, MediaTypeDisplay target, MapperContext context) - { - MapTypeToDisplayBase(source, target); - - // default listview - target.ListViewEditorName = Constants.Conventions.DataTypes.ListViewPrefix + "Media"; - target.IsSystemMediaType = source.IsSystemMediaType(); - - if (string.IsNullOrEmpty(source.Name)) - { - return; - } - - var name = Constants.Conventions.DataTypes.ListViewPrefix + source.Name; - if (_dataTypeService.GetDataType(name) != null) - { - target.ListViewEditorName = name; - } - } - - // no MapAll - take care - private void Map(IMemberType source, MemberTypeDisplay target, MapperContext context) - { - MapTypeToDisplayBase(source, target); - - // map the MemberCanEditProperty,MemberCanViewProperty,IsSensitiveData - foreach (IPropertyType propertyType in source.PropertyTypes) - { - IPropertyType localCopy = propertyType; - MemberPropertyTypeDisplay? displayProp = target.Groups.SelectMany(dest => dest.Properties) - .SingleOrDefault(dest => dest.Alias?.InvariantEquals(localCopy.Alias) ?? false); - if (displayProp == null) - { - continue; - } - - displayProp.MemberCanEditProperty = source.MemberCanEditProperty(localCopy.Alias); - displayProp.MemberCanViewProperty = source.MemberCanViewProperty(localCopy.Alias); - displayProp.IsSensitiveData = source.IsSensitiveProperty(localCopy.Alias); - } - } - - // Umbraco.Code.MapAll -Blueprints - private void Map(IContentTypeBase source, ContentTypeBasic target, string entityType) - { - target.Udi = Udi.Create(entityType, source.Key); - target.Alias = source.Alias; - target.CreateDate = source.CreateDate; - target.Description = source.Description; - target.Icon = source.Icon; - target.IconFilePath = target.IconIsClass - ? string.Empty - : $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}"; - - target.Trashed = source.Trashed; - target.Id = source.Id; - target.ListView = source.ListView; - target.IsElement = source.IsElement; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Thumbnail = source.Thumbnail; - target.ThumbnailFilePath = target.ThumbnailIsClass - ? string.Empty - : _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail); - target.UpdateDate = source.UpdateDate; - target.Variations = source.Variations; - } - - // no MapAll - uses the IContentTypeBase map method, which has MapAll - private void Map(IContentTypeComposition source, ContentTypeBasic target, MapperContext context) => - Map(source, target, Constants.UdiEntityType.MemberType); - - // no MapAll - uses the IContentTypeBase map method, which has MapAll - private void Map(IContentType source, ContentTypeBasic target, MapperContext context) => - Map(source, target, Constants.UdiEntityType.DocumentType); - - // no MapAll - uses the IContentTypeBase map method, which has MapAll - private void Map(IMediaType source, ContentTypeBasic target, MapperContext context) => - Map(source, target, Constants.UdiEntityType.MediaType); - - // no MapAll - uses the IContentTypeBase map method, which has MapAll - private void Map(IMemberType source, ContentTypeBasic target, MapperContext context) => - Map(source, target, Constants.UdiEntityType.MemberType); - - // no MapAll - take care - private void Map(DocumentTypeSave source, DocumentTypeDisplay target, MapperContext context) - { - MapTypeToDisplayBase( - source, - target, - context); - - // sync templates - IEnumerable destAllowedTemplateAliases = target.AllowedTemplates.Select(x => x.Alias); - - // if the dest is set and it's the same as the source, then don't change - if (source.AllowedTemplates is not null && - destAllowedTemplateAliases.SequenceEqual(source.AllowedTemplates) == false) - { - IEnumerable? templates = _fileService.GetTemplates(source.AllowedTemplates.ToArray()); - target.AllowedTemplates = source.AllowedTemplates - .Select(x => - { - ITemplate? template = templates?.SingleOrDefault(t => t.Alias == x); - return template != null - ? context.Map(template) - : null; - }) - .WhereNotNull() - .ToArray(); - } - - if (source.DefaultTemplate.IsNullOrWhiteSpace() == false) - { - // if the dest is set and it's the same as the source, then don't change - if (target.DefaultTemplate == null || source.DefaultTemplate != target.DefaultTemplate.Alias) - { - ITemplate? template = _fileService.GetTemplate(source.DefaultTemplate); - target.DefaultTemplate = template == null ? null : context.Map(template); - } - } - else - { - target.DefaultTemplate = null; - } - } - - // no MapAll - take care - private void Map(MediaTypeSave source, MediaTypeDisplay target, MapperContext context) => - MapTypeToDisplayBase( - source, - target, - context); - - // no MapAll - take care - private void Map(MemberTypeSave source, MemberTypeDisplay target, MapperContext context) => - MapTypeToDisplayBase( - source, target, context); - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate -Key -PropertyTypes - private static void Map(PropertyGroupBasic source, PropertyGroup target, - MapperContext context) - { - if (source.Id > 0) - { - target.Id = source.Id; - } - - target.Key = source.Key; - target.Type = source.Type; - target.Name = source.Name; - target.Alias = source.Alias; - target.SortOrder = source.SortOrder; - } - - // Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames - private static void Map( - PropertyGroupBasic source, - PropertyGroupDisplay target, - MapperContext context) - { - target.Inherited = source.Inherited; - if (source.Id > 0) - { - target.Id = source.Id; - } - - target.Key = source.Key; - target.Type = source.Type; - target.Name = source.Name; - target.Alias = source.Alias; - target.SortOrder = source.SortOrder; - target.Properties = context.MapEnumerable(source.Properties) - .WhereNotNull(); - } - - // Umbraco.Code.MapAll -ContentTypeId -ParentTabContentTypes -ParentTabContentTypeNames - private static void Map( - PropertyGroupBasic source, - PropertyGroupDisplay target, - MapperContext context) - { - target.Inherited = source.Inherited; - if (source.Id > 0) - { - target.Id = source.Id; - } - - target.Key = source.Key; - target.Type = source.Type; - target.Name = source.Name; - target.Alias = source.Alias; - target.SortOrder = source.SortOrder; - target.Properties = - context.MapEnumerable(source.Properties).WhereNotNull(); - } - - // Umbraco.Code.MapAll -Editor -View -Config -ContentTypeId -ContentTypeName -Locked -DataTypeIcon -DataTypeName - private static void Map(PropertyTypeBasic source, PropertyTypeDisplay target, MapperContext context) - { - target.Alias = source.Alias; - target.AllowCultureVariant = source.AllowCultureVariant; - target.AllowSegmentVariant = source.AllowSegmentVariant; - target.DataTypeId = source.DataTypeId; - target.DataTypeKey = source.DataTypeKey; - target.Description = source.Description; - target.GroupId = source.GroupId; - target.Id = source.Id; - target.Inherited = source.Inherited; - target.Label = source.Label; - target.SortOrder = source.SortOrder; - target.Validation = source.Validation; - target.LabelOnTop = source.LabelOnTop; - } - - // Umbraco.Code.MapAll -Editor -View -Config -ContentTypeId -ContentTypeName -Locked -DataTypeIcon -DataTypeName - private static void Map(MemberPropertyTypeBasic source, MemberPropertyTypeDisplay target, MapperContext context) - { - target.Alias = source.Alias; - target.AllowCultureVariant = source.AllowCultureVariant; - target.AllowSegmentVariant = source.AllowSegmentVariant; - target.DataTypeId = source.DataTypeId; - target.DataTypeKey = source.DataTypeKey; - target.Description = source.Description; - target.GroupId = source.GroupId; - target.Id = source.Id; - target.Inherited = source.Inherited; - target.IsSensitiveData = source.IsSensitiveData; - target.Label = source.Label; - target.MemberCanEditProperty = source.MemberCanEditProperty; - target.MemberCanViewProperty = source.MemberCanViewProperty; - target.SortOrder = source.SortOrder; - target.Validation = source.Validation; - target.LabelOnTop = source.LabelOnTop; - } - - // Umbraco.Code.MapAll -CreatorId -Level -SortOrder -Variations - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate - // Umbraco.Code.MapAll -ContentTypeComposition (done by AfterMapSaveToType) - private void MapSaveToTypeBase( - TSource source, - IContentTypeComposition target, - MapperContext context) - where TSource : ContentTypeSave - where TSourcePropertyType : PropertyTypeBasic - { - // TODO: not so clean really - var isPublishing = target is IContentType; - - var id = Convert.ToInt32(source.Id); - if (id > 0) - { - target.Id = id; - } - - target.Alias = source.Alias; - target.Description = source.Description; - target.Icon = source.Icon; - target.ListView = source.ListView; - target.IsElement = source.IsElement; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Thumbnail = source.Thumbnail; - - target.AllowedAsRoot = source.AllowAsRoot; - - // NOTE: we're now always overwriting the AllowedContentTypes instead of checking for changes. it is - // OK because this mapping method will be gone for V14 anyway (along with the old view models). - IContentType[] allowedContentTypes = target.AllowedContentTypes?.Any() is true - ? _contentTypeService.GetAll(target.AllowedContentTypes.Select(c => c.Key)).ToArray() - : Array.Empty(); - target.AllowedContentTypes = allowedContentTypes.Select((c, i) => new ContentTypeSort(c.Key, i, c.Alias)); - - if (!(target is IMemberType)) - { - target.SetVariesBy(ContentVariation.Culture, source.AllowCultureVariant); - target.SetVariesBy(ContentVariation.Segment, source.AllowSegmentVariant); - } - - // handle property groups and property types - // note that ContentTypeSave has - // - all groups, inherited and local; only *one* occurrence per group *name* - // - potentially including the generic properties group - // - all properties, inherited and local - // - // also, see PropertyTypeGroupResolver.ResolveCore: - // - if a group is local *and* inherited, then Inherited is true - // and the identifier is the identifier of the *local* group - // - // IContentTypeComposition AddPropertyGroup, AddPropertyType methods do some - // unique-alias-checking, etc that is *not* compatible with re-mapping everything - // the way we do it here, so we should exclusively do it by - // - managing a property group's PropertyTypes collection - // - managing the content type's PropertyTypes collection (for generic properties) - - // handle actual groups (non-generic-properties) - PropertyGroup[] destOrigGroups = target.PropertyGroups.ToArray(); // local groups - IPropertyType[] destOrigProperties = target.PropertyTypes.ToArray(); // all properties, in groups or not - var destGroups = new List(); - PropertyGroupBasic[] sourceGroups = - source.Groups.Where(x => x.IsGenericProperties == false).ToArray(); - var sourceGroupParentAliases = sourceGroups.Select(x => x.GetParentAlias()).Distinct().ToArray(); - foreach (PropertyGroupBasic sourceGroup in sourceGroups) - { - // get the dest group - PropertyGroup? destGroup = MapSaveGroup(sourceGroup, destOrigGroups, context); - - // handle local properties - IPropertyType[] destProperties = sourceGroup.Properties - .Where(x => x.Inherited == false) - .Select(x => MapSaveProperty(x, destOrigProperties, context)) - .WhereNotNull() - .ToArray(); - - // if the group has no local properties and is not used as parent, skip it, ie sort-of garbage-collect - // local groups which would not have local properties anymore - if (destProperties.Length == 0 && !sourceGroupParentAliases.Contains(sourceGroup.Alias)) - { - continue; - } - - // ensure no duplicate alias, then assign the group properties collection - EnsureUniqueAliases(destProperties); - - if (destGroup is not null) - { - if (destGroup.PropertyTypes?.SupportsPublishing != isPublishing || - destGroup.PropertyTypes.SequenceEqual(destProperties) is false) - { - destGroup.PropertyTypes = new PropertyTypeCollection(isPublishing, destProperties); - } - - destGroups.Add(destGroup); - } - } - - // ensure no duplicate name, then assign the groups collection - EnsureUniqueAliases(destGroups); - - if (target.PropertyGroups.SequenceEqual(destGroups) is false) - { - target.PropertyGroups = new PropertyGroupCollection(destGroups); - } - - // because the property groups collection was rebuilt, there is no need to remove - // the old groups - they are just gone and will be cleared by the repository - - // handle non-grouped (ie generic) properties - PropertyGroupBasic? genericPropertiesGroup = - source.Groups.FirstOrDefault(x => x.IsGenericProperties); - if (genericPropertiesGroup != null) - { - // handle local properties - IPropertyType[] destProperties = genericPropertiesGroup.Properties - .Where(x => x.Inherited == false) - .Select(x => MapSaveProperty(x, destOrigProperties, context)) - .WhereNotNull() - .ToArray(); - - // ensure no duplicate alias, then assign the generic properties collection - EnsureUniqueAliases(destProperties); - target.NoGroupPropertyTypes = new PropertyTypeCollection(isPublishing, destProperties); - } - - // because all property collections were rebuilt, there is no need to remove - // some old properties, they are just gone and will be cleared by the repository - } - - // Umbraco.Code.MapAll -Blueprints -Errors -ListViewEditorName -Trashed - private void MapTypeToDisplayBase(IContentTypeComposition source, ContentTypeCompositionDisplay target) - { - target.Alias = source.Alias; - target.AllowAsRoot = source.AllowedAsRoot; - target.CreateDate = source.CreateDate; - target.Description = source.Description; - target.Icon = source.Icon; - target.IconFilePath = target.IconIsClass - ? string.Empty - : $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}"; - target.Id = source.Id; - target.ListView = source.ListView; - target.IsElement = source.IsElement; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Thumbnail = source.Thumbnail; - target.ThumbnailFilePath = target.ThumbnailIsClass - ? string.Empty - : _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail); - target.Udi = MapContentTypeUdi(source); - target.UpdateDate = source.UpdateDate; - - // NOTE: this mapping is somewhat cumbersome at this point. it is OK because it will - // be gone for V14 anyway (along with the old view models). - IContentType[] allowedContentTypes = source.AllowedContentTypes?.Any() is true - ? _contentTypeService.GetAll(source.AllowedContentTypes.Select(c => c.Key)).ToArray() - : Array.Empty(); - Guid[] allowedContentTypesSortOrder = source.AllowedContentTypes?.Any() is true - ? source.AllowedContentTypes.OrderBy(c => c.SortOrder).Select(c => c.Key).ToArray() - : Array.Empty(); - target.AllowedContentTypes = allowedContentTypes.OrderBy(c => allowedContentTypesSortOrder.IndexOf(c.Key)).Select(c => c.Id).ToArray(); - target.CompositeContentTypes = source.ContentTypeComposition.Select(x => x.Alias); - target.LockedCompositeContentTypes = MapLockedCompositions(source); - target.Variations = source.Variations; - } - - // no MapAll - relies on the non-generic method - private void MapTypeToDisplayBase(IContentTypeComposition source, TTarget target) - where TTarget : ContentTypeCompositionDisplay - where TTargetPropertyType : PropertyTypeDisplay, new() - { - MapTypeToDisplayBase(source, target); - - var groupsMapper = new PropertyTypeGroupMapper( - _propertyEditors, - _dataTypeService, - _shortStringHelper, - _loggerFactory.CreateLogger>()); - target.Groups = groupsMapper.Map(source); - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -ListViewEditorName -Errors -LockedCompositeContentTypes - private void MapTypeToDisplayBase(ContentTypeSave source, ContentTypeCompositionDisplay target) - { - target.Alias = source.Alias; - target.AllowAsRoot = source.AllowAsRoot; - target.AllowedContentTypes = source.AllowedContentTypes; - target.Blueprints = source.Blueprints; - target.CompositeContentTypes = source.CompositeContentTypes; - target.Description = source.Description; - target.Icon = source.Icon; - target.IconFilePath = target.IconIsClass - ? string.Empty - : $"{_globalSettings.GetBackOfficePath(_hostingEnvironment).EnsureEndsWith("/")}images/umbraco/{source.Icon}"; - target.Id = source.Id; - target.ListView = source.ListView; - target.IsElement = source.IsElement; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Thumbnail = source.Thumbnail; - target.ThumbnailFilePath = target.ThumbnailIsClass - ? string.Empty - : _hostingEnvironment.ToAbsolute("~/umbraco/images/thumbnails/" + source.Thumbnail); - target.Trashed = source.Trashed; - target.Udi = source.Udi; - target.Variations = source.Variations; - } - - // no MapAll - relies on the non-generic method - private void MapTypeToDisplayBase( - TSource source, - TTarget target, - MapperContext context) - where TSource : ContentTypeSave - where TSourcePropertyType : PropertyTypeBasic - where TTarget : ContentTypeCompositionDisplay - where TTargetPropertyType : PropertyTypeDisplay - { - MapTypeToDisplayBase(source, target); - - target.Groups = - context - .MapEnumerable, PropertyGroupDisplay>( - source.Groups).WhereNotNull(); - } - - private IEnumerable MapLockedCompositions(IContentTypeComposition source) - { - // get ancestor ids from path of parent if not root - if (source.ParentId == Constants.System.Root) - { - return Enumerable.Empty(); - } - - IContentType? parent = _contentTypeService.Get(source.ParentId); - if (parent == null) - { - return Enumerable.Empty(); - } - - var aliases = new List(); - IEnumerable? ancestorIds = parent.Path?.Split(Constants.CharArrays.Comma) - .Select(s => int.Parse(s, CultureInfo.InvariantCulture)); - - // loop through all content types and return ordered aliases of ancestors - IContentType[] allContentTypes = _contentTypeService.GetAll().ToArray(); - if (ancestorIds is not null) - { - foreach (var ancestorId in ancestorIds) - { - IContentType? ancestor = allContentTypes.FirstOrDefault(x => x.Id == ancestorId); - if (ancestor is not null && ancestor.Alias is not null) - { - aliases.Add(ancestor.Alias); - } - } - } - - return aliases.OrderBy(x => x); - } - - private static PropertyGroup? MapSaveGroup( - PropertyGroupBasic sourceGroup, - IEnumerable destOrigGroups, - MapperContext context) - where TPropertyType : PropertyTypeBasic - { - PropertyGroup? destGroup; - if (sourceGroup.Id > 0) - { - // update an existing group - // ensure it is still there, then map/update - destGroup = destOrigGroups.FirstOrDefault(x => x.Id == sourceGroup.Id); - if (destGroup != null) - { - context.Map(sourceGroup, destGroup); - return destGroup; - } - - // force-clear the ID as it does not match anything - sourceGroup.Id = 0; - } - - // insert a new group, or update an existing group that has - // been deleted in the meantime and we need to re-create - // map/create - destGroup = context.Map(sourceGroup); - return destGroup; - } - - private static IPropertyType? MapSaveProperty( - PropertyTypeBasic sourceProperty, - IEnumerable destOrigProperties, - MapperContext context) - { - IPropertyType? destProperty; - if (sourceProperty.Id > 0) - { - // updating an existing property - // ensure it is still there, then map/update - destProperty = destOrigProperties.FirstOrDefault(x => x.Id == sourceProperty.Id); - if (destProperty != null) - { - context.Map(sourceProperty, destProperty); - return destProperty; - } - - // force-clear the ID as it does not match anything - sourceProperty.Id = 0; - } - - // insert a new property, or update an existing property that has - // been deleted in the meantime and we need to re-create - // map/create - destProperty = context.Map(sourceProperty); - return destProperty; - } - - private static void EnsureUniqueAliases(IEnumerable properties) - { - IPropertyType[] propertiesA = properties.ToArray(); - var distinctProperties = propertiesA - .Select(x => x.Alias?.ToUpperInvariant()) - .Distinct() - .Count(); - if (distinctProperties != propertiesA.Length) - { - throw new InvalidOperationException("Cannot map properties due to alias conflict."); - } - } - - private static void EnsureUniqueAliases(IEnumerable groups) - { - PropertyGroup[] groupsA = groups.ToArray(); - var distinctProperties = groupsA - .Select(x => x.Alias) - .Distinct() - .Count(); - if (distinctProperties != groupsA.Length) - { - throw new InvalidOperationException("Cannot map groups due to alias conflict."); - } - } - - private static void MapComposition(ContentTypeSave source, IContentTypeComposition target, - Func getContentType) - { - var current = target.CompositionAliases().ToArray(); - IEnumerable proposed = source.CompositeContentTypes; - - IEnumerable remove = current.Where(x => !proposed.Contains(x)); - IEnumerable add = proposed.Where(x => !current.Contains(x)); - - foreach (var alias in remove) - { - target.RemoveContentType(alias); - } - - foreach (var alias in add) - { - // TODO: Remove N+1 lookup - IContentTypeComposition? contentType = getContentType(alias); - if (contentType != null) - { - target.AddContentType(contentType); - } - } - } -} diff --git a/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs b/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs deleted file mode 100644 index 856f68f9ec5e..000000000000 --- a/src/Umbraco.Core/Models/Mapping/ContentVariantMapper.cs +++ /dev/null @@ -1,324 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.Extensions; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.Membership; -using Umbraco.Cms.Core.Security; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class ContentVariantMapper -{ - private readonly ILocalizationService _localizationService; - private readonly ILocalizedTextService _localizedTextService; - private readonly IBackOfficeSecurityAccessor _backOfficeSecurityAccessor; - private readonly IContentService _contentService; - private readonly IUserService _userService; - private ContentSettings _contentSettings; - - public ContentVariantMapper( - ILocalizationService localizationService, - ILocalizedTextService localizedTextService, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - IContentService contentService, - IUserService userService, - IOptionsMonitor contentSettings) - { - _localizationService = localizationService ?? throw new ArgumentNullException(nameof(localizationService)); - _localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); - _backOfficeSecurityAccessor = backOfficeSecurityAccessor; - _contentService = contentService; - _userService = userService; - _contentSettings = contentSettings.CurrentValue; - contentSettings.OnChange(settings => _contentSettings = settings); - } - - [Obsolete("Use constructor that takes all parameters instead")] - public ContentVariantMapper( - ILocalizationService localizationService, - ILocalizedTextService localizedTextService, - IBackOfficeSecurityAccessor backOfficeSecurityAccessor, - IContentService contentService, - IUserService userService, - IOptionsMonitor securitySettings) - : this( - localizationService, - localizedTextService, - backOfficeSecurityAccessor, - contentService, - userService, - StaticServiceProvider.Instance.GetRequiredService>()) - { - } - - [Obsolete("Use constructor that takes all parameters instead")] - public ContentVariantMapper(ILocalizationService localizationService, ILocalizedTextService localizedTextService) - : this( - localizationService, - localizedTextService, - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService>()) - { - } - - public IEnumerable Map(IContent source, MapperContext context) - where TVariant : ContentVariantDisplay - { - var variesByCulture = source.ContentType.VariesByCulture(); - var variesBySegment = source.ContentType.VariesBySegment(); - - List variants = new(); - - if (!variesByCulture && !variesBySegment) - { - // this is invariant so just map the IContent instance to ContentVariationDisplay - TVariant? variantDisplay = context.Map(source); - if (variantDisplay is not null) - { - // Map allowed actions per language - variantDisplay.AllowedActions = GetLanguagePermissions(source, context, variantDisplay); - variants.Add(variantDisplay); - } - } - else if (variesByCulture && !variesBySegment) - { - IEnumerable languages = GetLanguages(context); - variants = languages - .Select(language => CreateVariantDisplay(context, source, language, null)) - .WhereNotNull() - .ToList(); - } - else if (variesBySegment && !variesByCulture) - { - // Segment only - IEnumerable segments = GetSegments(source); - variants = segments - .Select(segment => CreateVariantDisplay(context, source, null, segment)) - .WhereNotNull() - .ToList(); - } - else - { - // Culture and segment - var languages = GetLanguages(context).ToList(); - var segments = GetSegments(source).ToList(); - - if (languages.Count == 0 || segments.Count == 0) - { - // This should not happen - throw new InvalidOperationException("No languages or segments available"); - } - - variants = languages - .SelectMany(language => segments - .Select(segment => CreateVariantDisplay(context, source, language, segment))) - .WhereNotNull() - .ToList(); - } - - return SortVariants(variants); - } - - private static bool IsDefaultSegment(ContentVariantDisplay variant) => variant.Segment == null; - - private IList SortVariants(IList variants) - where TVariant : ContentVariantDisplay - { - if (variants.Count <= 1) - { - return variants; - } - - // Default variant first, then order by language, segment. - return variants - .OrderBy(v => IsDefaultLanguage(v) ? 0 : 1) - .ThenBy(v => IsDefaultSegment(v) ? 0 : 1) - .ThenBy(v => v?.Language?.Name) - .ThenBy(v => v.Segment) - .ToList(); - } - - private static bool IsDefaultLanguage(ContentVariantDisplay variant) => - variant.Language == null || variant.Language.IsDefault; - - private IEnumerable GetLanguages(MapperContext context) - { - var allLanguages = _localizationService.GetAllLanguages().OrderBy(x => x.Id).ToList(); - if (allLanguages.Count == 0) - { - // This should never happen - return Enumerable.Empty(); - } - - return context.MapEnumerable(allLanguages).WhereNotNull().ToList(); - } - - /// - /// Returns all segments assigned to the content - /// - /// - /// - /// Returns all segments assigned to the content including the default `null` segment. - /// - private IEnumerable GetSegments(IContent content) - { - // The default segment (null) is always there, - // even when there is no property data at all yet - var segments = new List {null}; - - // Add actual segments based on the property values - segments.AddRange(content.Properties.SelectMany(p => p.Values.Select(v => v.Segment))); - - // Do not return a segment more than once - return segments.Distinct(); - } - - private TVariant? CreateVariantDisplay(MapperContext context, IContent content, ContentEditing.Language? language, string? segment) - where TVariant : ContentVariantDisplay - { - context.SetCulture(language?.IsoCode); - context.SetSegment(segment); - - TVariant? variantDisplay = context.Map(content); - - if (variantDisplay is null) - { - return null; - } - - variantDisplay.Segment = segment; - variantDisplay.Language = language; - - // Map allowed actions - variantDisplay.AllowedActions = GetLanguagePermissions(content, context, variantDisplay); - variantDisplay.Name = content.GetCultureName(language?.IsoCode); - variantDisplay.DisplayName = GetDisplayName(language, segment); - - return variantDisplay; - } - - private string GetDisplayName(ContentEditing.Language? language, string? segment) - { - var isCultureVariant = language is not null; - var isSegmentVariant = !segment.IsNullOrWhiteSpace(); - - if (!isCultureVariant && !isSegmentVariant) - { - return _localizedTextService.Localize("general", "default"); - } - - var parts = new List(); - - if (isSegmentVariant) - { - parts.Add(segment!); - } - - if (isCultureVariant) - { - parts.Add(language?.Name!); - } - - return string.Join(" — ", parts); - } - - // This is a bit ugly, but when languages get granular permissions this will be really useful - // For now we just return the exact same permissions as you had on the node, if you have access via language - private IEnumerable GetLanguagePermissions(IContent content, MapperContext context, TVariant variantDisplay) - where TVariant : ContentVariantDisplay - { - context.Items.TryGetValue("CurrentUser", out var currentBackofficeUser); - - IUser? currentUser = null; - - if (currentBackofficeUser is IUser currentIUserBackofficeUser) - { - currentUser = currentIUserBackofficeUser; - } - else if(_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser is not null) - { - currentUser = _backOfficeSecurityAccessor.BackOfficeSecurity.CurrentUser; - } - - if (currentUser is null) - { - return Enumerable.Empty(); - } - - IEnumerable userGroups = currentUser.Groups; - - // Map allowed actions - var hasAccess = false; - foreach (IReadOnlyUserGroup group in userGroups) - { - // Handle invariant - if (variantDisplay.Language is null) - { - var defaultLanguageId = _localizationService.GetDefaultLanguageId(); - if (_contentSettings.AllowEditInvariantFromNonDefault || (defaultLanguageId.HasValue && group.HasAccessToLanguage(defaultLanguageId.Value))) - { - hasAccess = true; - } - } - - if (variantDisplay.Language is not null && group.HasAccessToLanguage(variantDisplay.Language.Id)) - { - hasAccess = true; - break; - } - } - - // If user does not have access, return only browse permission - if (!hasAccess) - { - return new[] { ActionBrowse.ActionLetter.ToString() }; - } - - IContent? parent; - if (context.Items.TryGetValue("Parent", out var parentObj) && - parentObj is IContent typedParent) - { - parent = typedParent; - } - else - { - parent = _contentService.GetParent(content); - } - - string path; - if (content.HasIdentity) - { - path = content.Path; - } - else - { - path = parent == null ? "-1" : parent.Path; - } - - // A bit of a mess, but we need to ensure that all the required values are here AND that they're the right type. - if (context.Items.TryGetValue("Permissions", out var permissionsObject) && permissionsObject is Dictionary permissionsDict) - { - // If we already have permissions for a given path, - // and the current user is the same as was used to generate the permissions, return the stored permissions. - if (_backOfficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.Id == currentUser.Id && - permissionsDict.TryGetValue(path, out EntityPermissionSet? permissions)) - { - return permissions.GetAllPermissions(); - } - } - - // TODO: This is certainly not ideal usage here - perhaps the best way to deal with this in the future is - // with the IUmbracoContextAccessor. In the meantime, if used outside of a web app this will throw a null - // reference exception :( - - return _userService.GetPermissionsForPath(currentUser, path).GetAllPermissions(); - } -} diff --git a/src/Umbraco.Core/Models/Mapping/DataTypeMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/DataTypeMapDefinition.cs deleted file mode 100644 index 5f9cc4245da3..000000000000 --- a/src/Umbraco.Core/Models/Mapping/DataTypeMapDefinition.cs +++ /dev/null @@ -1,223 +0,0 @@ -using Microsoft.Extensions.Logging; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class DataTypeMapDefinition : IMapDefinition -{ - private static readonly int[] SystemIds = - { - Constants.DataTypes.DefaultContentListView, Constants.DataTypes.DefaultMediaListView, - Constants.DataTypes.DefaultMembersListView, - }; - - private readonly ContentSettings _contentSettings; - private readonly ILogger _logger; - private readonly PropertyEditorCollection _propertyEditors; - private readonly IConfigurationEditorJsonSerializer _serializer; - - public DataTypeMapDefinition(PropertyEditorCollection propertyEditors, ILogger logger, IOptions contentSettings, IConfigurationEditorJsonSerializer serializer) - { - _propertyEditors = propertyEditors; - _logger = logger; - _contentSettings = contentSettings.Value ?? throw new ArgumentNullException(nameof(contentSettings)); - _serializer = serializer; - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new PropertyEditorBasic(), Map); - mapper.Define( - (source, context) => new DataTypeConfigurationFieldDisplay(), Map); - mapper.Define((source, context) => new DataTypeBasic(), Map); - mapper.Define((source, context) => new DataTypeBasic(), Map); - mapper.Define((source, context) => new DataTypeDisplay(), Map); - mapper.Define>(MapPreValues); - mapper.Define( - (source, context) => - new DataType(_propertyEditors[source.EditorAlias], _serializer) { CreateDate = DateTime.Now }, - Map); - mapper.Define>(MapPreValues); - } - - // Umbraco.Code.MapAll - private static void Map(IDataEditor source, PropertyEditorBasic target, MapperContext context) - { - target.Alias = source.Alias; - } - - // Umbraco.Code.MapAll -Value - private static void Map(ConfigurationField source, DataTypeConfigurationFieldDisplay target, MapperContext context) - { - target.Config = source.Config; - target.Key = source.Key; - } - - // Umbraco.Code.MapAll -Udi -HasPrevalues -IsSystemDataType -Id -Trashed -Key - // Umbraco.Code.MapAll -ParentId -Path -Icon -Name - private static void Map(IDataEditor source, DataTypeBasic target, MapperContext context) - { - target.Alias = source.Alias; - } - - // Umbraco.Code.MapAll -HasPrevalues -Icon - private void Map(IDataType source, DataTypeBasic target, MapperContext context) - { - target.Id = source.Id; - target.IsSystemDataType = SystemIds.Contains(source.Id); - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Trashed = source.Trashed; - target.Udi = Udi.Create(Constants.UdiEntityType.DataType, source.Key); - - if (!_propertyEditors.TryGet(source.EditorAlias, out IDataEditor? editor)) - { - return; - } - - target.Alias = editor.Alias; - } - - // Umbraco.Code.MapAll -HasPrevalues -Icon - private void Map(IDataType source, DataTypeDisplay target, MapperContext context) - { - target.AvailableEditors = MapAvailableEditors(source, context); - target.Id = source.Id; - target.IsSystemDataType = SystemIds.Contains(source.Id); - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.PreValues = MapPreValues(source, context); - target.SelectedEditor = source.EditorAlias.IsNullOrWhiteSpace() ? null : source.EditorAlias; - target.Trashed = source.Trashed; - target.Udi = Udi.Create(Constants.UdiEntityType.DataType, source.Key); - - if (!_propertyEditors.TryGet(source.EditorAlias, out IDataEditor? editor)) - { - return; - } - - target.Alias = editor.Alias; - } - - // Umbraco.Code.MapAll -CreateDate -DeleteDate -UpdateDate - // Umbraco.Code.MapAll -Key -Path -CreatorId -Level -SortOrder -ConfigurationObject -ConfigurationData - private void Map(DataTypeSave source, IDataType target, MapperContext context) - { - target.DatabaseType = MapDatabaseType(source); - target.Editor = _propertyEditors[source.EditorAlias]; - target.EditorUiAlias = null; - target.Id = Convert.ToInt32(source.Id); - target.Name = source.Name; - target.ParentId = source.ParentId; - } - - private IEnumerable MapAvailableEditors(IDataType source, MapperContext context) - { - IOrderedEnumerable properties = _propertyEditors - .Where(x => !x.IsDeprecated || _contentSettings.ShowDeprecatedPropertyEditors || - source.EditorAlias == x.Alias) - .OrderBy(x => x.Alias); - return context.MapEnumerable(properties).WhereNotNull(); - } - - private IEnumerable MapPreValues(IDataType dataType, MapperContext context) - { - // in v7 it was apparently fine to have an empty .EditorAlias here, in which case we would map onto - // an empty fields list, which made no sense since there would be nothing to map to - and besides, - // a datatype without an editor alias is a serious issue - v8 wants an editor here - if (string.IsNullOrWhiteSpace(dataType.EditorAlias) || - !_propertyEditors.TryGet(dataType.EditorAlias, out IDataEditor? editor)) - { - throw new InvalidOperationException( - $"Could not find a property editor with alias \"{dataType.EditorAlias}\"."); - } - - IConfigurationEditor configurationEditor = editor.GetConfigurationEditor(); - var fields = context - .MapEnumerable(configurationEditor.Fields) - .WhereNotNull().ToList(); - IDictionary configurationDictionary = configurationEditor.ToConfigurationEditor(dataType.ConfigurationData); - - MapConfigurationFields(dataType, fields, configurationDictionary); - - return fields; - } - - private void MapConfigurationFields(IDataType? dataType, List fields, IDictionary? configuration) - { - if (fields == null) - { - throw new ArgumentNullException(nameof(fields)); - } - - if (configuration == null) - { - throw new ArgumentNullException(nameof(configuration)); - } - - // now we need to wire up the pre-values values with the actual fields defined - foreach (DataTypeConfigurationFieldDisplay field in fields.ToList()) - { - // filter out the not-supported pre-values for built-in data types - if (dataType != null && dataType.IsBuildInDataType() && - (field.Key?.InvariantEquals(Constants.DataTypes.ReservedPreValueKeys.IgnoreUserStartNodes) ?? false)) - { - fields.Remove(field); - continue; - } - - if (field.Key is not null && configuration.TryGetValue(field.Key, out var value)) - { - field.Value = value; - } - else - { - // weird - just leave the field without a value - but warn - _logger.LogWarning("Could not find a value for configuration field '{ConfigField}'", field.Key); - } - } - } - - private ValueStorageType MapDatabaseType(DataTypeSave source) - { - if (!_propertyEditors.TryGet(source.EditorAlias, out IDataEditor? editor)) - { - throw new InvalidOperationException($"Could not find property editor \"{source.EditorAlias}\"."); - } - - // TODO: what about source.PropertyEditor? can we get the configuration here? 'cos it may change the storage type?! - var valueType = editor.GetValueEditor().ValueType; - return ValueTypes.ToStorageType(valueType); - } - - private IEnumerable MapPreValues(IDataEditor source, MapperContext context) - { - // this is a new data type, initialize default configuration - // get the configuration editor, - // get the configuration fields and map to UI, - // get the configuration default values and map to UI - IConfigurationEditor configurationEditor = source.GetConfigurationEditor(); - - var fields = - context.MapEnumerable(configurationEditor.Fields) - .WhereNotNull().ToList(); - - IDictionary defaultConfiguration = configurationEditor.DefaultConfiguration; - if (defaultConfiguration != null) - { - MapConfigurationFields(null, fields, defaultConfiguration); - } - - return fields; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/DictionaryMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/DictionaryMapDefinition.cs deleted file mode 100644 index cfc1b5d4f425..000000000000 --- a/src/Umbraco.Core/Models/Mapping/DictionaryMapDefinition.cs +++ /dev/null @@ -1,105 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// -/// The dictionary model mapper. -/// -public class DictionaryMapDefinition : IMapDefinition -{ - private readonly CommonMapper? _commonMapper; - private readonly IDictionaryService _dictionaryService; - private readonly ILocalizationService _localizationService; - - [Obsolete("Use the constructor with the CommonMapper")] - public DictionaryMapDefinition(ILocalizationService localizationService) - : this( - localizationService, - StaticServiceProvider.Instance.GetRequiredService(), - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - [Obsolete("Use the constructor with the CommonMapper, and IDictionaryService")] - public DictionaryMapDefinition(ILocalizationService localizationService, CommonMapper commonMapper) - : this( - localizationService, - commonMapper, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public DictionaryMapDefinition(ILocalizationService localizationService, CommonMapper commonMapper, IDictionaryService dictionaryService) - { - _localizationService = localizationService; - _commonMapper = commonMapper; - _dictionaryService = dictionaryService; - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new DictionaryDisplay(), Map); - mapper.Define((source, context) => new DictionaryOverviewDisplay(), Map); - } - - // Umbraco.Code.MapAll -ParentId -Path -Trashed -Udi -Icon - private static void Map(IDictionaryItem source, EntityBasic target, MapperContext context) - { - target.Alias = source.ItemKey; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.ItemKey; - } - - // Umbraco.Code.MapAll -Icon -Trashed -Alias - private void Map(IDictionaryItem source, DictionaryDisplay target, MapperContext context) - { - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.ItemKey; - target.ParentId = source.ParentId ?? Guid.Empty; - target.Udi = Udi.Create(Constants.UdiEntityType.DictionaryItem, source.Key); - - target.Path = _dictionaryService.CalculatePath(source.ParentId, source.Id); - - // add all languages and the translations - foreach (ILanguage lang in _localizationService.GetAllLanguages()) - { - IDictionaryTranslation? translation = source.Translations?.FirstOrDefault(x => x.LanguageIsoCode == lang.IsoCode); - - target.Translations.Add(new DictionaryTranslationDisplay - { - IsoCode = lang.IsoCode, - DisplayName = lang.CultureName, - Translation = translation?.Value ?? string.Empty, - LanguageId = lang.Id, - }); - } - } - - // Umbraco.Code.MapAll -Level -Translations - private void Map(IDictionaryItem source, DictionaryOverviewDisplay target, MapperContext context) - { - target.Id = source.Id; - target.Name = source.ItemKey; - - // add all languages and the translations - foreach (ILanguage lang in _localizationService.GetAllLanguages()) - { - IDictionaryTranslation? translation = source.Translations?.FirstOrDefault(x => x.LanguageIsoCode == lang.IsoCode); - - target.Translations.Add( - new DictionaryOverviewTranslationDisplay - { - DisplayName = lang.CultureName, - HasTranslation = translation != null && string.IsNullOrEmpty(translation.Value) == false, - }); - } - } -} diff --git a/src/Umbraco.Core/Models/Mapping/LanguageMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/LanguageMapDefinition.cs deleted file mode 100644 index dd49b0a0eb57..000000000000 --- a/src/Umbraco.Core/Models/Mapping/LanguageMapDefinition.cs +++ /dev/null @@ -1,60 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class LanguageMapDefinition : IMapDefinition -{ - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new ContentEditing.Language(), Map); - mapper.Define, IEnumerable>((source, context) => new List(), Map); - } - - // Umbraco.Code.MapAll -Udi -Path -Trashed -AdditionalData -Icon - private static void Map(ILanguage source, EntityBasic target, MapperContext context) - { - target.Name = source.CultureName; - target.Key = source.Key; - target.ParentId = -1; - target.Alias = source.IsoCode; - target.Id = source.Id; - } - - // Umbraco.Code.MapAll - private static void Map(ILanguage source, ContentEditing.Language target, MapperContext context) - { - target.Id = source.Id; - target.IsoCode = source.IsoCode; - target.Name = source.CultureName; - target.IsDefault = source.IsDefault; - target.IsMandatory = source.IsMandatory; - target.FallbackIsoCode = source.FallbackIsoCode; - } - - private static void Map(IEnumerable source, IEnumerable target, MapperContext context) - { - if (target == null) - { - throw new ArgumentNullException(nameof(target)); - } - - if (!(target is List list)) - { - throw new NotSupportedException($"{nameof(target)} must be a List."); - } - - List temp = context.MapEnumerable(source); - - // Put the default language first in the list & then sort rest by a-z - ContentEditing.Language? defaultLang = temp.SingleOrDefault(x => x.IsDefault); - - // insert default lang first, then remaining language a-z - if (defaultLang is not null) - { - list.Add(defaultLang); - list.AddRange(temp.Where(x => x != defaultLang).OrderBy(x => x.Name)); - } - } -} diff --git a/src/Umbraco.Core/Models/Mapping/MediaMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/MediaMapDefinition.cs deleted file mode 100644 index 7a37562a822a..000000000000 --- a/src/Umbraco.Core/Models/Mapping/MediaMapDefinition.cs +++ /dev/null @@ -1,50 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// Declares model mappings for media. -/// -public class MediaMapDefinition : IMapDefinition -{ - private readonly CommonMapper _commonMapper; - - public MediaMapDefinition(CommonMapper commonMapper) - { - _commonMapper = commonMapper; - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new ContentPropertyCollectionDto(), Map); - mapper.Define>((source, context) => new ContentItemBasic(), Map); - } - - // Umbraco.Code.MapAll - private static void Map(IMedia source, ContentPropertyCollectionDto target, MapperContext context) => - target.Properties = context.MapEnumerable(source.Properties).WhereNotNull(); - - // Umbraco.Code.MapAll -Edited -Updater -Alias - private void Map(IMedia source, ContentItemBasic target, MapperContext context) - { - target.ContentTypeId = source.ContentType.Id; - target.ContentTypeAlias = source.ContentType.Alias; - target.CreateDate = source.CreateDate; - target.Icon = source.ContentType.Icon; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.Owner = _commonMapper.GetOwner(source, context); - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Properties = context.MapEnumerable(source.Properties).WhereNotNull(); - target.SortOrder = source.SortOrder; - target.State = null; - target.Trashed = source.Trashed; - target.Udi = Udi.Create(Constants.UdiEntityType.Media, source.Key); - target.UpdateDate = source.UpdateDate; - target.VariesByCulture = source.ContentType.VariesByCulture(); - } -} diff --git a/src/Umbraco.Core/Models/Mapping/MemberMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/MemberMapDefinition.cs deleted file mode 100644 index cff81c7fa90b..000000000000 --- a/src/Umbraco.Core/Models/Mapping/MemberMapDefinition.cs +++ /dev/null @@ -1,73 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -public class MemberMapDefinition : IMapDefinition -{ - private readonly CommonMapper _commonMapper; - - public MemberMapDefinition(CommonMapper commonMapper) => _commonMapper = commonMapper; - - /// - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define(Map); - mapper.Define((source, context) => new MemberBasic(), Map); - mapper.Define((source, context) => new ContentPropertyCollectionDto(), Map); - } - - private static void Map(MemberSave source, IMember target, MapperContext context) - { - target.IsApproved = source.IsApproved; - target.Name = source.Name; - target.Email = source.Email; - target.Key = source.Key; - target.Username = source.Username; - target.Comments = source.Comments; - target.CreateDate = source.CreateDate; - target.UpdateDate = source.UpdateDate; - target.Email = source.Email; - - // TODO: ensure all properties are mapped as required - // target.Id = source.Id; - // target.ParentId = -1; - // target.Path = "-1," + source.Id; - - // TODO: add groups as required - } - - // Umbraco.Code.MapAll -Trashed -Edited -Updater -Alias -VariesByCulture - private void Map(IMember source, MemberBasic target, MapperContext context) - { - target.ContentTypeId = source.ContentType.Id; - target.ContentTypeAlias = source.ContentType.Alias; - target.CreateDate = source.CreateDate; - target.Email = source.Email; - target.Icon = source.ContentType.Icon; - target.Id = int.MaxValue; - target.Key = source.Key; - target.Name = source.Name; - target.Owner = _commonMapper.GetOwner(source, context); - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Properties = context.MapEnumerable(source.Properties).WhereNotNull(); - target.SortOrder = source.SortOrder; - target.State = null; - target.Udi = Udi.Create(Constants.UdiEntityType.Member, source.Key); - target.UpdateDate = source.UpdateDate; - target.Username = source.Username; - target.FailedPasswordAttempts = source.FailedPasswordAttempts; - target.Approved = source.IsApproved; - target.LockedOut = source.IsLockedOut; - target.LastLockoutDate = source.LastLockoutDate; - target.LastLoginDate = source.LastLoginDate; - target.LastPasswordChangeDate = source.LastPasswordChangeDate; - } - - // Umbraco.Code.MapAll - private static void Map(IMember source, ContentPropertyCollectionDto target, MapperContext context) => - target.Properties = context.MapEnumerable(source.Properties).WhereNotNull(); -} diff --git a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs b/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs deleted file mode 100644 index f1b94e3142ab..000000000000 --- a/src/Umbraco.Core/Models/Mapping/MemberTabsAndPropertiesMapper.cs +++ /dev/null @@ -1,325 +0,0 @@ -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.Dictionary; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Security; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Web.Common.DependencyInjection; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -/// -/// A custom tab/property resolver for members which will ensure that the built-in membership properties are or aren't displayed -/// depending on if the member type has these properties -/// -/// -/// This also ensures that the IsLocked out property is readonly when the member is not locked out - this is because -/// an admin cannot actually set isLockedOut = true, they can only unlock. -/// -public class MemberTabsAndPropertiesMapper : TabsAndPropertiesMapper -{ - private readonly IBackOfficeSecurityAccessor _backofficeSecurityAccessor; - private readonly ILocalizedTextService _localizedTextService; - private readonly IMemberTypeService _memberTypeService; - private readonly IMemberService _memberService; - private readonly IMemberGroupService _memberGroupService; - private readonly MemberPasswordConfigurationSettings _memberPasswordConfiguration; - private readonly ITwoFactorLoginService _twoFactorLoginService; - - // PropertyEditorCollection is still injected as when removing it, the number of - // parameters matches with the obsolete ctor and the two ctors become ambiguous - // [ActivatorUtilitiesConstructor] won't solve the problem in this case. - // PropertyEditorCollection can be removed when the obsolete ctor is removed for - // Umbraco 13 - public MemberTabsAndPropertiesMapper( - ICultureDictionary cultureDictionary, - IBackOfficeSecurityAccessor backofficeSecurityAccessor, - ILocalizedTextService localizedTextService, - IMemberTypeService memberTypeService, - IMemberService memberService, - IMemberGroupService memberGroupService, - IOptions memberPasswordConfiguration, - IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - PropertyEditorCollection propertyEditorCollection, - ITwoFactorLoginService twoFactorLoginService) - : base(cultureDictionary, localizedTextService, contentTypeBaseServiceProvider) - { - _backofficeSecurityAccessor = backofficeSecurityAccessor ?? throw new ArgumentNullException(nameof(backofficeSecurityAccessor)); - _localizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); - _memberTypeService = memberTypeService ?? throw new ArgumentNullException(nameof(memberTypeService)); - _memberService = memberService ?? throw new ArgumentNullException(nameof(memberService)); - _memberGroupService = memberGroupService ?? throw new ArgumentNullException(nameof(memberGroupService)); - _memberPasswordConfiguration = memberPasswordConfiguration.Value; - _twoFactorLoginService = twoFactorLoginService ?? throw new ArgumentNullException(nameof(twoFactorLoginService)); - } - - [Obsolete("Use constructor that also takes an ITwoFactorLoginService. Scheduled for removal in V13")] - public MemberTabsAndPropertiesMapper( - ICultureDictionary cultureDictionary, - IBackOfficeSecurityAccessor backofficeSecurityAccessor, - ILocalizedTextService localizedTextService, - IMemberTypeService memberTypeService, - IMemberService memberService, - IMemberGroupService memberGroupService, - IOptions memberPasswordConfiguration, - IContentTypeBaseServiceProvider contentTypeBaseServiceProvider, - PropertyEditorCollection propertyEditorCollection) - : this( - cultureDictionary, - backofficeSecurityAccessor, - localizedTextService, - memberTypeService, - memberService, - memberGroupService, - memberPasswordConfiguration, - contentTypeBaseServiceProvider, - propertyEditorCollection, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - /// - /// Overridden to deal with custom member properties and permissions. - public override IEnumerable> Map(IMember source, MapperContext context) - { - - IMemberType? memberType = _memberTypeService.Get(source.ContentTypeId); - - if (memberType is not null) - { - - IgnoreProperties = memberType.CompositionPropertyTypes - .Where(x => x.HasIdentity == false) - .Select(x => x.Alias) - .ToArray(); - } - - IEnumerable> resolved = base.Map(source, context); - - return resolved; - } - - // We need this because we call GetCustomGenericProperties from TabsAndPropertiesMapper - // and we have no access to MapMembershipProperties from the base class without casting - protected override IEnumerable GetCustomGenericProperties(IContentBase content) - { - var member = (IMember)content; - return MapMembershipProperties(member, null); - } - - private Dictionary GetPasswordConfig(IMember member) - { - var result = new Dictionary(_memberPasswordConfiguration.GetConfiguration(true)) - { - // the password change toggle will only be displayed if there is already a password assigned. - {"hasPassword", member.RawPasswordValue.IsNullOrWhiteSpace() == false} - }; - - // This will always be true for members since we always want to allow admins to change a password - so long as that - // user has access to edit members (but that security is taken care of separately) - result["allowManuallyChangingPassword"] = true; - - return result; - } - - /// - /// Overridden to assign the IsSensitive property values - /// - /// - /// - /// - /// - protected override List MapProperties(IContentBase content, List properties, MapperContext context) - { - List result = base.MapProperties(content, properties, context); - var member = (IMember)content; - IMemberType? memberType = _memberTypeService.Get(member.ContentTypeId); - - // now update the IsSensitive value - foreach (ContentPropertyDisplay prop in result) - { - // check if this property is flagged as sensitive - var isSensitiveProperty = memberType?.IsSensitiveProperty(prop.Alias) ?? false; - // check permissions for viewing sensitive data - if (isSensitiveProperty && _backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.HasAccessToSensitiveData() == false) - { - // mark this property as sensitive - prop.IsSensitive = true; - // mark this property as readonly so that it does not post any data - prop.Readonly = true; - // clear the value - prop.Value = null; - } - } - return result; - } - - /// - /// Returns the login property display field - /// - /// - /// - /// - /// - /// If the membership provider installed is the umbraco membership provider, then we will allow changing the username, however if - /// the membership provider is a custom one, we cannot allow changing the username because MembershipProvider's do not actually natively - /// allow that. - /// - internal static ContentPropertyDisplay GetLoginProperty(IMember member, ILocalizedTextService localizedText) - { - var prop = new ContentPropertyDisplay - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}login", - Label = localizedText.Localize(null,"login"), - Value = member.Username - }; - - prop.Validation.Mandatory = true; - return prop; - } - - internal IDictionary GetMemberGroupValue(string username) - { - IEnumerable userRoles = _memberService.GetAllRoles(username); - - // create a dictionary of all roles (except internal roles) + "false" - var result = _memberGroupService.GetAll() - .Select(x => x.Name!) - // if a role starts with __umbracoRole we won't show it as it's an internal role used for public access - .Where(x => x?.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false) - .OrderBy(x => x, StringComparer.OrdinalIgnoreCase) - .ToDictionary(x => x, x => false); - - // if user has no roles, just return the dictionary - if (userRoles == null) - { - return result; - } - - // else update the dictionary to "true" for the user roles (except internal roles) - foreach (var userRole in userRoles.Where(x => x?.StartsWith(Constants.Conventions.Member.InternalRolePrefix) == false)) - { - result[userRole] = true; - } - - return result; - } - - public IEnumerable MapMembershipProperties(IMember member, MapperContext? context) - { - var isTwoFactorEnabled = _twoFactorLoginService.IsTwoFactorEnabledAsync(member.Key).Result; - - var properties = new List - { - GetLoginProperty(member, _localizedTextService), - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}email", - Label = _localizedTextService.Localize("general","email"), - Value = member.Email, - Validation = { Mandatory = true } - }, - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}password", - Label = _localizedTextService.Localize(null,"password"), - Value = new Dictionary - { - // TODO: why ignoreCase, what are we doing here?! - { "newPassword", member.GetAdditionalDataValueIgnoreCase("NewPassword", null) } - }, - Config = GetPasswordConfig(member) // Initialize the dictionary with the configuration from the default membership provider - }, - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}membergroup", - Label = _localizedTextService.Localize("content","membergroup"), - Value = GetMemberGroupValue(member.Username), - Config = new Dictionary - { - { "IsRequired", true } - }, - }, - - // These properties used to live on the member as property data, defaulting to sensitive, so we set them to sensitive here too - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}failedPasswordAttempts", - Label = _localizedTextService.Localize("user", "failedPasswordAttempts"), - Value = member.FailedPasswordAttempts, - IsSensitive = true, - }, - - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}approved", - Label = _localizedTextService.Localize("user", "stateApproved"), - Value = member.IsApproved, - IsSensitive = true, - Readonly = false, - }, - - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lockedOut", - Label = _localizedTextService.Localize("user", "stateLockedOut"), - Value = member.IsLockedOut, - IsSensitive = true, - Readonly = !member.IsLockedOut, // IMember.IsLockedOut can't be set to true, so make it readonly when that's the case (you can only unlock) - }, - - // Toggle for disabling Two-Factor Authentication for a Member - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}twoFactorEnabled", - Label = _localizedTextService.Localize("member", "2fa"), - Value = isTwoFactorEnabled, - IsSensitive = true, - Readonly = !isTwoFactorEnabled, // The value can't be set to true, so make it readonly when that's the case (you can only disable) - }, - - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLockoutDate", - Label = _localizedTextService.Localize("user", "lastLockoutDate"), - Value = member.LastLockoutDate?.ToString(), - IsSensitive = true, - }, - - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastLoginDate", - Label = _localizedTextService.Localize("user", "lastLogin"), - Value = member.LastLoginDate?.ToString(), - IsSensitive = true, - }, - - new() - { - Alias = $"{Constants.PropertyEditors.InternalGenericPropertiesPrefix}lastPasswordChangeDate", - Label = _localizedTextService.Localize("user", "lastPasswordChangeDate"), - Value = member.LastPasswordChangeDate?.ToString(), - IsSensitive = true, - }, - }; - - if (_backofficeSecurityAccessor.BackOfficeSecurity?.CurrentUser?.HasAccessToSensitiveData() is false) - { - // Current user doesn't have access to sensitive data so explicitly set the views and remove the value from sensitive data - foreach (ContentPropertyDisplay property in properties) - { - if (property.IsSensitive) - { - property.Value = null; - property.Readonly = true; - } - } - } - - return properties; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs b/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs deleted file mode 100644 index 8d6451886067..000000000000 --- a/src/Umbraco.Core/Models/Mapping/PropertyTypeGroupMapper.cs +++ /dev/null @@ -1,293 +0,0 @@ -using Microsoft.Extensions.Logging; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class PropertyTypeGroupMapper - where TPropertyType : PropertyTypeDisplay, new() -{ - private readonly IDataTypeService _dataTypeService; - private readonly ILogger> _logger; - private readonly PropertyEditorCollection _propertyEditors; - private readonly IShortStringHelper _shortStringHelper; - - public PropertyTypeGroupMapper(PropertyEditorCollection propertyEditors, IDataTypeService dataTypeService, IShortStringHelper shortStringHelper, ILogger> logger) - { - _propertyEditors = propertyEditors; - _dataTypeService = dataTypeService; - _shortStringHelper = shortStringHelper; - _logger = logger; - } - - public IEnumerable> Map(IContentTypeComposition source) - { - // deal with groups - var groups = new List>(); - - // add groups local to this content type - foreach (PropertyGroup propertyGroup in source.PropertyGroups) - { - var group = new PropertyGroupDisplay - { - Id = propertyGroup.Id, - Key = propertyGroup.Key, - Type = propertyGroup.Type, - Name = propertyGroup.Name, - Alias = propertyGroup.Alias, - SortOrder = propertyGroup.SortOrder, - Properties = MapProperties(propertyGroup.PropertyTypes, source, propertyGroup.Id, false), - ContentTypeId = source.Id, - }; - - groups.Add(group); - } - - // add groups inherited through composition - var localGroupIds = groups.Select(x => x.Id).ToArray(); - foreach (PropertyGroup propertyGroup in source.CompositionPropertyGroups) - { - // skip those that are local to this content type - if (localGroupIds.Contains(propertyGroup.Id)) - { - continue; - } - - // get the content type that defines this group - IContentTypeComposition? definingContentType = GetContentTypeForPropertyGroup(source, propertyGroup.Id); - if (definingContentType == null) - { - throw new Exception("PropertyGroup with id=" + propertyGroup.Id + - " was not found on any of the content type's compositions."); - } - - var group = new PropertyGroupDisplay - { - Inherited = true, - Id = propertyGroup.Id, - Key = propertyGroup.Key, - Type = propertyGroup.Type, - Name = propertyGroup.Name, - Alias = propertyGroup.Alias, - SortOrder = propertyGroup.SortOrder, - Properties = - MapProperties(propertyGroup.PropertyTypes, definingContentType, propertyGroup.Id, true), - ContentTypeId = definingContentType.Id, - ParentTabContentTypes = new[] { definingContentType.Id }, - ParentTabContentTypeNames = new[] { definingContentType.Name }, - }; - - groups.Add(group); - } - - // deal with generic properties - var genericProperties = new List(); - - // add generic properties local to this content type - IEnumerable entityGenericProperties = source.PropertyTypes.Where(x => x.PropertyGroupId == null); - genericProperties.AddRange(MapProperties(entityGenericProperties, source, PropertyGroupBasic.GenericPropertiesGroupId, false)); - - // add generic properties inherited through compositions - var localGenericPropertyIds = genericProperties.Select(x => x.Id).ToArray(); - IEnumerable compositionGenericProperties = source.CompositionPropertyTypes - .Where(x => x.PropertyGroupId == null // generic - && localGenericPropertyIds.Contains(x.Id) == false); // skip those that are local - foreach (IPropertyType compositionGenericProperty in compositionGenericProperties) - { - IContentTypeComposition? definingContentType = - GetContentTypeForPropertyType(source, compositionGenericProperty.Id); - if (definingContentType == null) - { - throw new Exception("PropertyType with id=" + compositionGenericProperty.Id + - " was not found on any of the content type's compositions."); - } - - genericProperties.AddRange(MapProperties(new[] { compositionGenericProperty }, definingContentType, PropertyGroupBasic.GenericPropertiesGroupId, true)); - } - - // if there are any generic properties, add the corresponding tab - if (genericProperties.Any()) - { - var genericGroup = new PropertyGroupDisplay - { - Id = PropertyGroupBasic.GenericPropertiesGroupId, - Name = "Generic properties", - Alias = "genericProperties", - SortOrder = 999, - Properties = genericProperties, - ContentTypeId = source.Id, - }; - - groups.Add(genericGroup); - } - - // handle locked properties - var lockedPropertyAliases = new List(); - - // add built-in member property aliases to list of aliases to be locked - foreach (var propertyAlias in ConventionsHelper.GetStandardPropertyTypeStubs(_shortStringHelper).Keys) - { - lockedPropertyAliases.Add(propertyAlias); - } - - // lock properties by aliases - foreach (TPropertyType property in groups.SelectMany(x => x.Properties)) - { - if (property.Alias is not null) - { - property.Locked = lockedPropertyAliases.Contains(property.Alias); - } - } - - // now merge tabs based on alias - // as for one name, we might have one local tab, plus some inherited tabs - IGrouping>[] groupsGroupsByAlias = - groups.GroupBy(x => x.Alias).ToArray(); - groups = new List>(); // start with a fresh list - foreach (IGrouping> groupsByAlias in groupsGroupsByAlias) - { - // single group, just use it - if (groupsByAlias.Count() == 1) - { - groups.Add(groupsByAlias.First()); - continue; - } - - // multiple groups, merge - PropertyGroupDisplay group = - groupsByAlias.FirstOrDefault(x => x.Inherited == false) // try local - ?? groupsByAlias.First(); // else pick one randomly - groups.Add(group); - - // in case we use the local one, flag as inherited - group.Inherited = - true; // TODO Remove to allow changing sort order of the local one (and use the inherited group order below) - - // merge (and sort) properties - TPropertyType[] properties = - groupsByAlias.SelectMany(x => x.Properties).OrderBy(x => x.SortOrder).ToArray(); - group.Properties = properties; - - // collect parent group info - PropertyGroupDisplay[] parentGroups = - groupsByAlias.Where(x => x.ContentTypeId != source.Id).ToArray(); - group.ParentTabContentTypes = parentGroups.SelectMany(x => x.ParentTabContentTypes).ToArray(); - group.ParentTabContentTypeNames = parentGroups.SelectMany(x => x.ParentTabContentTypeNames).ToArray(); - } - - return groups.OrderBy(x => x.SortOrder); - } - - /// - /// Gets the content type that defines a property group, within a composition. - /// - /// The composition. - /// The identifier of the property group. - /// The composition content type that defines the specified property group. - private static IContentTypeComposition? GetContentTypeForPropertyGroup( - IContentTypeComposition contentType, - int propertyGroupId) - { - // test local groups - if (contentType.PropertyGroups.Any(x => x.Id == propertyGroupId)) - { - return contentType; - } - - // test composition types groups - // .ContentTypeComposition is just the local ones, not recursive, - // so we have to recurse here - return contentType.ContentTypeComposition - .Select(x => GetContentTypeForPropertyGroup(x, propertyGroupId)) - .FirstOrDefault(x => x != null); - } - - /// - /// Gets the content type that defines a property group, within a composition. - /// - /// The composition. - /// The identifier of the property type. - /// The composition content type that defines the specified property group. - private static IContentTypeComposition? GetContentTypeForPropertyType( - IContentTypeComposition contentType, - int propertyTypeId) - { - // test local property types - if (contentType.PropertyTypes.Any(x => x.Id == propertyTypeId)) - { - return contentType; - } - - // test composition property types - // .ContentTypeComposition is just the local ones, not recursive, - // so we have to recurse here - return contentType.ContentTypeComposition - .Select(x => GetContentTypeForPropertyType(x, propertyTypeId)) - .FirstOrDefault(x => x != null); - } - - private IEnumerable MapProperties( - IEnumerable? properties, - IContentTypeBase contentType, - int groupId, - bool inherited) - { - var mappedProperties = new List(); - - foreach (IPropertyType p in properties?.Where(x => x.DataTypeId != 0).OrderBy(x => x.SortOrder) ?? - Enumerable.Empty()) - { - var propertyEditorAlias = p.PropertyEditorAlias; - IDataEditor? propertyEditor = _propertyEditors[propertyEditorAlias]; - IDataType? dataType = _dataTypeService.GetDataType(p.DataTypeId); - - // TODO: Don't explode if we can't find this, log an error and change this to a label - if (propertyEditor == null) - { - _logger.LogError( - "No property editor could be resolved with the alias: {PropertyEditorAlias}, defaulting to label", - p.PropertyEditorAlias); - propertyEditorAlias = Constants.PropertyEditors.Aliases.Label; - propertyEditor = _propertyEditors[propertyEditorAlias]; - } - - IDictionary? config = propertyEditor is null || dataType is null ? new Dictionary() - : dataType.Editor?.GetConfigurationEditor().ToConfigurationEditor(dataType.ConfigurationData); - - mappedProperties.Add(new TPropertyType - { - Id = p.Id, - Alias = p.Alias, - Description = p.Description, - LabelOnTop = p.LabelOnTop, - Editor = p.PropertyEditorAlias, - Validation = new PropertyTypeValidation - { - Mandatory = p.Mandatory, - MandatoryMessage = p.MandatoryMessage, - Pattern = p.ValidationRegExp, - PatternMessage = p.ValidationRegExpMessage, - }, - Label = p.Name, - Config = config, - - // Value = "", - GroupId = groupId, - Inherited = inherited, - DataTypeId = p.DataTypeId, - DataTypeKey = p.DataTypeKey, - DataTypeName = dataType?.Name, - SortOrder = p.SortOrder, - ContentTypeId = contentType.Id, - ContentTypeName = contentType.Name, - AllowCultureVariant = p.VariesByCulture(), - AllowSegmentVariant = p.VariesBySegment(), - }); - } - - return mappedProperties; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/RedirectUrlMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/RedirectUrlMapDefinition.cs deleted file mode 100644 index 8cdc24b18d66..000000000000 --- a/src/Umbraco.Core/Models/Mapping/RedirectUrlMapDefinition.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Routing; - -namespace Umbraco.Cms.Core.Models.Mapping; - -[Obsolete("Will no longer be used with new backoffice, use IRedirectUrlViewModelFactory instead")] -public class RedirectUrlMapDefinition : IMapDefinition -{ - private readonly IPublishedUrlProvider _publishedUrlProvider; - - public RedirectUrlMapDefinition(IPublishedUrlProvider publishedUrlProvider) => - _publishedUrlProvider = publishedUrlProvider; - - public void DefineMaps(IUmbracoMapper mapper) => - mapper.Define((source, context) => new ContentRedirectUrl(), Map); - - // Umbraco.Code.MapAll - private void Map(IRedirectUrl source, ContentRedirectUrl target, MapperContext context) - { - target.ContentId = source.ContentId; - target.CreateDateUtc = source.CreateDateUtc; - target.Culture = source.Culture; - target.DestinationUrl = source.ContentId > 0 - ? _publishedUrlProvider?.GetUrl(source.ContentId, culture: source.Culture) - : "#"; - target.OriginalUrl = _publishedUrlProvider?.GetUrlFromRoute(source.ContentId, source.Url, source.Culture); - target.RedirectId = source.Key; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/RelationMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/RelationMapDefinition.cs deleted file mode 100644 index d5658368474a..000000000000 --- a/src/Umbraco.Core/Models/Mapping/RelationMapDefinition.cs +++ /dev/null @@ -1,96 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.Entities; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class RelationMapDefinition : IMapDefinition -{ - private readonly IEntityService _entityService; - private readonly IRelationService _relationService; - - public RelationMapDefinition(IEntityService entityService, IRelationService relationService) - { - _entityService = entityService; - _relationService = relationService; - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new RelationTypeDisplay(), Map); - mapper.Define((source, context) => new RelationDisplay(), Map); - mapper.Define(Map); - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate - private static void Map(RelationTypeSave source, IRelationType target, MapperContext context) - { - target.Alias = source.Alias; - target.ChildObjectType = source.ChildObjectType; - target.Id = source.Id.TryConvertTo().Result; - target.IsBidirectional = source.IsBidirectional; - if (target is IRelationTypeWithIsDependency targetWithIsDependency) - { - targetWithIsDependency.IsDependency = source.IsDependency; - } - - target.Key = source.Key; - target.Name = source.Name; - target.ParentObjectType = source.ParentObjectType; - } - - // Umbraco.Code.MapAll -Icon -Trashed -AdditionalData - // Umbraco.Code.MapAll -ParentId -Notifications - private void Map(IRelationType source, RelationTypeDisplay target, MapperContext context) - { - target.ChildObjectType = source.ChildObjectType; - target.Id = source.Id; - target.IsBidirectional = source.IsBidirectional; - - if (source is IRelationTypeWithIsDependency sourceWithIsDependency) - { - target.IsDependency = sourceWithIsDependency.IsDependency; - } - - target.Key = source.Key; - target.Name = source.Name; - target.Alias = source.Alias; - target.ParentObjectType = source.ParentObjectType; - target.Udi = Udi.Create(Constants.UdiEntityType.RelationType, source.Key); - target.Path = "-1," + source.Id; - - target.IsSystemRelationType = source.IsSystemRelationType(); - - // Set the "friendly" and entity names for the parent and child object types - if (source.ParentObjectType.HasValue) - { - UmbracoObjectTypes objType = ObjectTypes.GetUmbracoObjectType(source.ParentObjectType.Value); - target.ParentObjectTypeName = objType.GetFriendlyName(); - } - - if (source.ChildObjectType.HasValue) - { - UmbracoObjectTypes objType = ObjectTypes.GetUmbracoObjectType(source.ChildObjectType.Value); - target.ChildObjectTypeName = objType.GetFriendlyName(); - } - } - - // Umbraco.Code.MapAll -ParentName -ChildName - private void Map(IRelation source, RelationDisplay target, MapperContext context) - { - target.ChildId = source.ChildId; - target.Comment = source.Comment; - target.CreateDate = source.CreateDate; - target.ParentId = source.ParentId; - - Tuple? entities = _relationService.GetEntitiesFromRelation(source); - - if (entities is not null) - { - target.ParentName = entities.Item1.Name; - target.ChildName = entities.Item2.Name; - } - } -} diff --git a/src/Umbraco.Core/Models/Mapping/TabsAndPropertiesMapper.cs b/src/Umbraco.Core/Models/Mapping/TabsAndPropertiesMapper.cs deleted file mode 100644 index 42ea05e8f9d5..000000000000 --- a/src/Umbraco.Core/Models/Mapping/TabsAndPropertiesMapper.cs +++ /dev/null @@ -1,156 +0,0 @@ -using Umbraco.Cms.Core.Dictionary; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public abstract class TabsAndPropertiesMapper -{ - protected TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService) - : this(cultureDictionary, localizedTextService, new List()) - { - } - - protected TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IEnumerable ignoreProperties) - { - CultureDictionary = cultureDictionary ?? throw new ArgumentNullException(nameof(cultureDictionary)); - LocalizedTextService = localizedTextService ?? throw new ArgumentNullException(nameof(localizedTextService)); - IgnoreProperties = ignoreProperties ?? throw new ArgumentNullException(nameof(ignoreProperties)); - } - - protected ICultureDictionary CultureDictionary { get; } - - protected ILocalizedTextService LocalizedTextService { get; } - - protected IEnumerable IgnoreProperties { get; set; } - - /// - /// Returns a collection of custom generic properties that exist on the generic properties tab - /// - /// - protected virtual IEnumerable GetCustomGenericProperties(IContentBase content) => - Enumerable.Empty(); - - /// - /// Maps properties on to the generic properties tab - /// - /// - /// - /// - /// - /// The generic properties tab is responsible for - /// setting up the properties such as Created date, updated date, template selected, etc... - /// - protected virtual void MapGenericProperties(IContentBase content, List> tabs, MapperContext context) - { - // add the generic properties tab, for properties that don't belong to a tab - // get the properties, map and translate them, then add the tab - var noGroupProperties = content.GetNonGroupedProperties() - .Where(x => IgnoreProperties.Contains(x.Alias) == false) // skip ignored - .ToList(); - List genericProperties = MapProperties(content, noGroupProperties, context); - - IEnumerable customProperties = GetCustomGenericProperties(content); - if (customProperties != null) - { - genericProperties.AddRange(customProperties); - } - - if (genericProperties.Count > 0) - { - tabs.Add(new Tab - { - Id = 0, - Label = LocalizedTextService.Localize("general", "properties"), - Alias = "Generic properties", - Properties = genericProperties, - }); - } - } - - /// - /// Maps a list of to a list of - /// - /// - /// - /// - /// - protected virtual List MapProperties(IContentBase content, List properties, MapperContext context) => - context.MapEnumerable(properties.OrderBy(x => x.PropertyType?.SortOrder)) - .WhereNotNull().ToList(); -} - -/// -/// Creates the tabs collection with properties assigned for display models -/// -public class TabsAndPropertiesMapper : TabsAndPropertiesMapper - where TSource : IContentBase -{ - private readonly IContentTypeBaseServiceProvider _contentTypeBaseServiceProvider; - - public TabsAndPropertiesMapper(ICultureDictionary cultureDictionary, ILocalizedTextService localizedTextService, IContentTypeBaseServiceProvider contentTypeBaseServiceProvider) - : base(cultureDictionary, localizedTextService) => - _contentTypeBaseServiceProvider = contentTypeBaseServiceProvider ?? - throw new ArgumentNullException(nameof(contentTypeBaseServiceProvider)); - - public virtual IEnumerable> Map(TSource source, MapperContext context) - { - var tabs = new List>(); - - // Property groups only exist on the content type (as it's only used for display purposes) - IContentTypeComposition? contentType = _contentTypeBaseServiceProvider.GetContentTypeOf(source); - - // Merge the groups, as compositions can introduce duplicate aliases - PropertyGroup[]? groups = contentType?.CompositionPropertyGroups.OrderBy(x => x.SortOrder).ToArray(); - var parentAliases = groups?.Select(x => x.GetParentAlias()).Distinct().ToArray(); - if (groups is not null) - { - foreach (IGrouping groupsByAlias in groups.GroupBy(x => x.Alias)) - { - var properties = new List(); - - // Merge properties for groups with the same alias - foreach (PropertyGroup group in groupsByAlias) - { - IEnumerable groupProperties = source.GetPropertiesForGroup(group) - .Where(x => IgnoreProperties.Contains(x.Alias) == false); // Skip ignored properties - - properties.AddRange(groupProperties); - } - - if (properties.Count == 0 && (!parentAliases?.Contains(groupsByAlias.Key) ?? false)) - { - continue; - } - - // Map the properties - List mappedProperties = MapProperties(source, properties, context); - - // Add the tab (the first is closest to the content type, e.g. local, then direct composition) - PropertyGroup g = groupsByAlias.First(); - - tabs.Add(new Tab - { - Id = g.Id, - Key = g.Key, - Type = g.Type.ToString(), - Alias = g.Alias, - Label = LocalizedTextService.UmbracoDictionaryTranslate(CultureDictionary, g.Name), - Properties = mappedProperties, - }); - } - } - - MapGenericProperties(source, tabs, context); - - // Activate the first tab, if any - if (tabs.Count > 0) - { - tabs[0].IsActive = true; - } - - return tabs; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/TemplateMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/TemplateMapDefinition.cs deleted file mode 100644 index 5afc8bc8d777..000000000000 --- a/src/Umbraco.Core/Models/Mapping/TemplateMapDefinition.cs +++ /dev/null @@ -1,47 +0,0 @@ -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Strings; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class TemplateMapDefinition : IMapDefinition -{ - private readonly IShortStringHelper _shortStringHelper; - - public TemplateMapDefinition(IShortStringHelper shortStringHelper) => _shortStringHelper = shortStringHelper; - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new TemplateDisplay(), Map); - mapper.Define( - (source, context) => new Template(_shortStringHelper, source.Name, source.Alias), Map); - } - - // Umbraco.Code.MapAll - private static void Map(ITemplate source, TemplateDisplay target, MapperContext context) - { - target.Id = source.Id; - target.Name = source.Name; - target.Alias = source.Alias; - target.Key = source.Key; - target.Content = source.Content; - target.Path = source.Path; - target.VirtualPath = source.VirtualPath; - target.MasterTemplateAlias = source.MasterTemplateAlias; - target.IsMasterTemplate = source.IsMasterTemplate; - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate - // Umbraco.Code.MapAll -Path -VirtualPath -MasterTemplateId -IsMasterTemplate - // Umbraco.Code.MapAll -GetFileContent - private static void Map(TemplateDisplay source, ITemplate target, MapperContext context) - { - // don't need to worry about mapping MasterTemplateAlias here; - // the template controller handles any changes made to the master template - target.Name = source.Name; - target.Alias = source.Alias; - target.Content = source.Content; - target.Id = source.Id; - target.Key = source.Key; - } -} diff --git a/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs b/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs deleted file mode 100644 index fe6df58824ae..000000000000 --- a/src/Umbraco.Core/Models/Mapping/UserMapDefinition.cs +++ /dev/null @@ -1,566 +0,0 @@ -using System.Globalization; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Options; -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Cache; -using Umbraco.Cms.Core.Configuration.Models; -using Umbraco.Cms.Core.DependencyInjection; -using Umbraco.Cms.Core.IO; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Media; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.Entities; -using Umbraco.Cms.Core.Models.Membership; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Extensions; -using UserProfile = Umbraco.Cms.Core.Models.ContentEditing.UserProfile; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class UserMapDefinition : IMapDefinition -{ - private readonly ActionCollection _actions; - private readonly AppCaches _appCaches; - private readonly IEntityService _entityService; - private readonly GlobalSettings _globalSettings; - private readonly IImageUrlGenerator _imageUrlGenerator; - private readonly MediaFileManager _mediaFileManager; - private readonly IShortStringHelper _shortStringHelper; - private readonly ILocalizedTextService _textService; - private readonly IUserService _userService; - private readonly ILocalizationService _localizationService; - private readonly IUserGroupService _userGroupService; - - public UserMapDefinition( - ILocalizedTextService textService, - IUserService userService, - IEntityService entityService, - AppCaches appCaches, - ActionCollection actions, - IOptions globalSettings, - MediaFileManager mediaFileManager, - IShortStringHelper shortStringHelper, - IImageUrlGenerator imageUrlGenerator, - ILocalizationService localizationService, - IUserGroupService userGroupService) - { - _entityService = entityService; - _userService = userService; - _textService = textService; - _actions = actions; - _appCaches = appCaches; - _globalSettings = globalSettings.Value; - _mediaFileManager = mediaFileManager; - _shortStringHelper = shortStringHelper; - _imageUrlGenerator = imageUrlGenerator; - _localizationService = localizationService; - _userGroupService = userGroupService; - } - - [Obsolete("Use constructor that takes IUserGroupService, scheduled for removal in V15.")] - public UserMapDefinition( - ILocalizedTextService textService, - IUserService userService, - IEntityService entityService, - AppCaches appCaches, - ActionCollection actions, - IOptions globalSettings, - MediaFileManager mediaFileManager, - IShortStringHelper shortStringHelper, - IImageUrlGenerator imageUrlGenerator, - ILocalizationService localizationService) - : this( - textService, - userService, - entityService, - appCaches, - actions, - globalSettings, - mediaFileManager, - shortStringHelper, - imageUrlGenerator, - localizationService, - StaticServiceProvider.Instance.GetRequiredService()) - { - } - - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define( - (source, context) => new UserGroup(_shortStringHelper) { CreateDate = DateTime.UtcNow }, Map); - mapper.Define(Map); - mapper.Define((source, context) => new UserProfile(), Map); - mapper.Define((source, context) => new UserGroupBasic(), Map); - mapper.Define((source, context) => new UserGroupBasic(), Map); - mapper.Define( - (source, context) => new AssignedUserGroupPermissions(), - Map); - mapper.Define( - (source, context) => new AssignedContentPermissions(), - Map); - mapper.Define((source, context) => new UserGroupDisplay(), Map); - mapper.Define((source, context) => new UserBasic(), Map); - mapper.Define((source, context) => new UserDetail(), Map); - - // used for merging existing UserSave to an existing IUser instance - this will not create an IUser instance! - mapper.Define(Map); - - // important! Currently we are never mapping to multiple UserDisplay objects but if we start doing that - // this will cause an N+1 and we'll need to change how this works. - mapper.Define((source, context) => new UserDisplay(), Map); - } - - // mappers - private static void Map(UserGroupSave source, IUserGroup target, MapperContext context) - { - if (!(target is UserGroup ttarget)) - { - throw new NotSupportedException($"{nameof(target)} must be a UserGroup."); - } - - Map(source, ttarget); - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate - private static void Map(UserGroupSave source, UserGroup target) - { - target.StartMediaId = source.StartMediaId; - target.StartContentId = source.StartContentId; - target.Icon = source.Icon; - target.Alias = source.Alias; - target.Name = source.Name; - target.Permissions = source.Permissions; - target.GranularPermissions = source.GranularPermissions; - target.Key = source.Key; - target.HasAccessToAllLanguages = source.HasAccessToAllLanguages; - - var id = GetIntId(source.Id); - if (id > 0) - { - target.Id = id; - } - - target.ClearAllowedSections(); - if (source.Sections is not null) - { - foreach (var section in source.Sections) - { - target.AddAllowedSection(section); - } - } - - target.ClearAllowedLanguages(); - if (source.AllowedLanguages is not null) - { - foreach (var language in source.AllowedLanguages) - { - target.AddAllowedLanguage(language); - } - } - } - - // Umbraco.Code.MapAll - private static void Map(IProfile source, UserProfile target, MapperContext context) - { - target.Name = source.Name; - target.UserId = source.Id; - } - - // Umbraco.Code.MapAll -Trashed -Alias -AssignedPermissions - private static void Map(EntitySlim source, AssignedContentPermissions target, MapperContext context) - { - target.Icon = MapContentTypeIcon(source); - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); - - if (source.NodeObjectType == Constants.ObjectTypes.Member && target.Icon.IsNullOrWhiteSpace()) - { - target.Icon = Constants.Icons.Member; - } - } - - private static string? MapContentTypeIcon(IEntitySlim entity) - => entity is IContentEntitySlim contentEntity ? contentEntity.ContentTypeIcon : null; - - private static int GetIntId(object? id) - { - if (id is string strId && - int.TryParse(strId, NumberStyles.Integer, CultureInfo.InvariantCulture, out var asInt)) - { - return asInt; - } - - Attempt result = id.TryConvertTo(); - if (result.Success == false) - { - throw new InvalidOperationException( - "Cannot convert the profile to a " + typeof(UserDetail).Name + - " object since the id is not an integer"); - } - - return result.Result; - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate - // Umbraco.Code.MapAll -Id -TourData -StartContentIds -StartMediaIds -Language -Username - // Umbraco.Code.MapAll -PasswordQuestion -SessionTimeout -EmailConfirmedDate -InvitedDate - // Umbraco.Code.MapAll -SecurityStamp -Avatar -ProviderUserKey -RawPasswordValue - // Umbraco.Code.MapAll -RawPasswordAnswerValue -Comments -IsApproved -IsLockedOut -LastLoginDate - // Umbraco.Code.MapAll -LastPasswordChangeDate -LastLockoutDate -FailedPasswordAttempts - // Umbraco.Code.MapAll -PasswordConfiguration - private void Map(UserInvite source, IUser target, MapperContext context) - { - target.Email = source.Email; - target.Key = source.Key; - target.Name = source.Name; - target.IsApproved = false; - - target.ClearGroups(); - IEnumerable groups = _userGroupService.GetAsync(source.UserGroups.ToArray()).GetAwaiter().GetResult(); - foreach (IUserGroup group in groups) - { - target.AddGroup(group.ToReadOnlyGroup()); - } - } - - // Umbraco.Code.MapAll -CreateDate -UpdateDate -DeleteDate - // Umbraco.Code.MapAll -TourData -SessionTimeout -EmailConfirmedDate -InvitedDate -SecurityStamp -Avatar - // Umbraco.Code.MapAll -ProviderUserKey -RawPasswordValue -RawPasswordAnswerValue -PasswordQuestion -Comments - // Umbraco.Code.MapAll -IsApproved -IsLockedOut -LastLoginDate -LastPasswordChangeDate -LastLockoutDate - // Umbraco.Code.MapAll -FailedPasswordAttempts - // Umbraco.Code.MapAll -PasswordConfiguration - private void Map(UserSave source, IUser target, MapperContext context) - { - target.Name = source.Name; - target.StartContentIds = source.StartContentIds ?? Array.Empty(); - target.StartMediaIds = source.StartMediaIds ?? Array.Empty(); - target.Language = source.Culture; - target.Email = source.Email; - target.Key = source.Key; - target.Username = source.Username; - target.Id = source.Id; - - target.ClearGroups(); - IEnumerable groups = _userGroupService.GetAsync(source.UserGroups.ToArray()).GetAwaiter().GetResult(); - foreach (IUserGroup group in groups) - { - target.AddGroup(group.ToReadOnlyGroup()); - } - } - - // Umbraco.Code.MapAll -ContentStartNode -UserCount -MediaStartNode -Key -Languages -Sections - // Umbraco.Code.MapAll -Notifications -Udi -Trashed -AdditionalData -IsSystemUserGroup - private void Map(IReadOnlyUserGroup source, UserGroupBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = source.Icon; - target.Id = source.Id; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.IsSystemUserGroup = source.IsSystemUserGroup(); - target.HasAccessToAllLanguages = source.HasAccessToAllLanguages; - - MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); - } - - // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Languages -Sections -Notifications - // Umbraco.Code.MapAll -Udi -Trashed -AdditionalData -IsSystemUserGroup - private void Map(IUserGroup source, UserGroupBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = source.Icon; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.UserCount = source.UserCount; - target.IsSystemUserGroup = source.IsSystemUserGroup(); - target.HasAccessToAllLanguages = source.HasAccessToAllLanguages; - - MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); - } - - // Umbraco.Code.MapAll -Udi -Trashed -AdditionalData -AssignedPermissions - private void Map(IUserGroup source, AssignedUserGroupPermissions target, MapperContext context) - { - target.Id = source.Id; - target.Alias = source.Alias; - target.Icon = source.Icon; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - - target.DefaultPermissions = MapUserGroupDefaultPermissions(source); - - if (target.Icon.IsNullOrWhiteSpace()) - { - target.Icon = Constants.Icons.UserGroup; - } - } - - // Umbraco.Code.MapAll -ContentStartNode -MediaStartNode -Languages -Sections -Notifications -Udi - // Umbraco.Code.MapAll -Trashed -AdditionalData -Users -AssignedPermissions - private void Map(IUserGroup source, UserGroupDisplay target, MapperContext context) - { - target.Alias = source.Alias; - target.DefaultPermissions = MapUserGroupDefaultPermissions(source); - target.Icon = source.Icon; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.UserCount = source.UserCount; - target.IsSystemUserGroup = source.IsSystemUserGroup(); - target.HasAccessToAllLanguages = source.HasAccessToAllLanguages; - - MapUserGroupBasic(target, source.AllowedLanguages, source.AllowedSections, source.StartContentId, source.StartMediaId, context); - - // Important! Currently we are never mapping to multiple UserGroupDisplay objects but if we start doing that - // this will cause an N+1 and we'll need to change how this works. - IEnumerable users = _userService.GetAllInGroup(source.Id); - target.Users = context.MapEnumerable(users).WhereNotNull(); - - // Deal with assigned permissions: - var allContentPermissions = _userService.GetPermissions(source, true) - .ToDictionary(x => x.EntityId, x => x); - - IEntitySlim[] contentEntities; - if (allContentPermissions.Keys.Count == 0) - { - contentEntities = Array.Empty(); - } - else - { - // a group can end up with way more than 2000 assigned permissions, - // so we need to break them into groups in order to avoid breaking - // the entity service due to too many Sql parameters. - var list = new List(); - foreach (IEnumerable idGroup in allContentPermissions.Keys.InGroupsOf(Constants.Sql.MaxParameterCount)) - { - list.AddRange(_entityService.GetAll(UmbracoObjectTypes.Document, idGroup.ToArray())); - } - - contentEntities = list.ToArray(); - } - - var allAssignedPermissions = new List(); - foreach (IEntitySlim entity in contentEntities) - { - EntityPermission contentPermissions = allContentPermissions[entity.Id]; - - AssignedContentPermissions? assignedContentPermissions = context.Map(entity); - if (assignedContentPermissions is null) - { - continue; - } - - assignedContentPermissions.AssignedPermissions = - AssignedUserGroupPermissions.ClonePermissions(target.DefaultPermissions); - - // since there is custom permissions assigned to this node for this group, we need to clear all of the default permissions - // and we'll re-check it if it's one of the explicitly assigned ones - foreach (Permission permission in assignedContentPermissions.AssignedPermissions.SelectMany(x => x.Value)) - { - permission.Checked = false; - permission.Checked = - contentPermissions.AssignedPermissions.Contains( - permission.PermissionCode, - StringComparer.InvariantCulture); - } - - allAssignedPermissions.Add(assignedContentPermissions); - } - - target.AssignedPermissions = allAssignedPermissions; - } - - // Umbraco.Code.MapAll -Notifications -Udi -Icon -IsCurrentUser -Trashed -ResetPasswordValue - // Umbraco.Code.MapAll -Alias -AdditionalData - private void Map(IUser source, UserDisplay target, MapperContext context) - { - target.AvailableCultures = _textService.GetSupportedCultures().ToDictionary(x => x.Name, x => x.DisplayName); - target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileManager, _imageUrlGenerator); - target.CalculatedStartContentIds = - GetStartNodes(source.CalculateContentStartNodeIds(_entityService, _appCaches), UmbracoObjectTypes.Document, "content", "contentRoot", context); - target.CalculatedStartMediaIds = GetStartNodes(source.CalculateMediaStartNodeIds(_entityService, _appCaches), UmbracoObjectTypes.Media, "media", "mediaRoot", context); - target.CreateDate = source.CreateDate; - target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString(); - target.Email = source.Email; - target.EmailHash = source.Email?.ToLowerInvariant().Trim().GenerateHash(); - target.FailedPasswordAttempts = source.FailedPasswordAttempts; - target.Id = source.Id; - target.Key = source.Key; - target.LastLockoutDate = source.LastLockoutDate; - target.LastLoginDate = source.LastLoginDate == default(DateTime) ? null : source.LastLoginDate; - target.LastPasswordChangeDate = source.LastPasswordChangeDate; - target.Name = source.Name; - target.Navigation = CreateUserEditorNavigation(); - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.StartContentIds = GetStartNodes(source.StartContentIds?.ToArray(), UmbracoObjectTypes.Document, "content", "contentRoot", context); - target.StartMediaIds = GetStartNodes(source.StartMediaIds?.ToArray(), UmbracoObjectTypes.Media, "media", "mediaRoot", context); - target.UpdateDate = source.UpdateDate; - target.UserGroups = context.MapEnumerable(source.Groups).WhereNotNull(); - target.Username = source.Username; - target.UserState = source.UserState; - } - - // Umbraco.Code.MapAll -Notifications -IsCurrentUser -Udi -Icon -Trashed -Alias -AdditionalData - private void Map(IUser source, UserBasic target, MapperContext context) - { - // Loading in the user avatar's requires an external request if they don't have a local file avatar, this means that initial load of paging may incur a cost - // Alternatively, if this is annoying the back office UI would need to be updated to request the avatars for the list of users separately so it doesn't look - // like the load time is waiting. - target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileManager, _imageUrlGenerator); - target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString(); - target.Email = source.Email; - target.EmailHash = source.Email?.ToLowerInvariant().Trim().GenerateHash(); - target.Id = source.Id; - target.Key = source.Key; - target.LastLoginDate = source.LastLoginDate == default ? null : source.LastLoginDate; - target.Name = source.Name; - target.ParentId = -1; - target.Path = "-1," + source.Id; - target.UserGroups = context.MapEnumerable(source.Groups).WhereNotNull(); - target.Username = source.Username; - target.UserState = source.UserState; - } - - // Umbraco.Code.MapAll -SecondsUntilTimeout - private void Map(IUser source, UserDetail target, MapperContext context) - { - target.AllowedSections = source.AllowedSections; - target.AllowedLanguageIds = source.CalculateAllowedLanguageIds(_localizationService); - target.Avatars = source.GetUserAvatarUrls(_appCaches.RuntimeCache, _mediaFileManager, _imageUrlGenerator); - target.Culture = source.GetUserCulture(_textService, _globalSettings).ToString(); - target.Email = source.Email; - target.EmailHash = source.Email?.ToLowerInvariant().Trim().GenerateHash(); - target.Name = source.Name; - target.StartContentIds = source.CalculateContentStartNodeIds(_entityService, _appCaches); - target.StartMediaIds = source.CalculateMediaStartNodeIds(_entityService, _appCaches); - target.UserId = source.Id; - - // we need to map the legacy UserType - // the best we can do here is to return the user's first user group as a IUserType object - // but we should attempt to return any group that is the built in ones first - target.UserGroups = source.Groups.Select(x => x.Alias).ToArray(); - } - - // helpers - private void MapUserGroupBasic(UserGroupBasic target, IEnumerable sourceAllowedLanguages, IEnumerable sourceAllowedSections, int? sourceStartContentId, int? sourceStartMediaId, MapperContext context) - { - var allLanguages = _localizationService.GetAllLanguages(); - var applicableLanguages = Enumerable.Empty(); - - - if (sourceAllowedLanguages.Any()) - { - applicableLanguages = allLanguages.Where(x => sourceAllowedLanguages.Contains(x.Id)); - } - - target.Languages = context.MapEnumerable(applicableLanguages).WhereNotNull(); - - if (sourceStartMediaId > 0) - { - target.MediaStartNode = - context.Map(_entityService.Get(sourceStartMediaId.Value, UmbracoObjectTypes.Media)); - } - else if (sourceStartMediaId == -1) - { - target.MediaStartNode = CreateRootNode(_textService.Localize("media", "mediaRoot")); - } - - if (sourceStartContentId > 0) - { - target.ContentStartNode = - context.Map(_entityService.Get(sourceStartContentId.Value, UmbracoObjectTypes.Document)); - } - else if (sourceStartContentId == -1) - { - target.ContentStartNode = CreateRootNode(_textService.Localize("content", "contentRoot")); - } - - if (target.Icon.IsNullOrWhiteSpace()) - { - target.Icon = Constants.Icons.UserGroup; - } - } - - private IDictionary> MapUserGroupDefaultPermissions(IUserGroup source) - { - Permission GetPermission(IAction action) - { - return new() - { - Category = action.Category.IsNullOrWhiteSpace() - ? _textService.Localize( - "actionCategories", - Constants.Conventions.PermissionCategories.OtherCategory) - : _textService.Localize("actionCategories", action.Category), - Name = _textService.Localize("actions", action.Alias), - Description = _textService.Localize("actionDescriptions", action.Alias), - Icon = action.Icon, - Checked = source.Permissions != null && - source.Permissions.Contains(action.Letter), - PermissionCode = action.Letter.ToString(CultureInfo.InvariantCulture), - }; - } - - return _actions - .Where(x => x.CanBePermissionAssigned) - .Select(GetPermission) - .GroupBy(x => x.Category) - .ToDictionary(x => x.Key, x => (IEnumerable)x.ToArray()); - } - - private IEnumerable GetStartNodes(int[]? startNodeIds, UmbracoObjectTypes objectType, string localizedArea, string localizedAlias, MapperContext context) - { - if (startNodeIds is null || startNodeIds.Length <= 0) - { - return Enumerable.Empty(); - } - - var startNodes = new List(); - if (startNodeIds.Contains(-1)) - { - startNodes.Add(CreateRootNode(_textService.Localize(localizedArea, localizedAlias))); - } - - IEnumerable mediaItems = _entityService.GetAll(objectType, startNodeIds); - startNodes.AddRange(context.MapEnumerable(mediaItems).WhereNotNull()); - return startNodes; - } - - private IEnumerable CreateUserEditorNavigation() => - new[] - { - new EditorNavigation - { - Active = true, - Alias = "details", - Icon = "icon-umb-users", - Name = _textService.Localize("general", "user"), - View = "views/users/views/user/details.html", - }, - }; - - private EntityBasic CreateRootNode(string name) => - new EntityBasic - { - Name = name, - Path = "-1", - Icon = "icon-folder", - Id = -1, - Trashed = false, - ParentId = -1, - }; -} diff --git a/src/Umbraco.Core/Models/MigrationEntry.cs b/src/Umbraco.Core/Models/MigrationEntry.cs deleted file mode 100644 index ab1294b13efe..000000000000 --- a/src/Umbraco.Core/Models/MigrationEntry.cs +++ /dev/null @@ -1,34 +0,0 @@ -using Umbraco.Cms.Core.Models.Entities; -using Umbraco.Cms.Core.Semver; - -namespace Umbraco.Cms.Core.Models; - -public class MigrationEntry : EntityBase, IMigrationEntry -{ - private string? _migrationName; - private SemVersion? _version; - - public MigrationEntry() - { - } - - public MigrationEntry(int id, DateTime createDate, string migrationName, SemVersion version) - { - Id = id; - CreateDate = createDate; - _migrationName = migrationName; - _version = version; - } - - public string? MigrationName - { - get => _migrationName; - set => SetPropertyValueAndDetectChanges(value, ref _migrationName, nameof(MigrationName)); - } - - public SemVersion? Version - { - get => _version; - set => SetPropertyValueAndDetectChanges(value, ref _version, nameof(Version)); - } -} diff --git a/src/Umbraco.Core/Models/RichTextStylesheetData.cs b/src/Umbraco.Core/Models/RichTextStylesheetData.cs deleted file mode 100644 index 58bfa4ec4ad5..000000000000 --- a/src/Umbraco.Core/Models/RichTextStylesheetData.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Umbraco.Cms.Core.Strings.Css; - -namespace Umbraco.Cms.Core.Models; - -public class RichTextStylesheetData -{ - public string? Content { get; set; } - - public StylesheetRule[] Rules { get; set; } = Array.Empty(); -} diff --git a/src/Umbraco.Core/Models/SetPasswordModel.cs b/src/Umbraco.Core/Models/SetPasswordModel.cs deleted file mode 100644 index 58803c101d10..000000000000 --- a/src/Umbraco.Core/Models/SetPasswordModel.cs +++ /dev/null @@ -1,20 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models; - -[DataContract(Name = "setPassword", Namespace = "")] -public class SetPasswordModel -{ - [Required] - [DataMember(Name = "userId", IsRequired = true)] - public int UserId { get; set; } - - [Required] - [DataMember(Name = "password", IsRequired = true)] - public required string Password { get; set; } - - [Required] - [DataMember(Name = "resetCode", IsRequired = true)] - public required string ResetCode { get; set; } -} diff --git a/src/Umbraco.Core/Models/TemplateNode.cs b/src/Umbraco.Core/Models/TemplateNode.cs deleted file mode 100644 index f02988e6d2b8..000000000000 --- a/src/Umbraco.Core/Models/TemplateNode.cs +++ /dev/null @@ -1,31 +0,0 @@ -namespace Umbraco.Cms.Core.Models; - -/// -/// Represents a template in a template tree -/// -public class TemplateNode -{ - public TemplateNode(ITemplate template) - { - Template = template; - Children = new List(); - } - - /// - /// The current template - /// - public ITemplate Template { get; set; } - - /// - /// The children of the current template - /// - public IEnumerable Children { get; set; } - - /// - /// The parent template to the current template - /// - /// - /// Will be null if there is no parent - /// - public TemplateNode? Parent { get; set; } -} diff --git a/src/Umbraco.Core/Models/Trees/ActionMenuItem.cs b/src/Umbraco.Core/Models/Trees/ActionMenuItem.cs deleted file mode 100644 index 7fdcc4f76f9b..000000000000 --- a/src/Umbraco.Core/Models/Trees/ActionMenuItem.cs +++ /dev/null @@ -1,52 +0,0 @@ -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Trees; - -/// -/// -/// A menu item that represents some JS that needs to execute when the menu item is clicked. -/// -/// -/// These types of menu items are rare but they do exist. Things like refresh node simply execute -/// JS and don't launch a dialog. -/// Each action menu item describes what angular service that it's method exists in and what the method name is. -/// An action menu item must describe the angular service name for which it's method exists. It may also define what -/// the -/// method name is that will be called in this service but if one is not specified then we will assume the method name -/// is the -/// same as the Type name of the current action menu class. -/// -public abstract class ActionMenuItem : MenuItem -{ - protected ActionMenuItem(string alias, string name) - : base(alias, name) => Initialize(); - - protected ActionMenuItem(string alias, ILocalizedTextService textService) - : base(alias, textService) => - Initialize(); - - /// - /// The angular service name containing the - /// - public abstract string AngularServiceName { get; } - - /// - /// The angular service method name to call for this menu item - /// - public virtual string? AngularServiceMethodName { get; } = null; - - private void Initialize() - { - // add the current type to the metadata - if (AngularServiceMethodName.IsNullOrWhiteSpace()) - { - // if no method name is supplied we will assume that the menu action is the type name of the current menu class - ExecuteJsMethod($"{AngularServiceName}.{GetType().Name}"); - } - else - { - ExecuteJsMethod($"{AngularServiceName}.{AngularServiceMethodName}"); - } - } -} diff --git a/src/Umbraco.Core/Models/Trees/CreateChildEntity.cs b/src/Umbraco.Core/Models/Trees/CreateChildEntity.cs deleted file mode 100644 index 7b3d8f2932ce..000000000000 --- a/src/Umbraco.Core/Models/Trees/CreateChildEntity.cs +++ /dev/null @@ -1,31 +0,0 @@ -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.Models.Trees; - -/// - /// Represents the refresh node menu item -/// -public sealed class CreateChildEntity : ActionMenuItem -{ - private const string icon = "icon-add"; - - public CreateChildEntity(string name, bool separatorBefore = false) - : base(ActionNew.ActionAlias, name) - { - Icon = icon; - Name = name; - SeparatorBefore = separatorBefore; - UseLegacyIcon = false; - } - - public CreateChildEntity(ILocalizedTextService textService, bool separatorBefore = false) - : base(ActionNew.ActionAlias, textService) - { - Icon = icon; - SeparatorBefore = separatorBefore; - UseLegacyIcon = false; - } - - public override string AngularServiceName => "umbracoMenuActions"; -} diff --git a/src/Umbraco.Core/Models/Trees/ExportMember.cs b/src/Umbraco.Core/Models/Trees/ExportMember.cs deleted file mode 100644 index 2039a827cf6c..000000000000 --- a/src/Umbraco.Core/Models/Trees/ExportMember.cs +++ /dev/null @@ -1,18 +0,0 @@ -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.Models.Trees; - -/// -/// Represents the export member menu item -/// -public sealed class ExportMember : ActionMenuItem -{ - public ExportMember(ILocalizedTextService textService) - : base("export", textService) - { - Icon = "icon-download-alt"; - UseLegacyIcon = false; - } - - public override string AngularServiceName => "umbracoMenuActions"; -} diff --git a/src/Umbraco.Core/Models/Trees/MenuItem.cs b/src/Umbraco.Core/Models/Trees/MenuItem.cs deleted file mode 100644 index e99e0d598a85..000000000000 --- a/src/Umbraco.Core/Models/Trees/MenuItem.cs +++ /dev/null @@ -1,208 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Trees; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Trees; - -/// - /// A context menu item -/// -[DataContract(Name = "menuItem", Namespace = "")] -public class MenuItem -{ - #region Constructors - - public MenuItem() - { - AdditionalData = new Dictionary(); - Icon = Constants.Icons.Folder; - } - - public MenuItem(string alias, string name) - : this() - { - Alias = alias; - Name = name; - } - - public MenuItem(string alias, ILocalizedTextService textService) - : this() - { - Alias = alias; - Name = textService.Localize("actions", Alias); - TextDescription = textService.Localize("visuallyHiddenTexts", alias + "_description", Thread.CurrentThread.CurrentUICulture); - } - - /// - /// Create a menu item based on an definition - /// - /// - /// - public MenuItem(IAction action, string name = "") - : this() - { - Name = name.IsNullOrWhiteSpace() ? action.Alias : name; - Alias = action.Alias; - SeparatorBefore = false; - Icon = action.Icon; - Action = action; - } - - #endregion - - #region Properties - - [IgnoreDataMember] - public IAction? Action { get; set; } - - /// - /// A dictionary to support any additional meta data that should be rendered for the node which is - /// useful for custom action commands such as 'create', 'copy', etc... - /// - /// - /// We will also use the meta data collection for dealing with legacy menu items (i.e. for loading custom URLs or - /// executing custom JS). - /// - [DataMember(Name = "metaData")] - public Dictionary AdditionalData { get; private set; } - - [DataMember(Name = "name", IsRequired = true)] - [Required] - public string? Name { get; set; } - - [DataMember(Name = "alias", IsRequired = true)] - [Required] - public string? Alias { get; set; } - - [DataMember(Name = "textDescription")] - public string? TextDescription { get; set; } - - /// - /// Ensures a menu separator will exist before this menu item - /// - [DataMember(Name = "separator")] - public bool SeparatorBefore { get; set; } - - /// - /// Icon to use at action menu item. - /// - [DataMember(Name = "icon")] - public string Icon { get; set; } - - /// - /// Used in the UI to indicate whether icons should be prefixed with "icon-". - /// If not legacy icon full icon name should be specified. - /// - [DataMember(Name = "useLegacyIcon")] - public bool UseLegacyIcon { get; set; } = true; - - /// - /// Used in the UI to inform the user that the menu item will open a dialog/confirmation - /// - [DataMember(Name = "opensDialog")] - public bool OpensDialog { get; set; } - - #endregion - - #region Constants - - /// - /// Used as a key for the AdditionalData to specify a specific dialog title instead of the menu title - /// - internal const string DialogTitleKey = "dialogTitle"; - - /// - /// Used to specify the URL that the dialog will launch to in an iframe - /// - internal const string ActionUrlKey = "actionUrl"; - - // TODO: some action's want to launch a new window like live editing, we support this in the menu item's metadata with - // a key called: "actionUrlMethod" which can be set to either: Dialog, BlankWindow. Normally this is always set to Dialog - // if a URL is specified in the "actionUrl" metadata. For now I'm not going to implement launching in a blank window, - // though would be v-easy, just not sure we want to ever support that? - internal const string ActionUrlMethodKey = "actionUrlMethod"; - - /// - /// Used to specify the angular view that the dialog will launch - /// - internal const string ActionViewKey = "actionView"; - - /// - /// Used to specify the js method to execute for the menu item - /// - internal const string JsActionKey = "jsAction"; - - /// - /// Used to specify an angular route to go to for the menu item - /// - internal const string ActionRouteKey = "actionRoute"; - - #endregion - - #region Methods - - /// - /// Sets the menu item to navigate to the specified angular route path - /// - /// - public void NavigateToRoute(string route) => AdditionalData[ActionRouteKey] = route; - - /// - /// Adds the required meta data to the menu item so that angular knows to attempt to call the Js method. - /// - /// - public void ExecuteJsMethod(string jsToExecute) => SetJsAction(jsToExecute); - - /// - /// Sets the menu item to display a dialog based on an angular view path - /// - /// - /// - public void LaunchDialogView(string view, string dialogTitle) - { - SetDialogTitle(dialogTitle); - SetActionView(view); - } - - /// - /// Sets the menu item to display a dialog based on a URL path in an iframe - /// - /// - /// - public void LaunchDialogUrl(string url, string dialogTitle) - { - SetDialogTitle(dialogTitle); - SetActionUrl(url); - } - - private void SetJsAction(string jsToExecute) => AdditionalData[JsActionKey] = jsToExecute; - - /// - /// Puts a dialog title into the meta data to be displayed on the dialog of the menu item (if there is one) - /// instead of the menu name - /// - /// - private void SetDialogTitle(string dialogTitle) => AdditionalData[DialogTitleKey] = dialogTitle; - - /// - /// Configures the menu item to launch a specific view - /// - /// - private void SetActionView(string view) => AdditionalData[ActionViewKey] = view; - - /// - /// Configures the menu item to launch a URL with the specified action (dialog or new window) - /// - /// - /// - private void SetActionUrl(string url, ActionUrlMethod method = ActionUrlMethod.Dialog) - { - AdditionalData[ActionUrlKey] = url; - AdditionalData[ActionUrlMethodKey] = method; - } - - #endregion -} diff --git a/src/Umbraco.Core/Models/Trees/RefreshNode.cs b/src/Umbraco.Core/Models/Trees/RefreshNode.cs deleted file mode 100644 index c10cdfcdf520..000000000000 --- a/src/Umbraco.Core/Models/Trees/RefreshNode.cs +++ /dev/null @@ -1,30 +0,0 @@ -using Umbraco.Cms.Core.Services; - -namespace Umbraco.Cms.Core.Models.Trees; - -/// -/// -/// Represents the refresh node menu item -/// -public sealed class RefreshNode : ActionMenuItem -{ - private const string icon = "icon-refresh"; - - public RefreshNode(string name, bool separatorBefore = false) - : base("refreshNode", name) - { - Icon = icon; - SeparatorBefore = separatorBefore; - UseLegacyIcon = false; - } - - public RefreshNode(ILocalizedTextService textService, bool separatorBefore = false) - : base("refreshNode", textService) - { - Icon = icon; - SeparatorBefore = separatorBefore; - UseLegacyIcon = false; - } - - public override string AngularServiceName => "umbracoMenuActions"; -} diff --git a/src/Umbraco.Core/Models/UnLinkLoginModel.cs b/src/Umbraco.Core/Models/UnLinkLoginModel.cs deleted file mode 100644 index ba4d881b734f..000000000000 --- a/src/Umbraco.Core/Models/UnLinkLoginModel.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models; - -public class UnLinkLoginModel -{ - [Required] - [DataMember(Name = "loginProvider", IsRequired = true)] - public required string LoginProvider { get; set; } - - [Required] - [DataMember(Name = "providerKey", IsRequired = true)] - public required string ProviderKey { get; set; } -} diff --git a/src/Umbraco.Core/Models/UpgradeCheckResponse.cs b/src/Umbraco.Core/Models/UpgradeCheckResponse.cs deleted file mode 100644 index b639616524e5..000000000000 --- a/src/Umbraco.Core/Models/UpgradeCheckResponse.cs +++ /dev/null @@ -1,29 +0,0 @@ -using System.Net; -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Configuration; - -namespace Umbraco.Cms.Core.Models; - -[DataContract(Name = "upgrade", Namespace = "")] -public class UpgradeCheckResponse -{ - public UpgradeCheckResponse() - { - } - - public UpgradeCheckResponse(string upgradeType, string upgradeComment, string upgradeUrl, IUmbracoVersion umbracoVersion) - { - Type = upgradeType; - Comment = upgradeComment; - Url = upgradeUrl + "?version=" + WebUtility.UrlEncode(umbracoVersion.Version?.ToString(3)); - } - - [DataMember(Name = "type")] - public string? Type { get; set; } - - [DataMember(Name = "comment")] - public string? Comment { get; set; } - - [DataMember(Name = "url")] - public string? Url { get; set; } -} diff --git a/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs b/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs deleted file mode 100644 index b4ebb89e47ec..000000000000 --- a/src/Umbraco.Core/Models/ValidatePasswordResetCodeModel.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.ComponentModel.DataAnnotations; -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Models; - -[Serializable] -[DataContract(Name = "validatePasswordReset", Namespace = "")] -public class ValidatePasswordResetCodeModel -{ - [Required] - [DataMember(Name = "userId", IsRequired = true)] - public int UserId { get; set; } - - [Required] - [DataMember(Name = "resetCode", IsRequired = true)] - public string? ResetCode { get; set; } -} diff --git a/src/Umbraco.Core/Notifications/SendingAllowedChildrenNotification.cs b/src/Umbraco.Core/Notifications/SendingAllowedChildrenNotification.cs deleted file mode 100644 index ff57f9c902bc..000000000000 --- a/src/Umbraco.Core/Notifications/SendingAllowedChildrenNotification.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Web; - -namespace Umbraco.Cms.Core.Notifications; - -public class SendingAllowedChildrenNotification : INotification -{ - public SendingAllowedChildrenNotification(IEnumerable children, IUmbracoContext umbracoContext) - { - UmbracoContext = umbracoContext; - Children = children; - } - - public IUmbracoContext UmbracoContext { get; } - - public IEnumerable Children { get; set; } -} diff --git a/src/Umbraco.Core/Notifications/SendingContentNotification.cs b/src/Umbraco.Core/Notifications/SendingContentNotification.cs deleted file mode 100644 index a42fefca68c6..000000000000 --- a/src/Umbraco.Core/Notifications/SendingContentNotification.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Web; - -namespace Umbraco.Cms.Core.Notifications; - -public class SendingContentNotification : INotification -{ - public SendingContentNotification(ContentItemDisplay content, IUmbracoContext umbracoContext) - { - Content = content; - UmbracoContext = umbracoContext; - } - - public IUmbracoContext UmbracoContext { get; } - - public ContentItemDisplay Content { get; } -} diff --git a/src/Umbraco.Core/Notifications/SendingMediaNotification.cs b/src/Umbraco.Core/Notifications/SendingMediaNotification.cs deleted file mode 100644 index cca282b3eaaf..000000000000 --- a/src/Umbraco.Core/Notifications/SendingMediaNotification.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Web; - -namespace Umbraco.Cms.Core.Notifications; - -public class SendingMediaNotification : INotification -{ - public SendingMediaNotification(MediaItemDisplay media, IUmbracoContext umbracoContext) - { - Media = media; - UmbracoContext = umbracoContext; - } - - public IUmbracoContext UmbracoContext { get; } - - public MediaItemDisplay Media { get; } -} diff --git a/src/Umbraco.Core/Notifications/SendingMemberNotification.cs b/src/Umbraco.Core/Notifications/SendingMemberNotification.cs deleted file mode 100644 index e9e03a868f53..000000000000 --- a/src/Umbraco.Core/Notifications/SendingMemberNotification.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Web; - -namespace Umbraco.Cms.Core.Notifications; - -public class SendingMemberNotification : INotification -{ - public SendingMemberNotification(MemberDisplay member, IUmbracoContext umbracoContext) - { - Member = member; - UmbracoContext = umbracoContext; - } - - public IUmbracoContext UmbracoContext { get; } - - public MemberDisplay Member { get; } -} diff --git a/src/Umbraco.Core/Notifications/SendingUserNotification.cs b/src/Umbraco.Core/Notifications/SendingUserNotification.cs deleted file mode 100644 index da46ec749e5b..000000000000 --- a/src/Umbraco.Core/Notifications/SendingUserNotification.cs +++ /dev/null @@ -1,17 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Web; - -namespace Umbraco.Cms.Core.Notifications; - -public class SendingUserNotification : INotification -{ - public SendingUserNotification(UserDisplay user, IUmbracoContext umbracoContext) - { - User = user; - UmbracoContext = umbracoContext; - } - - public IUmbracoContext UmbracoContext { get; } - - public UserDisplay User { get; } -} diff --git a/src/Umbraco.Core/Services/IRichTextStylesheetService.cs b/src/Umbraco.Core/Services/IRichTextStylesheetService.cs deleted file mode 100644 index 239a0b1afb79..000000000000 --- a/src/Umbraco.Core/Services/IRichTextStylesheetService.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Services.OperationStatus; -using Umbraco.Cms.Core.Strings.Css; - -namespace Umbraco.Cms.Core.Services; - -public interface IRichTextStylesheetService -{ - Task InterpolateRichTextRules(RichTextStylesheetData data); - - Task> ExtractRichTextRules(RichTextStylesheetData data); - - Task, StylesheetOperationStatus>> GetRulesByPathAsync(string path); -} diff --git a/src/Umbraco.Core/Trees/ActionUrlMethod.cs b/src/Umbraco.Core/Trees/ActionUrlMethod.cs deleted file mode 100644 index c2be2cea5439..000000000000 --- a/src/Umbraco.Core/Trees/ActionUrlMethod.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace Umbraco.Cms.Core.Trees; - -/// -/// Specifies the action to take for a menu item when a URL is specified -/// -public enum ActionUrlMethod -{ - Dialog, - BlankWindow, -} diff --git a/src/Umbraco.Core/Trees/CoreTreeAttribute.cs b/src/Umbraco.Core/Trees/CoreTreeAttribute.cs deleted file mode 100644 index b1c29ccb632c..000000000000 --- a/src/Umbraco.Core/Trees/CoreTreeAttribute.cs +++ /dev/null @@ -1,12 +0,0 @@ -namespace Umbraco.Cms.Core.Trees; - -/// -/// Indicates that a tree is a core tree and should not be treated as a plugin tree. -/// -/// -/// This ensures that umbraco will look in the umbraco folders for views for this tree. -/// -[AttributeUsage(AttributeTargets.Class)] -public class CoreTreeAttribute : Attribute -{ -} diff --git a/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs b/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs deleted file mode 100644 index bba1bfc2dce8..000000000000 --- a/src/Umbraco.Core/Trees/IMenuItemCollectionFactory.cs +++ /dev/null @@ -1,13 +0,0 @@ -namespace Umbraco.Cms.Core.Trees; - -/// -/// Represents a factory to create . -/// -public interface IMenuItemCollectionFactory -{ - /// - /// Creates an empty . - /// - /// An empty . - MenuItemCollection Create(); -} diff --git a/src/Umbraco.Core/Trees/ISearchableTree.cs b/src/Umbraco.Core/Trees/ISearchableTree.cs deleted file mode 100644 index 1f24d33f663c..000000000000 --- a/src/Umbraco.Core/Trees/ISearchableTree.cs +++ /dev/null @@ -1,24 +0,0 @@ -using Umbraco.Cms.Core.Composing; -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Core.Trees; - -public interface ISearchableTree : IDiscoverable -{ - /// - /// The alias of the tree that the belongs to - /// - string TreeAlias { get; } - - /// - /// Searches for results based on the entity type - /// - /// - /// - /// - /// - /// A starting point for the search, generally a node id, but for members this is a member type alias - /// - /// - Task SearchAsync(string query, int pageSize, long pageIndex, string? searchFrom = null); -} diff --git a/src/Umbraco.Core/Trees/ISearchableTreeWithCulture.cs b/src/Umbraco.Core/Trees/ISearchableTreeWithCulture.cs deleted file mode 100644 index 6ac4ea3be1dc..000000000000 --- a/src/Umbraco.Core/Trees/ISearchableTreeWithCulture.cs +++ /dev/null @@ -1,21 +0,0 @@ -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Core.Trees -{ - [Obsolete("This interface will be merged into ISearchableTree in Umbraco 12")] - public interface ISearchableTreeWithCulture : ISearchableTree - { - /// - /// Searches for results based on the entity type - /// - /// - /// - /// - /// - /// A starting point for the search, generally a node id, but for members this is a member type alias - /// - /// - /// - Task SearchAsync(string query, int pageSize, long pageIndex, string? searchFrom = null, string? culture = null); - } -} diff --git a/src/Umbraco.Core/Trees/ITree.cs b/src/Umbraco.Core/Trees/ITree.cs deleted file mode 100644 index efb3cfab972e..000000000000 --- a/src/Umbraco.Core/Trees/ITree.cs +++ /dev/null @@ -1,43 +0,0 @@ -namespace Umbraco.Cms.Core.Trees; - -// TODO: we don't really use this, it is nice to have the treecontroller, attribute and ApplicationTree streamlined to implement this but it's not used -// leave as internal for now, maybe we'll use in the future, means we could pass around ITree -// TODO: We should make this a thing, a tree should just be an interface *not* a controller -public interface ITree -{ - /// - /// Gets or sets the sort order. - /// - /// The sort order. - int SortOrder { get; } - - /// - /// Gets the section alias. - /// - string SectionAlias { get; } - - /// - /// Gets the tree group. - /// - string? TreeGroup { get; } - - /// - /// Gets the tree alias. - /// - string TreeAlias { get; } - - /// - /// Gets or sets the tree title (fallback if the tree alias isn't localized) - /// - string? TreeTitle { get; } - - /// - /// Gets the tree use. - /// - TreeUse TreeUse { get; } - - /// - /// Flag to define if this tree is a single node tree (will never contain child nodes, full screen app) - /// - bool IsSingleNodeTree { get; } -} diff --git a/src/Umbraco.Core/Trees/MenuItemCollection.cs b/src/Umbraco.Core/Trees/MenuItemCollection.cs deleted file mode 100644 index aaace2cbd32b..000000000000 --- a/src/Umbraco.Core/Trees/MenuItemCollection.cs +++ /dev/null @@ -1,33 +0,0 @@ -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Models.Trees; - -namespace Umbraco.Cms.Core.Trees; - -/// -/// A menu item collection for a given tree node -/// -[DataContract(Name = "menuItems", Namespace = "")] -public class MenuItemCollection -{ - public MenuItemCollection(ActionCollection actionCollection) => Items = new MenuItemList(actionCollection); - - public MenuItemCollection(ActionCollection actionCollection, IEnumerable items) => - Items = new MenuItemList(actionCollection, items); - - /// - /// Sets the default menu item alias to be shown when the menu is launched - this is optional and if not set then the - /// menu will just be shown normally. - /// - [DataMember(Name = "defaultAlias")] - public string? DefaultMenuAlias { get; set; } - - /// - /// The list of menu items - /// - /// - /// We require this so the json serialization works correctly - /// - [DataMember(Name = "menuItems")] - public MenuItemList Items { get; } -} diff --git a/src/Umbraco.Core/Trees/MenuItemCollectionFactory.cs b/src/Umbraco.Core/Trees/MenuItemCollectionFactory.cs deleted file mode 100644 index da24b0d933f7..000000000000 --- a/src/Umbraco.Core/Trees/MenuItemCollectionFactory.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Umbraco.Cms.Core.Actions; - -namespace Umbraco.Cms.Core.Trees; - -public class MenuItemCollectionFactory : IMenuItemCollectionFactory -{ - private readonly ActionCollection _actionCollection; - - public MenuItemCollectionFactory(ActionCollection actionCollection) => _actionCollection = actionCollection; - - public MenuItemCollection Create() => new MenuItemCollection(_actionCollection); -} diff --git a/src/Umbraco.Core/Trees/MenuItemList.cs b/src/Umbraco.Core/Trees/MenuItemList.cs deleted file mode 100644 index cb912a112be8..000000000000 --- a/src/Umbraco.Core/Trees/MenuItemList.cs +++ /dev/null @@ -1,80 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core.Actions; -using Umbraco.Cms.Core.Models.Trees; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Trees; - -/// -/// A custom menu list -/// -/// -/// NOTE: We need a sub collection to the MenuItemCollection object due to how json serialization works. -/// -public class MenuItemList : List -{ - private readonly ActionCollection _actionCollection; - - public MenuItemList(ActionCollection actionCollection) => _actionCollection = actionCollection; - - public MenuItemList(ActionCollection actionCollection, IEnumerable items) - : base(items) => - _actionCollection = actionCollection; - - /// - /// Adds a menu item with a dictionary which is merged to the AdditionalData bag - /// - /// - /// - /// The used to localize the action name based on its alias - /// Whether or not this action opens a dialog - public MenuItem? Add(ILocalizedTextService textService, bool hasSeparator = false, bool opensDialog = false) - where T : IAction => Add(textService, hasSeparator, opensDialog, useLegacyIcon: true); - - /// - /// Adds a menu item with a dictionary which is merged to the AdditionalData bag - /// - /// - /// - /// The used to localize the action name based on its alias - /// Whether or not this action opens a dialog - /// Whether or not this action should use legacy icon prefixed with "icon-" or full icon name is specified. - public MenuItem? Add(ILocalizedTextService textService, bool hasSeparator = false, bool opensDialog = false, bool useLegacyIcon = true) - where T : IAction - { - MenuItem? item = CreateMenuItem(textService, hasSeparator, opensDialog, useLegacyIcon); - if (item != null) - { - Add(item); - return item; - } - - return null; - } - - private MenuItem? CreateMenuItem(ILocalizedTextService textService, bool hasSeparator = false, bool opensDialog = false, bool useLegacyIcon = true) - where T : IAction - { - T? item = _actionCollection.GetAction(); - if (item == null) - { - return null; - } - - IDictionary values = textService.GetAllStoredValues(Thread.CurrentThread.CurrentUICulture); - values.TryGetValue($"visuallyHiddenTexts/{item.Alias}Description", out var textDescription); - - var menuItem = new MenuItem(item, textService.Localize("actions", item.Alias)) - { - SeparatorBefore = hasSeparator, - OpensDialog = opensDialog, - TextDescription = textDescription, - UseLegacyIcon = useLegacyIcon, - }; - - return menuItem; - } -} diff --git a/src/Umbraco.Core/Trees/SearchableApplicationTree.cs b/src/Umbraco.Core/Trees/SearchableApplicationTree.cs deleted file mode 100644 index 44b0a896acf1..000000000000 --- a/src/Umbraco.Core/Trees/SearchableApplicationTree.cs +++ /dev/null @@ -1,26 +0,0 @@ -namespace Umbraco.Cms.Core.Trees; - -public class SearchableApplicationTree -{ - public SearchableApplicationTree(string appAlias, string treeAlias, int sortOrder, string formatterService, string formatterMethod, ISearchableTree searchableTree) - { - AppAlias = appAlias; - TreeAlias = treeAlias; - SortOrder = sortOrder; - FormatterService = formatterService; - FormatterMethod = formatterMethod; - SearchableTree = searchableTree; - } - - public string AppAlias { get; } - - public string TreeAlias { get; } - - public int SortOrder { get; } - - public string FormatterService { get; } - - public string FormatterMethod { get; } - - public ISearchableTree SearchableTree { get; } -} diff --git a/src/Umbraco.Core/Trees/Tree.cs b/src/Umbraco.Core/Trees/Tree.cs deleted file mode 100644 index 47ee0b234b6a..000000000000 --- a/src/Umbraco.Core/Trees/Tree.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Diagnostics; -using Umbraco.Cms.Core.Services; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Trees; - -[DebuggerDisplay("Tree - {SectionAlias}/{TreeAlias}")] -public class Tree : ITree -{ - public Tree(int sortOrder, string applicationAlias, string? group, string alias, string? title, TreeUse use, Type treeControllerType, bool isSingleNodeTree) - { - SortOrder = sortOrder; - SectionAlias = applicationAlias ?? throw new ArgumentNullException(nameof(applicationAlias)); - TreeGroup = group; - TreeAlias = alias ?? throw new ArgumentNullException(nameof(alias)); - TreeTitle = title; - TreeUse = use; - TreeControllerType = treeControllerType ?? throw new ArgumentNullException(nameof(treeControllerType)); - IsSingleNodeTree = isSingleNodeTree; - } - - /// - /// Gets the tree controller type. - /// - public Type TreeControllerType { get; } - - /// - public int SortOrder { get; set; } - - /// - public string SectionAlias { get; set; } - - /// - public string? TreeGroup { get; } - - /// - public string TreeAlias { get; } - - /// - public string? TreeTitle { get; set; } - - /// - public TreeUse TreeUse { get; set; } - - /// - public bool IsSingleNodeTree { get; } - - public static string? GetRootNodeDisplayName(ITree tree, ILocalizedTextService textService) - { - var label = $"[{tree.TreeAlias}]"; - - // try to look up a the localized tree header matching the tree alias - var localizedLabel = textService.Localize("treeHeader", tree.TreeAlias); - - // if the localizedLabel returns [alias] then return the title if it's defined - if (localizedLabel != null && localizedLabel.Equals(label, StringComparison.InvariantCultureIgnoreCase)) - { - if (string.IsNullOrEmpty(tree.TreeTitle) == false) - { - label = tree.TreeTitle; - } - } - else - { - // the localizedLabel translated into something that's not just [alias], so use the translation - label = localizedLabel; - } - - return label; - } -} diff --git a/src/Umbraco.Core/Trees/TreeCollection.cs b/src/Umbraco.Core/Trees/TreeCollection.cs deleted file mode 100644 index fa6283753ad6..000000000000 --- a/src/Umbraco.Core/Trees/TreeCollection.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Umbraco.Cms.Core.Composing; - -namespace Umbraco.Cms.Core.Trees; - -/// -/// Represents the collection of section trees. -/// -public class TreeCollection : BuilderCollectionBase -{ - public TreeCollection(Func> items) - : base(items) - { - } -} diff --git a/src/Umbraco.Core/Trees/TreeNode.cs b/src/Umbraco.Core/Trees/TreeNode.cs deleted file mode 100644 index dde66bd3a3c5..000000000000 --- a/src/Umbraco.Core/Trees/TreeNode.cs +++ /dev/null @@ -1,130 +0,0 @@ -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Trees; - -/// -/// Represents a model in the tree -/// -/// -/// TreeNode is sealed to prevent developers from adding additional json data to the response -/// -[DataContract(Name = "node", Namespace = "")] -public class TreeNode : EntityBasic -{ - /// - /// Internal constructor, to create a tree node use the CreateTreeNode methods of the TreeApiController. - /// - /// - /// The parent id for the current node - /// - /// - public TreeNode(string nodeId, string? parentId, string? getChildNodesUrl, string? menuUrl) - { - if (nodeId == null) - { - throw new ArgumentNullException(nameof(nodeId)); - } - - if (string.IsNullOrWhiteSpace(nodeId)) - { - throw new ArgumentException( - "Value can't be empty or consist only of white-space characters.", - nameof(nodeId)); - } - - Id = nodeId; - ParentId = parentId; - ChildNodesUrl = getChildNodesUrl; - MenuUrl = menuUrl; - CssClasses = new List(); - - // default - Icon = "icon-folder-close"; - Path = "-1"; - } - - [DataMember(Name = "parentId", IsRequired = true)] - public new object? ParentId { get; set; } - - /// - /// A flag to set whether or not this node has children - /// - [DataMember(Name = "hasChildren")] - public bool HasChildren { get; set; } - - /// - /// The tree nodetype which refers to the type of node rendered in the tree - /// - [DataMember(Name = "nodeType")] - public string? NodeType { get; set; } - - /// - /// Optional: The Route path for the editor for this node - /// - /// - /// If this is not set, then the route path will be automatically determined by: {section}/edit/{id} - /// - [DataMember(Name = "routePath")] - public string? RoutePath { get; set; } - - /// - /// The JSON URL to load the nodes children - /// - [DataMember(Name = "childNodesUrl")] - public string? ChildNodesUrl { get; set; } - - /// - /// The JSON URL to load the menu from - /// - [DataMember(Name = "menuUrl")] - public string? MenuUrl { get; set; } - - /// - /// Returns true if the icon represents a CSS class instead of a file path - /// - [DataMember(Name = "iconIsClass")] - public bool IconIsClass - { - get - { - if (Icon.IsNullOrWhiteSpace()) - { - return true; - } - - if (Icon!.StartsWith("..")) - { - return false; - } - - // if it starts with a '.' or doesn't contain a '.' at all then it is a class - return Icon.StartsWith(".") || Icon.Contains(".") == false; - } - } - - /// - /// Returns the icon file path if the icon is not a class, otherwise returns an empty string - /// - [DataMember(Name = "iconFilePath")] - public string IconFilePath => string.Empty; - - // TODO Figure out how to do this, without the model has to know a bout services and config. - // - // if (IconIsClass) - // return string.Empty; - // - // //absolute path with or without tilde - // if (Icon.StartsWith("~") || Icon.StartsWith("/")) - // return IOHelper.ResolveUrl("~" + Icon.TrimStart(Constants.CharArrays.Tilde)); - // - // //legacy icon path - // return string.Format("{0}images/umbraco/{1}", Current.Configs.Global().Path.EnsureEndsWith("/"), Icon); - - /// - /// A list of additional/custom css classes to assign to the node - /// - [DataMember(Name = "cssClasses")] - public IList CssClasses { get; private set; } -} diff --git a/src/Umbraco.Core/Trees/TreeNodeCollection.cs b/src/Umbraco.Core/Trees/TreeNodeCollection.cs deleted file mode 100644 index b76fcc41ce8e..000000000000 --- a/src/Umbraco.Core/Trees/TreeNodeCollection.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Core.Trees; - -[CollectionDataContract(Name = "nodes", Namespace = "")] -public sealed class TreeNodeCollection : List -{ - public TreeNodeCollection() - { - } - - public TreeNodeCollection(IEnumerable nodes) - : base(nodes) - { - } - - public static TreeNodeCollection Empty => new(); -} diff --git a/src/Umbraco.Core/Trees/TreeNodeExtensions.cs b/src/Umbraco.Core/Trees/TreeNodeExtensions.cs deleted file mode 100644 index 7fdc8ef480ed..000000000000 --- a/src/Umbraco.Core/Trees/TreeNodeExtensions.cs +++ /dev/null @@ -1,79 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core.Trees; - -namespace Umbraco.Extensions; - -public static class TreeNodeExtensions -{ - internal const string LegacyJsCallbackKey = "jsClickCallback"; - - /// - /// Sets the node style to show that it is a container type - /// - /// - public static void SetContainerStyle(this TreeNode treeNode) - { - if (treeNode.CssClasses.Contains("is-container") == false) - { - treeNode.CssClasses.Add("is-container"); - } - } - - /// - /// Legacy tree node's assign a JS method callback for when an item is clicked, this method facilitates that. - /// - /// - /// - internal static void AssignLegacyJsCallback(this TreeNode treeNode, string jsCallback) => - treeNode.AdditionalData[LegacyJsCallbackKey] = jsCallback; - - /// - /// Sets the node style to show that it is currently protected publicly - /// - /// - public static void SetProtectedStyle(this TreeNode treeNode) - { - if (treeNode.CssClasses.Contains("protected") == false) - { - treeNode.CssClasses.Add("protected"); - } - } - - /// - /// Sets the node style to show that it is currently locked / non-deletable - /// - /// - public static void SetLockedStyle(this TreeNode treeNode) - { - if (treeNode.CssClasses.Contains("locked") == false) - { - treeNode.CssClasses.Add("locked"); - } - } - - /// - /// Sets the node style to show that it is has unpublished versions (but is currently published) - /// - /// - public static void SetHasPendingVersionStyle(this TreeNode treeNode) - { - if (treeNode.CssClasses.Contains("has-unpublished-version") == false) - { - treeNode.CssClasses.Add("has-unpublished-version"); - } - } - - /// - /// Sets the node style to show that it is not published - /// - /// - public static void SetNotPublishedStyle(this TreeNode treeNode) - { - if (treeNode.CssClasses.Contains("not-published") == false) - { - treeNode.CssClasses.Add("not-published"); - } - } -} diff --git a/src/Umbraco.Core/Trees/TreeUse.cs b/src/Umbraco.Core/Trees/TreeUse.cs deleted file mode 100644 index ff06bc1dead6..000000000000 --- a/src/Umbraco.Core/Trees/TreeUse.cs +++ /dev/null @@ -1,23 +0,0 @@ -namespace Umbraco.Cms.Core.Trees; - -/// -/// Defines tree uses. -/// -[Flags] -public enum TreeUse -{ - /// - /// The tree is not used. - /// - None = 0, - - /// - /// The tree is used as a main (section) tree. - /// - Main = 1, - - /// - /// The tree is used as a dialog. - /// - Dialog = 2, -} diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs index 2bebd75c9c27..58d3c5493d76 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.CoreServices.cs @@ -2,7 +2,6 @@ using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; -using Serilog; using Umbraco.Cms.Core; using Umbraco.Cms.Core.Cache; using Umbraco.Cms.Core.Configuration; @@ -16,9 +15,7 @@ using Umbraco.Cms.Core.HealthChecks.NotificationMethods; using Umbraco.Cms.Core.Hosting; using Umbraco.Cms.Core.Install; -using Umbraco.Cms.Core.Logging; using Umbraco.Cms.Core.Logging.Serilog.Enrichers; -using Umbraco.Cms.Core.Logging.Viewer; using Umbraco.Cms.Core.Mail; using Umbraco.Cms.Core.Manifest; using Umbraco.Cms.Core.Media; @@ -38,9 +35,7 @@ using Umbraco.Cms.Core.Services; using Umbraco.Cms.Core.Strings; using Umbraco.Cms.Core.Templates; -using Umbraco.Cms.Core.Trees; using Umbraco.Cms.Core.Web; -using Umbraco.Cms.Core.Webhooks; using Umbraco.Cms.Infrastructure.Configuration; using Umbraco.Cms.Infrastructure.DeliveryApi; using Umbraco.Cms.Infrastructure.DistributedLocking; @@ -126,7 +121,6 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde builder.Services.AddSingleton(); builder.Services.AddSingleton(); - builder.Services.AddSingleton(); // register database builder // *not* a singleton, don't want to keep it around @@ -178,8 +172,6 @@ public static IUmbracoBuilder AddCoreInitialServices(this IUmbracoBuilder builde builder.Services.AddSingleton(); - builder.Services.AddScoped(); - // replace builder.Services.AddSingleton( services => new EmailSender( diff --git a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs index 204b92916616..4344432bd2c9 100644 --- a/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs +++ b/src/Umbraco.Infrastructure/DependencyInjection/UmbracoBuilder.MappingProfiles.cs @@ -18,26 +18,11 @@ public static IUmbracoBuilder AddCoreMappingProfiles(this IUmbracoBuilder builde builder.Services.AddUnique(); builder.WithCollectionBuilder() - .Add() - .Add() - .Add() - .Add() - .Add() - .Add() .Add() - .Add() - .Add() - .Add() .Add() - .Add() - .Add() - .Add() - .Add() - .Add() .Add(); builder.Services.AddTransient(); - builder.Services.AddTransient(); return builder; } diff --git a/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs b/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs deleted file mode 100644 index 16ce1ad34050..000000000000 --- a/src/Umbraco.Infrastructure/Models/Mapping/EntityMapDefinition.cs +++ /dev/null @@ -1,331 +0,0 @@ -using System.Globalization; -using Examine; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.Entities; -using Umbraco.Cms.Core.Models.Membership; -using Umbraco.Cms.Infrastructure.Examine; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Core.Models.Mapping; - -public class EntityMapDefinition : IMapDefinition -{ - public void DefineMaps(IUmbracoMapper mapper) - { - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new ContentTypeSort(), Map); - mapper.Define((source, context) => new EntityBasic(), Map); - mapper.Define((source, context) => new SearchResultEntity(), Map); - mapper.Define((source, context) => new SearchResultEntity(), Map); - mapper.Define>((source, context) => - context.MapEnumerable(source).WhereNotNull()); - mapper.Define, IEnumerable>((source, context) => - context.MapEnumerable(source).WhereNotNull()); - } - - // Umbraco.Code.MapAll -Alias - private static void Map(IEntitySlim source, EntityBasic target, MapperContext context) - { - target.Icon = MapContentTypeIcon(source); - target.Id = source.Id; - target.Key = source.Key; - target.Name = MapName(source, context); - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Trashed = source.Trashed; - target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); - - if (source is IContentEntitySlim contentSlim) - { - source.AdditionalData!["ContentTypeAlias"] = contentSlim.ContentTypeAlias; - } - - if (source is IDocumentEntitySlim documentSlim) - { - source.AdditionalData!["IsPublished"] = documentSlim.Published; - } - - if (source is IMediaEntitySlim mediaSlim) - { - if (source.AdditionalData is not null) - { - // pass UpdateDate for MediaPicker ListView ordering - source.AdditionalData["UpdateDate"] = mediaSlim.UpdateDate; - source.AdditionalData["MediaPath"] = mediaSlim.MediaPath; - } - } - - if (source.AdditionalData is not null) - { - // NOTE: we're mapping the objects in AdditionalData by object reference here. - // it works fine for now, but it's something to keep in mind in the future - foreach (KeyValuePair kvp in source.AdditionalData) - { - if (kvp.Value is not null) - { - target.AdditionalData[kvp.Key] = kvp.Value; - } - } - } - - target.AdditionalData.Add("IsContainer", source.IsContainer); - } - - // Umbraco.Code.MapAll -Udi -Trashed - private static void Map(IPropertyType source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = "icon-box"; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = string.Empty; - } - - // Umbraco.Code.MapAll -Udi -Trashed - private static void Map(PropertyGroup source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = "icon-tab"; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = string.Empty; - } - - // Umbraco.Code.MapAll -Udi -Trashed - private static void Map(IUser source, EntityBasic target, MapperContext context) - { - target.Alias = source.Key.ToString(); - target.Icon = Constants.Icons.User; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = string.Empty; - } - - // Umbraco.Code.MapAll -Trashed - private static void Map(ITemplate source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = Constants.Icons.Template; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = -1; - target.Path = source.Path; - target.Udi = Udi.Create(Constants.UdiEntityType.Template, source.Key); - } - - // Umbraco.Code.MapAll -SortOrder - private static void Map(EntityBasic source, ContentTypeSort target, MapperContext context) - { - target.Alias = source.Alias; - target.Key = source.Key; - } - - // Umbraco.Code.MapAll -Trashed - private static void Map(IContentTypeComposition source, EntityBasic target, MapperContext context) - { - target.Alias = source.Alias; - target.Icon = source.Icon; - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Udi = ContentTypeMapDefinition.MapContentTypeUdi(source); - } - - // Umbraco.Code.MapAll -Trashed -Alias -Score - private static void Map(EntitySlim source, SearchResultEntity target, MapperContext context) - { - target.Icon = MapContentTypeIcon(source); - target.Id = source.Id; - target.Key = source.Key; - target.Name = source.Name; - target.ParentId = source.ParentId; - target.Path = source.Path; - target.Udi = Udi.Create(ObjectTypes.GetUdiType(source.NodeObjectType), source.Key); - - if (target.Icon.IsNullOrWhiteSpace()) - { - if (source.NodeObjectType == Constants.ObjectTypes.Document) - { - target.Icon = Constants.Icons.Content; - } - - if (source.NodeObjectType == Constants.ObjectTypes.Media) - { - target.Icon = Constants.Icons.Content; - } - - if (source.NodeObjectType == Constants.ObjectTypes.Member) - { - target.Icon = Constants.Icons.Member; - } - else if (source.NodeObjectType == Constants.ObjectTypes.DataType) - { - target.Icon = Constants.Icons.DataType; - } - else if (source.NodeObjectType == Constants.ObjectTypes.DocumentType) - { - target.Icon = Constants.Icons.ContentType; - } - else if (source.NodeObjectType == Constants.ObjectTypes.MediaType) - { - target.Icon = Constants.Icons.MediaType; - } - else if (source.NodeObjectType == Constants.ObjectTypes.MemberType) - { - target.Icon = Constants.Icons.MemberType; - } - else if (source.NodeObjectType == Constants.ObjectTypes.TemplateType) - { - target.Icon = Constants.Icons.Template; - } - } - } - - // Umbraco.Code.MapAll -Alias -Trashed - private static void Map(ISearchResult source, SearchResultEntity target, MapperContext context) - { - target.Id = source.Id; - target.Score = source.Score; - - // TODO: Properly map this (not aftermap) - - // get the icon if there is one - target.Icon = source.Values.ContainsKey(UmbracoExamineFieldNames.IconFieldName) - ? source.Values[UmbracoExamineFieldNames.IconFieldName] - : Constants.Icons.DefaultIcon; - - target.Name = source.Values.ContainsKey(UmbracoExamineFieldNames.NodeNameFieldName) - ? source.Values[UmbracoExamineFieldNames.NodeNameFieldName] - : "[no name]"; - - var culture = context.GetCulture()?.ToLowerInvariant(); - if (culture.IsNullOrWhiteSpace() == false) - { - target.Name = source.Values.ContainsKey($"nodeName_{culture}") - ? source.Values[$"nodeName_{culture}"] - : target.Name; - } - - if (source.Values.TryGetValue(UmbracoExamineFieldNames.UmbracoFileFieldName, out var umbracoFile) && - umbracoFile.IsNullOrWhiteSpace() == false) - { - if (umbracoFile != null) - { - target.Name = $"{target.Name} ({umbracoFile})"; - } - } - - if (source.Values.ContainsKey(UmbracoExamineFieldNames.NodeKeyFieldName)) - { - if (Guid.TryParse(source.Values[UmbracoExamineFieldNames.NodeKeyFieldName], out Guid key)) - { - target.Key = key; - - // need to set the UDI - if (source.Values.ContainsKey(ExamineFieldNames.CategoryFieldName)) - { - switch (source.Values[ExamineFieldNames.CategoryFieldName]) - { - case IndexTypes.Member: - target.Udi = new GuidUdi(Constants.UdiEntityType.Member, target.Key); - break; - case IndexTypes.Content: - target.Udi = new GuidUdi(Constants.UdiEntityType.Document, target.Key); - break; - case IndexTypes.Media: - target.Udi = new GuidUdi(Constants.UdiEntityType.Media, target.Key); - break; - } - } - } - } - - if (source.Values.ContainsKey("parentID")) - { - if (int.TryParse(source.Values["parentID"], NumberStyles.Integer, CultureInfo.InvariantCulture, - out var parentId)) - { - target.ParentId = parentId; - } - else - { - target.ParentId = -1; - } - } - - target.Path = source.Values.ContainsKey(UmbracoExamineFieldNames.IndexPathFieldName) - ? source.Values[UmbracoExamineFieldNames.IndexPathFieldName] - : string.Empty; - - if (source.Values.ContainsKey(ExamineFieldNames.ItemTypeFieldName)) - { - target.AdditionalData.Add("contentType", source.Values[ExamineFieldNames.ItemTypeFieldName]); - } - - if (source.Values.ContainsKey(UmbracoExamineFieldNames.PublishedFieldName)) - { - target.AdditionalData.Add("published", string.Equals(source.Values[UmbracoExamineFieldNames.PublishedFieldName], "y", StringComparison.InvariantCultureIgnoreCase)); - } - } - - private static string? MapContentTypeIcon(IEntitySlim entity) - { - switch (entity) - { - case IMemberEntitySlim memberEntity: - return memberEntity.ContentTypeIcon; - case IContentEntitySlim contentEntity: - // NOTE: this case covers both content and media entities - return contentEntity.ContentTypeIcon; - } - - return null; - } - - private static string MapName(IEntitySlim source, MapperContext context) - { - if (!(source is DocumentEntitySlim doc)) - { - return source.Name!; - } - - // invariant = only 1 name - if (!doc.Variations.VariesByCulture()) - { - return source.Name!; - } - - // variant = depends on culture - var culture = context.GetCulture(); - - // if there's no culture here, the issue is somewhere else (UI, whatever) - throw! - if (culture == null) - - // throw new InvalidOperationException("Missing culture in mapping options."); - // TODO: we should throw, but this is used in various places that won't set a culture yet - { - return source.Name!; - } - - // if we don't have a name for a culture, it means the culture is not available, and - // hey we should probably not be mapping it, but it's too late, return a fallback name - return doc.CultureNames.TryGetValue(culture, out var name) && !name.IsNullOrWhiteSpace() - ? name - : $"({source.Name})"; - } -} diff --git a/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs b/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs deleted file mode 100644 index 26f1195e1a3f..000000000000 --- a/src/Umbraco.Infrastructure/Search/UmbracoTreeSearcher.cs +++ /dev/null @@ -1,204 +0,0 @@ -using System.Globalization; -using Examine; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.Entities; -using Umbraco.Cms.Core.Routing; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Trees; -using Umbraco.Cms.Infrastructure.Examine; -using Umbraco.Cms.Infrastructure.Persistence; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Infrastructure.Search; - -/// -/// Used for internal Umbraco implementations of -/// -public class UmbracoTreeSearcher -{ - private readonly IBackOfficeExamineSearcher _backOfficeExamineSearcher; - private readonly IEntityService _entityService; - private readonly ILocalizationService _languageService; - private readonly IUmbracoMapper _mapper; - private readonly IPublishedUrlProvider _publishedUrlProvider; - private readonly ISqlContext _sqlContext; - - public UmbracoTreeSearcher( - ILocalizationService languageService, - IEntityService entityService, - IUmbracoMapper mapper, - ISqlContext sqlContext, - IBackOfficeExamineSearcher backOfficeExamineSearcher, - IPublishedUrlProvider publishedUrlProvider) - { - _languageService = languageService; - _entityService = entityService; - _mapper = mapper; - _sqlContext = sqlContext; - _backOfficeExamineSearcher = backOfficeExamineSearcher; - _publishedUrlProvider = publishedUrlProvider; - } - - /// - /// Searches Examine for results based on the entity type - /// - /// - /// - /// - /// - /// - /// A starting point for the search, generally a node id, but for members this is a member type alias - /// - /// - /// - /// If set to true, user and group start node permissions will be ignored. - /// - public IEnumerable ExamineSearch( - string query, - UmbracoEntityTypes entityType, - int pageSize, - long pageIndex, - out long totalFound, - string? culture = null, - string? searchFrom = null, - bool ignoreUserStartNodes = false) - { - IEnumerable pagedResult = _backOfficeExamineSearcher.Search(query, entityType, pageSize, pageIndex, out totalFound, searchFrom, ignoreUserStartNodes); - - switch (entityType) - { - case UmbracoEntityTypes.Member: - return MemberFromSearchResults(pagedResult.ToArray()); - case UmbracoEntityTypes.Media: - return MediaFromSearchResults(pagedResult); - case UmbracoEntityTypes.Document: - return ContentFromSearchResults(pagedResult, culture); - default: - throw new NotSupportedException("The " + typeof(UmbracoTreeSearcher) + - " currently does not support searching against object type " + - entityType); - } - } - - /// - /// Searches with the for results based on the entity type - /// - /// - /// - /// - /// - /// - /// - /// - public IEnumerable EntitySearch(UmbracoObjectTypes objectType, string query, int pageSize, long pageIndex, out long totalFound, string? searchFrom = null) - { - // if it's a GUID, match it - Guid.TryParse(query, out Guid g); - - IEnumerable results = _entityService.GetPagedDescendants( - objectType, - pageIndex, - pageSize, - out totalFound, - _sqlContext.Query() - .Where(x => x.Name!.Contains(query) || x.Key == g)); - return _mapper.MapEnumerable(results); - } - - /// - /// Returns a collection of entities for media based on search results - /// - /// - /// - private IEnumerable MemberFromSearchResults(IEnumerable results) - { - // add additional data - foreach (ISearchResult result in results) - { - SearchResultEntity? m = _mapper.Map(result); - - if (m is null) - { - continue; - } - - // if no icon could be mapped, it will be set to document, so change it to picture - if (m.Icon == Constants.Icons.DefaultIcon) - { - m.Icon = Constants.Icons.Member; - } - - if (result.Values.ContainsKey("email") && result.Values["email"] != null) - { - m.AdditionalData["Email"] = result.Values["email"]; - } - - if (result.Values.ContainsKey(UmbracoExamineFieldNames.NodeKeyFieldName) && - result.Values[UmbracoExamineFieldNames.NodeKeyFieldName] != null) - { - if (Guid.TryParse(result.Values[UmbracoExamineFieldNames.NodeKeyFieldName], out Guid key)) - { - m.Key = key; - } - } - - yield return m; - } - } - - /// - /// Returns a collection of entities for media based on search results - /// - /// - /// - private IEnumerable MediaFromSearchResults(IEnumerable results) - => _mapper.Map>(results) ?? Enumerable.Empty(); - - /// - /// Returns a collection of entities for content based on search results - /// - /// - /// - /// - private IEnumerable ContentFromSearchResults( - IEnumerable results, - string? culture = null) - { - var defaultLang = _languageService.GetDefaultLanguageIsoCode(); - - foreach (ISearchResult result in results) - { - SearchResultEntity? entity = _mapper.Map(result, context => - { - if (culture != null) - { - context.SetCulture(culture); - } - }); - - if (entity is null) - { - continue; - } - - if (int.TryParse(entity.Id?.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture, out var intId)) - { - // if it varies by culture, return the default language URL - if (result.Values.TryGetValue(UmbracoExamineFieldNames.VariesByCultureFieldName, out var varies) && - varies == "y") - { - entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId, culture: culture ?? defaultLang); - } - else - { - entity.AdditionalData["Url"] = _publishedUrlProvider.GetUrl(intId); - } - } - - yield return entity; - } - } -} diff --git a/src/Umbraco.Infrastructure/Trees/TreeRootNode.cs b/src/Umbraco.Infrastructure/Trees/TreeRootNode.cs deleted file mode 100644 index d0fa516b92dc..000000000000 --- a/src/Umbraco.Infrastructure/Trees/TreeRootNode.cs +++ /dev/null @@ -1,153 +0,0 @@ -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Trees; - -namespace Umbraco.Cms.Core.Models.Trees; - -/// -/// A tree node that represents various types of root nodes -/// -/// -/// -/// A represents: -/// * The root node for a section containing a single tree -/// * The root node for a section containing multiple sub-trees -/// * The root node for a section containing groups of multiple sub-trees -/// * The group node in a section containing groups of multiple sub-trees -/// -/// -/// This is required to return the tree data for a given section. Some sections may only contain one tree which -/// means it's section -/// root should also display a menu, whereas other sections have multiple trees and the section root shouldn't -/// display a menu. -/// -/// -/// The root node also contains an explicit collection of children. -/// -/// -[DataContract(Name = "node", Namespace = "")] -public sealed class TreeRootNode : TreeNode -{ - private static readonly string RootId = Constants.System.RootString; - private bool _isGroup; - private bool _isSingleNodeTree; - - /// - /// Private constructor - /// - /// - /// - /// - private TreeRootNode(string nodeId, string? getChildNodesUrl, string? menuUrl) - : base(nodeId, null, getChildNodesUrl, menuUrl) => - - // default to false - IsContainer = false; - - /// - /// Will be true if this is a multi-tree section root node (i.e. contains other trees) - /// - [DataMember(Name = "isContainer")] - public bool IsContainer { get; private set; } - - /// - /// True if this is a group root node - /// - [DataMember(Name = "isGroup")] - public bool IsGroup - { - get => _isGroup; - private set - { - // if a group is true then it is also a container - _isGroup = value; - IsContainer = true; - } - } - - /// - /// True if this root node contains group root nodes - /// - [DataMember(Name = "containsGroups")] - public bool ContainsGroups { get; private set; } - - /// - /// The node's children collection - /// - [DataMember(Name = "children")] - public TreeNodeCollection? Children { get; private set; } - - /// - /// Returns true if there are any children - /// - /// - /// This is used in the UI to configure a full screen section/app - /// - [DataMember(Name = "containsTrees")] - public bool ContainsTrees => Children?.Count > 0 || !_isSingleNodeTree; - - /// - /// Creates a group node for grouped multiple trees - /// - public static TreeRootNode CreateGroupNode(TreeNodeCollection children, string section) - { - var sectionRoot = new TreeRootNode(RootId, string.Empty, string.Empty) - { - IsGroup = true, - Children = children, - RoutePath = section, - }; - - return sectionRoot; - } - - /// - /// Creates a section root node for grouped multiple trees - /// - /// - /// - public static TreeRootNode CreateGroupedMultiTreeRoot(TreeNodeCollection children) - { - var sectionRoot = new TreeRootNode(RootId, string.Empty, string.Empty) - { - IsContainer = true, - Children = children, - ContainsGroups = true, - }; - - return sectionRoot; - } - - /// - /// Creates a section root node for non-grouped multiple trees - /// - /// - /// - public static TreeRootNode CreateMultiTreeRoot(TreeNodeCollection children) - { - var sectionRoot = new TreeRootNode(RootId, string.Empty, string.Empty) - { - IsContainer = true, - Children = children, - }; - - return sectionRoot; - } - - /// - /// Creates a section root node for a section with a single tree - /// - /// - /// - /// - /// - /// - /// - /// - public static TreeRootNode CreateSingleTreeRoot(string nodeId, string? getChildNodesUrl, string? menuUrl, string? title, TreeNodeCollection? children, bool isSingleNodeTree = false) => - new TreeRootNode(nodeId, getChildNodesUrl, menuUrl) - { - Children = children, - Name = title, - _isSingleNodeTree = isSingleNodeTree, - }; -} diff --git a/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs b/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs index d6996f6355c3..00eda14ab10b 100644 --- a/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs +++ b/src/Umbraco.Web.Common/ActionsResults/ValidationErrorResult.cs @@ -45,18 +45,6 @@ public ValidationErrorResult(string errorMessage) { } - /// - /// Typically this should not be used and just use the ValidationProblem method on the base controller class. - /// - /// - /// - public static ValidationErrorResult CreateNotificationValidationErrorResult(string errorMessage) - { - var notificationModel = new SimpleNotificationModel { Message = errorMessage }; - notificationModel.AddErrorNotification(errorMessage, string.Empty); - return new ValidationErrorResult(notificationModel); - } - public override void OnFormatting(ActionContext context) { base.OnFormatting(context); diff --git a/src/Umbraco.Web.Common/Models/DisabledUsersModel.cs b/src/Umbraco.Web.Common/Models/DisabledUsersModel.cs deleted file mode 100644 index f6712ab19327..000000000000 --- a/src/Umbraco.Web.Common/Models/DisabledUsersModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System.Runtime.Serialization; -using Umbraco.Cms.Core.Models.ContentEditing; - -namespace Umbraco.Cms.Web.Common.Models; - -[DataContract] -public class DisabledUsersModel : INotificationModel -{ - public List Notifications { get; } = new(); - - [DataMember(Name = "disabledUserIds")] - public IEnumerable DisabledUserIds { get; set; } = Enumerable.Empty(); -} diff --git a/src/Umbraco.Web.Common/Models/InvitePasswordModel.cs b/src/Umbraco.Web.Common/Models/InvitePasswordModel.cs deleted file mode 100644 index da21cec2ed53..000000000000 --- a/src/Umbraco.Web.Common/Models/InvitePasswordModel.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.ComponentModel.DataAnnotations; - -namespace Umbraco.Cms.Web.Common.Models; - -/// -/// A model used for setting a new password for a user that has been invited to Umbraco. -/// -public class InvitePasswordModel -{ - /// - /// Gets or sets the desired password for the user. - /// - [Required] - [DataType(DataType.Password)] - [Display(Name = "New password")] - [StringLength(256)] - public string NewPassword { get; set; } = null!; -} diff --git a/src/Umbraco.Web.Common/Models/WebhookLogViewModel.cs b/src/Umbraco.Web.Common/Models/WebhookLogViewModel.cs deleted file mode 100644 index 0b3ff552a7ec..000000000000 --- a/src/Umbraco.Web.Common/Models/WebhookLogViewModel.cs +++ /dev/null @@ -1,43 +0,0 @@ -using System.Runtime.Serialization; - -namespace Umbraco.Cms.Web.Common.Models; - -[DataContract] -public class WebhookLogViewModel -{ - [DataMember(Name = "key")] - public Guid Key { get; set; } - - [DataMember(Name = "webhookKey")] - public Guid WebhookKey { get; set; } - - [DataMember(Name = "statusCode")] - public string StatusCode { get; set; } = string.Empty; - - [DataMember(Name = "date")] - public DateTime Date { get; set; } - - [DataMember(Name = "eventAlias")] - public string EventAlias { get; set; } = string.Empty; - - [DataMember(Name = "url")] - public string Url { get; set; } = string.Empty; - - [DataMember(Name = "retryCount")] - public int RetryCount { get; set; } - - [DataMember(Name = "requestHeaders")] - public string RequestHeaders { get; set; } = string.Empty; - - [DataMember(Name = "requestBody")] - public string RequestBody { get; set; } = string.Empty; - - [DataMember(Name = "responseHeaders")] - public string ResponseHeaders { get; set; } = string.Empty; - - [DataMember(Name = "responseBody")] - public string ResponseBody { get; set; } = string.Empty; - - [DataMember(Name = "exceptionOccured")] - public bool ExceptionOccured { get; set; } -} diff --git a/tests/Umbraco.Tests.Common/Builders/ContentItemSaveBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentItemSaveBuilder.cs deleted file mode 100644 index b16898e886b7..000000000000 --- a/tests/Umbraco.Tests.Common/Builders/ContentItemSaveBuilder.cs +++ /dev/null @@ -1,74 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Collections.Generic; -using System.Linq; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Tests.Common.Builders.Interfaces; - -namespace Umbraco.Cms.Tests.Common.Builders; - -public class ContentItemSaveBuilder : BuilderBase, - IWithIdBuilder, - IWithParentIdBuilder -{ - private ContentSaveAction? _action; - private string _contentTypeAlias; - - private int? _id; - private int? _parentId; - private readonly List> _variantBuilders = new(); - - int? IWithIdBuilder.Id - { - get => _id; - set => _id = value; - } - - int? IWithParentIdBuilder.ParentId - { - get => _parentId; - set => _parentId = value; - } - - public ContentVariantSaveBuilder AddVariant() - { - var builder = new ContentVariantSaveBuilder(this); - _variantBuilders.Add(builder); - return builder; - } - - public override ContentItemSave Build() - { - var id = _id ?? 0; - var parentId = _parentId ?? -1; - var contentTypeAlias = _contentTypeAlias; - var action = _action ?? ContentSaveAction.Save; - var variants = _variantBuilders.Select(x => x.Build()); - - return new TestContentItemSave - { - Id = id, - ParentId = parentId, - ContentTypeAlias = contentTypeAlias, - Action = action, - Variants = variants - }; - } - - public ContentItemSaveBuilder WithAction(ContentSaveAction action) - { - _action = action; - return this; - } - - public ContentItemSaveBuilder WithContentTypeAlias(string contentTypeAlias) - { - _contentTypeAlias = contentTypeAlias; - return this; - } -} - -public class TestContentItemSave : ContentItemSave -{ -} diff --git a/tests/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs deleted file mode 100644 index ce234d38f176..000000000000 --- a/tests/Umbraco.Tests.Common/Builders/ContentPropertyBasicBuilder.cs +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Tests.Common.Builders.Interfaces; - -namespace Umbraco.Cms.Tests.Common.Builders; - -public class ContentPropertyBasicBuilder : ChildBuilderBase, - IWithIdBuilder, IWithAliasBuilder -{ - private string _alias; - private int? _id; - private object _value; - - public ContentPropertyBasicBuilder(TParent parentBuilder) - : base(parentBuilder) - { - } - - string IWithAliasBuilder.Alias - { - get => _alias; - set => _alias = value; - } - - int? IWithIdBuilder.Id - { - get => _id; - set => _id = value; - } - - public override ContentPropertyBasic Build() - { - var alias = _alias; - var id = _id ?? 0; - var value = _value; - - return new ContentPropertyBasic { Alias = alias, Id = id, Value = value }; - } - - public ContentPropertyBasicBuilder WithValue(object value) - { - _value = value; - return this; - } -} diff --git a/tests/Umbraco.Tests.Common/Builders/ContentVariantSaveBuilder.cs b/tests/Umbraco.Tests.Common/Builders/ContentVariantSaveBuilder.cs deleted file mode 100644 index 556319b28fb9..000000000000 --- a/tests/Umbraco.Tests.Common/Builders/ContentVariantSaveBuilder.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Collections.Generic; -using System.Globalization; -using System.Linq; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Tests.Common.Builders.Interfaces; - -namespace Umbraco.Cms.Tests.Common.Builders; - -public class ContentVariantSaveBuilder : ChildBuilderBase, - IWithNameBuilder, - IWithCultureInfoBuilder -{ - private readonly List>> _propertyBuilders = new(); - private CultureInfo _cultureInfo; - - private string _name; - private bool? _publish; - private bool? _save; - - public ContentVariantSaveBuilder(TParent parentBuilder) - : base(parentBuilder) - { - } - - CultureInfo IWithCultureInfoBuilder.CultureInfo - { - get => _cultureInfo; - set => _cultureInfo = value; - } - - string IWithNameBuilder.Name - { - get => _name; - set => _name = value; - } - - public ContentVariantSaveBuilder WithSave(bool save) - { - _save = save; - return this; - } - - public ContentVariantSaveBuilder WithPublish(bool publish) - { - _publish = publish; - return this; - } - - public ContentPropertyBasicBuilder> AddProperty() - { - var builder = new ContentPropertyBasicBuilder>(this); - _propertyBuilders.Add(builder); - return builder; - } - - public override ContentVariantSave Build() - { - var name = _name; - var culture = _cultureInfo?.Name; - var save = _save ?? true; - var publish = _publish ?? true; - var properties = _propertyBuilders.Select(x => x.Build()); - - return new ContentVariantSave - { - Name = name, - Culture = culture, - Save = save, - Publish = publish, - Properties = properties - }; - } -} diff --git a/tests/Umbraco.Tests.Common/Builders/Extensions/ContentItemSaveBuilderExtensions.cs b/tests/Umbraco.Tests.Common/Builders/Extensions/ContentItemSaveBuilderExtensions.cs deleted file mode 100644 index 0a44c25cc546..000000000000 --- a/tests/Umbraco.Tests.Common/Builders/Extensions/ContentItemSaveBuilderExtensions.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core.Models; - -namespace Umbraco.Cms.Tests.Common.Builders.Extensions; - -public static class ContentItemSaveBuilderExtensions -{ - public static ContentItemSaveBuilder WithContent(this ContentItemSaveBuilder builder, IContent content) - { - builder.WithId(content.Id); - builder.WithContentTypeAlias(content.ContentType.Alias); - - if (content.CultureInfos.Count == 0) - { - var variantBuilder = builder.AddVariant(); - variantBuilder.WithName(content.Name); - - foreach (var contentProperty in content.Properties) - { - AddInvariantProperty(variantBuilder, contentProperty); - } - } - else - { - foreach (var contentCultureInfos in content.CultureInfos) - { - var variantBuilder = builder.AddVariant(); - - variantBuilder.WithName(contentCultureInfos.Name); - variantBuilder.WithCultureInfo(contentCultureInfos.Culture); - - foreach (var contentProperty in content.Properties) - { - AddInvariantProperty(variantBuilder, contentProperty); - } - } - } - - return builder; - } - - private static void AddInvariantProperty(ContentVariantSaveBuilder variantBuilder, IProperty contentProperty) => - variantBuilder - .AddProperty() - .WithId(contentProperty.Id) - .WithAlias(contentProperty.Alias) - .WithValue(contentProperty.GetValue()) - .Done(); -} diff --git a/tests/Umbraco.Tests.Common/Builders/TreeBuilder.cs b/tests/Umbraco.Tests.Common/Builders/TreeBuilder.cs deleted file mode 100644 index 2d1b687aa252..000000000000 --- a/tests/Umbraco.Tests.Common/Builders/TreeBuilder.cs +++ /dev/null @@ -1,81 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Trees; -using Umbraco.Cms.Tests.Common.Builders.Interfaces; - -namespace Umbraco.Cms.Tests.Common.Builders; - -public class TreeBuilder - : BuilderBase, - IWithAliasBuilder, - IWithSortOrderBuilder -{ - private string _alias; - private string _group; - private bool? _isSingleNode; - private string _sectionAlias; - private int? _sortOrder; - private string _title; - private TreeUse? _treeUse; - - string IWithAliasBuilder.Alias - { - get => _alias; - set => _alias = value; - } - - int? IWithSortOrderBuilder.SortOrder - { - get => _sortOrder; - set => _sortOrder = value; - } - - public TreeBuilder WithSectionAlias(string sectionAlias) - { - _sectionAlias = sectionAlias; - return this; - } - - public TreeBuilder WithGroup(string group) - { - _group = group; - return this; - } - - public TreeBuilder WithTitle(string title) - { - _title = title; - return this; - } - - public TreeBuilder WithTreeUse(TreeUse treeUse) - { - _treeUse = treeUse; - return this; - } - - public TreeBuilder WithTreeUse(bool isSingleNode) - { - _isSingleNode = isSingleNode; - return this; - } - - public override Tree Build() - { - var sortOrder = _sortOrder ?? 1; - var alias = _alias ?? "testTree"; - var sectionAlias = _sectionAlias ?? Constants.Applications.Content; - var group = _group ?? string.Empty; - var title = _title ?? string.Empty; - var treeUse = _treeUse ?? TreeUse.Main; - var isSingleNode = _isSingleNode ?? false; - - return new Tree(sortOrder, sectionAlias, group, alias, title, treeUse, typeof(SampleTreeController), isSingleNode); - } - - private class SampleTreeController - { - } -} diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/ContentTypeModelMappingTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/ContentTypeModelMappingTests.cs deleted file mode 100644 index 1f2adfb96a2f..000000000000 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/ContentTypeModelMappingTests.cs +++ /dev/null @@ -1,1077 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using NUnit.Framework; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Serialization; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Core.Strings; -using Umbraco.Cms.Tests.Common.Attributes; -using Umbraco.Cms.Tests.Common.Builders; -using Umbraco.Cms.Tests.Common.Testing; -using Umbraco.Cms.Tests.Integration.Testing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Mapping; - -[TestFixture] -[UmbracoTest(Mapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerTest)] -public class ContentTypeModelMappingTests : UmbracoIntegrationTest -{ - [SetUp] - public void SetupTest() - { - _sut = Services.GetRequiredService(); - _dataTypeService = Services.GetRequiredService(); - _fileService = Services.GetRequiredService(); - _serializer = Services.GetRequiredService(); - } - - private IDataTypeService _dataTypeService; - private IUmbracoMapper _sut; - private IFileService _fileService; - private IConfigurationEditorJsonSerializer _serializer; - - [Test] - public void MemberTypeSave_To_IMemberType() - { - // Arrange - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var display = CreateMemberTypeSave(dataType.Id); - - // Act - var result = _sut.Map(display); - - // Assert - Assert.AreEqual(display.Alias, result.Alias); - Assert.AreEqual(display.Description, result.Description); - Assert.AreEqual(display.Icon, result.Icon); - Assert.AreEqual(display.Id, result.Id); - Assert.AreEqual(display.Name, result.Name); - Assert.AreEqual(display.ParentId, result.ParentId); - Assert.AreEqual(display.Path, result.Path); - Assert.AreEqual(display.Thumbnail, result.Thumbnail); - Assert.AreEqual(display.ListView, result.ListView); - Assert.AreEqual(display.AllowAsRoot, result.AllowedAsRoot); - Assert.AreEqual(display.CreateDate, result.CreateDate); - Assert.AreEqual(display.UpdateDate, result.UpdateDate); - - // TODO: Now we need to assert all of the more complicated parts - Assert.AreEqual(display.Groups.Count(), result.PropertyGroups.Count); - for (var i = 0; i < display.Groups.Count(); i++) - { - Assert.AreEqual(display.Groups.ElementAt(i).Id, result.PropertyGroups.ElementAt(i).Id); - Assert.AreEqual(display.Groups.ElementAt(i).Name, result.PropertyGroups.ElementAt(i).Name); - var propTypes = display.Groups.ElementAt(i).Properties; - Assert.AreEqual(propTypes.Count(), result.PropertyTypes.Count()); - for (var j = 0; j < propTypes.Count(); j++) - { - Assert.AreEqual(propTypes.ElementAt(j).Id, result.PropertyTypes.ElementAt(j).Id); - Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.PropertyTypes.ElementAt(j).DataTypeId); - Assert.AreEqual(propTypes.ElementAt(j).MemberCanViewProperty, result.MemberCanViewProperty(result.PropertyTypes.ElementAt(j).Alias)); - Assert.AreEqual(propTypes.ElementAt(j).MemberCanEditProperty, result.MemberCanEditProperty(result.PropertyTypes.ElementAt(j).Alias)); - Assert.AreEqual(propTypes.ElementAt(j).IsSensitiveData, result.IsSensitiveProperty(result.PropertyTypes.ElementAt(j).Alias)); - } - } - } - - [Test] - public void MediaTypeSave_To_IMediaType() - { - // Arrange - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var display = CreateMediaTypeSave(dataType.Id); - - // Act - var result = _sut.Map(display); - - // Assert - Assert.AreEqual(display.Alias, result.Alias); - Assert.AreEqual(display.Description, result.Description); - Assert.AreEqual(display.Icon, result.Icon); - Assert.AreEqual(display.Id, result.Id); - Assert.AreEqual(display.Name, result.Name); - Assert.AreEqual(display.ParentId, result.ParentId); - Assert.AreEqual(display.Path, result.Path); - Assert.AreEqual(display.Thumbnail, result.Thumbnail); - Assert.AreEqual(display.ListView, result.ListView); - Assert.AreEqual(display.AllowAsRoot, result.AllowedAsRoot); - Assert.AreEqual(display.CreateDate, result.CreateDate); - Assert.AreEqual(display.UpdateDate, result.UpdateDate); - - // TODO: Now we need to assert all of the more complicated parts - Assert.AreEqual(display.Groups.Count(), result.PropertyGroups.Count); - for (var i = 0; i < display.Groups.Count(); i++) - { - Assert.AreEqual(display.Groups.ElementAt(i).Id, result.PropertyGroups.ElementAt(i).Id); - Assert.AreEqual(display.Groups.ElementAt(i).Name, result.PropertyGroups.ElementAt(i).Name); - var propTypes = display.Groups.ElementAt(i).Properties; - Assert.AreEqual(propTypes.Count(), result.PropertyTypes.Count()); - for (var j = 0; j < propTypes.Count(); j++) - { - Assert.AreEqual(propTypes.ElementAt(j).Id, result.PropertyTypes.ElementAt(j).Id); - Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.PropertyTypes.ElementAt(j).DataTypeId); - } - } - } - - [Test] - [LongRunning] - public void ContentTypeSave_To_IContentType() - { - // Arrange - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var templates = new ITemplate[] - { - // Note the aliases is important - TODO use builder - new Template(Services.GetRequiredService(), "Name 1", "test"), - new Template(Services.GetRequiredService(), "Name 2", "template1"), - new Template(Services.GetRequiredService(), "Name 3", "template2") - }; - - foreach (var template in templates) - { - _fileService.SaveTemplate(template); - } - - var display = CreateContentTypeSave(dataType.Id); - - // Act - var result = _sut.Map(display); - - // Assert - Assert.AreEqual(display.Alias, result.Alias); - Assert.AreEqual(display.Description, result.Description); - Assert.AreEqual(display.Icon, result.Icon); - Assert.AreEqual(display.Id, result.Id); - Assert.AreEqual(display.Name, result.Name); - Assert.AreEqual(display.ParentId, result.ParentId); - Assert.AreEqual(display.Path, result.Path); - Assert.AreEqual(display.Thumbnail, result.Thumbnail); - Assert.AreEqual(display.ListView, result.ListView); - Assert.AreEqual(display.AllowAsRoot, result.AllowedAsRoot); - Assert.AreEqual(display.CreateDate, result.CreateDate); - Assert.AreEqual(display.UpdateDate, result.UpdateDate); - - // TODO: Now we need to assert all of the more complicated parts - Assert.AreEqual(display.Groups.Count(), result.PropertyGroups.Count); - for (var i = 0; i < display.Groups.Count(); i++) - { - Assert.AreEqual(display.Groups.ElementAt(i).Id, result.PropertyGroups.ElementAt(i).Id); - Assert.AreEqual(display.Groups.ElementAt(i).Name, result.PropertyGroups.ElementAt(i).Name); - var propTypes = display.Groups.ElementAt(i).Properties; - Assert.AreEqual(propTypes.Count(), result.PropertyTypes.Count()); - for (var j = 0; j < propTypes.Count(); j++) - { - Assert.AreEqual(propTypes.ElementAt(j).Id, result.PropertyTypes.ElementAt(j).Id); - Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.PropertyTypes.ElementAt(j).DataTypeId); - Assert.AreEqual(propTypes.ElementAt(j).LabelOnTop, result.PropertyTypes.ElementAt(j).LabelOnTop); - } - } - - var allowedTemplateAliases = display.AllowedTemplates - .Concat(new[] { display.DefaultTemplate }) - .Distinct(); - - Assert.AreEqual(allowedTemplateAliases.Count(), result.AllowedTemplates.Count()); - for (var i = 0; i < display.AllowedTemplates.Count(); i++) - { - Assert.AreEqual(display.AllowedTemplates.ElementAt(i), result.AllowedTemplates.ElementAt(i).Alias); - } - } - - [Test] - public void MediaTypeSave_With_Composition_To_IMediaType() - { - // Arrange - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var display = CreateCompositionMediaTypeSave(dataType.Id); - - // Act - var result = _sut.Map(display); - - // Assert - Assert.AreEqual(display.Groups.Count(x => x.Inherited == false), result.PropertyGroups.Count); - - // TODO: Now we need to assert all of the more complicated parts - } - - [Test] - public void ContentTypeSave_With_Composition_To_IContentType() - { - // Arrange - - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var display = CreateCompositionContentTypeSave(dataType.Id); - - // Act - var result = _sut.Map(display); - - // Assert - // TODO: Now we need to assert all of the more complicated parts - Assert.AreEqual(display.Groups.Count(x => x.Inherited == false), result.PropertyGroups.Count); - } - - [Test] - public void IMemberType_To_MemberTypeDisplay() - { - // Arrange - var memberType = MemberTypeBuilder.CreateSimpleMemberType(); - var alias = memberType.PropertyTypes.Last().Alias; - memberType.SetIsSensitiveProperty(alias, true); - memberType.SetMemberCanEditProperty(alias, true); - memberType.SetMemberCanViewProperty(alias, true); - MemberTypeBuilder.EnsureAllIds(memberType, 8888); - - // Act - var result = _sut.Map(memberType); - - // Assert - Assert.AreEqual(memberType.Alias, result.Alias); - Assert.AreEqual(memberType.Description, result.Description); - Assert.AreEqual(memberType.Icon, result.Icon); - Assert.AreEqual(memberType.Id, result.Id); - Assert.AreEqual(memberType.Name, result.Name); - Assert.AreEqual(memberType.ParentId, result.ParentId); - Assert.AreEqual(memberType.Path, result.Path); - Assert.AreEqual(memberType.Thumbnail, result.Thumbnail); - Assert.AreEqual(memberType.ListView, result.ListView); - Assert.AreEqual(memberType.CreateDate, result.CreateDate); - Assert.AreEqual(memberType.UpdateDate, result.UpdateDate); - - Assert.AreEqual(memberType.PropertyGroups.Count(), result.Groups.Count()); - for (var i = 0; i < memberType.PropertyGroups.Count(); i++) - { - Assert.AreEqual(memberType.PropertyGroups.ElementAt(i).Id, result.Groups.ElementAt(i).Id); - Assert.AreEqual(memberType.PropertyGroups.ElementAt(i).Name, result.Groups.ElementAt(i).Name); - var propTypes = memberType.PropertyGroups.ElementAt(i).PropertyTypes; - - Assert.AreEqual(propTypes.Count(), result.Groups.ElementAt(i).Properties.Count()); - for (var j = 0; j < propTypes.Count(); j++) - { - Assert.AreEqual(propTypes.ElementAt(j).Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id); - Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId); - - Assert.AreEqual(memberType.MemberCanViewProperty(propTypes.ElementAt(j).Alias), result.Groups.ElementAt(i).Properties.ElementAt(j).MemberCanViewProperty); - Assert.AreEqual(memberType.MemberCanEditProperty(propTypes.ElementAt(j).Alias), result.Groups.ElementAt(i).Properties.ElementAt(j).MemberCanEditProperty); - } - } - - Assert.AreEqual(memberType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); - } - - [Test] - public void IMediaType_To_MediaTypeDisplay() - { - // Arrange - var mediaType = MediaTypeBuilder.CreateImageMediaType(); - MediaTypeBuilder.EnsureAllIds(mediaType, 8888); - - // Act - var result = _sut.Map(mediaType); - - // Assert - Assert.AreEqual(mediaType.Alias, result.Alias); - Assert.AreEqual(mediaType.Description, result.Description); - Assert.AreEqual(mediaType.Icon, result.Icon); - Assert.AreEqual(mediaType.Id, result.Id); - Assert.AreEqual(mediaType.Name, result.Name); - Assert.AreEqual(mediaType.ParentId, result.ParentId); - Assert.AreEqual(mediaType.Path, result.Path); - Assert.AreEqual(mediaType.Thumbnail, result.Thumbnail); - Assert.AreEqual(mediaType.ListView, result.ListView); - Assert.AreEqual(mediaType.CreateDate, result.CreateDate); - Assert.AreEqual(mediaType.UpdateDate, result.UpdateDate); - - Assert.AreEqual(mediaType.PropertyGroups.Count(), result.Groups.Count()); - for (var i = 0; i < mediaType.PropertyGroups.Count(); i++) - { - Assert.AreEqual(mediaType.PropertyGroups.ElementAt(i).Id, result.Groups.ElementAt(i).Id); - Assert.AreEqual(mediaType.PropertyGroups.ElementAt(i).Name, result.Groups.ElementAt(i).Name); - var propTypes = mediaType.PropertyGroups.ElementAt(i).PropertyTypes; - - Assert.AreEqual(propTypes.Count(), result.Groups.ElementAt(i).Properties.Count()); - for (var j = 0; j < propTypes.Count(); j++) - { - Assert.AreEqual(propTypes.ElementAt(j).Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id); - Assert.AreEqual(propTypes.ElementAt(j).DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId); - } - } - - Assert.AreEqual(mediaType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); - } - - [Test] - public void IContentType_To_ContentTypeDisplay() - { - // Arrange - //// _dataTypeService.Setup(x => x.GetDataType(It.IsAny())) - //// .Returns(new DataType(new VoidEditor(Mock.Of(), Mock.Of(), Mock.Of(),Mock.Of(), Mock.Of()))); - // - // setup the mocks to return the data we want to test against... - var contentType = ContentTypeBuilder.CreateTextPageContentType(); - ContentTypeBuilder.EnsureAllIds(contentType, 8888); - - // Act - var result = _sut.Map(contentType); - - // Assert - Assert.AreEqual(contentType.Alias, result.Alias); - Assert.AreEqual(contentType.Description, result.Description); - Assert.AreEqual(contentType.Icon, result.Icon); - Assert.AreEqual(contentType.Id, result.Id); - Assert.AreEqual(contentType.Name, result.Name); - Assert.AreEqual(contentType.ParentId, result.ParentId); - Assert.AreEqual(contentType.Path, result.Path); - Assert.AreEqual(contentType.Thumbnail, result.Thumbnail); - Assert.AreEqual(contentType.ListView, result.ListView); - Assert.AreEqual(contentType.CreateDate, result.CreateDate); - Assert.AreEqual(contentType.UpdateDate, result.UpdateDate); - Assert.AreEqual(contentType.DefaultTemplate.Alias, result.DefaultTemplate.Alias); - - Assert.AreEqual(contentType.PropertyGroups.Count, result.Groups.Count()); - for (var i = 0; i < contentType.PropertyGroups.Count; i++) - { - Assert.AreEqual(contentType.PropertyGroups[i].Id, result.Groups.ElementAt(i).Id); - Assert.AreEqual(contentType.PropertyGroups[i].Name, result.Groups.ElementAt(i).Name); - var propTypes = contentType.PropertyGroups[i].PropertyTypes; - - Assert.AreEqual(propTypes.Count, result.Groups.ElementAt(i).Properties.Count()); - for (var j = 0; j < propTypes.Count; j++) - { - Assert.AreEqual(propTypes[j].Id, result.Groups.ElementAt(i).Properties.ElementAt(j).Id); - Assert.AreEqual(propTypes[j].DataTypeId, result.Groups.ElementAt(i).Properties.ElementAt(j).DataTypeId); - Assert.AreEqual(propTypes[j].LabelOnTop, result.Groups.ElementAt(i).Properties.ElementAt(j).LabelOnTop); - } - } - - Assert.AreEqual(contentType.AllowedTemplates.Count(), result.AllowedTemplates.Count()); - for (var i = 0; i < contentType.AllowedTemplates.Count(); i++) - { - Assert.AreEqual(contentType.AllowedTemplates.ElementAt(i).Id, result.AllowedTemplates.ElementAt(i).Id); - } - - Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); - } - - [Test] - public void MemberPropertyGroupBasic_To_MemberPropertyGroup() - { - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var basic = new PropertyGroupBasic - { - Id = 222, - Alias = "group1", - Name = "Group 1", - SortOrder = 1, - Properties = new[] - { - new MemberPropertyTypeBasic - { - MemberCanEditProperty = true, - MemberCanViewProperty = true, - IsSensitiveData = true, - Id = 33, - SortOrder = 1, - Alias = "prop1", - Description = "property 1", - DataTypeId = dataType.Id, - GroupId = 222, - Label = "Prop 1", - Validation = new PropertyTypeValidation {Mandatory = true, Pattern = null} - }, - new MemberPropertyTypeBasic - { - MemberCanViewProperty = false, - MemberCanEditProperty = false, - IsSensitiveData = false, - Id = 34, - SortOrder = 2, - Alias = "prop2", - Description = "property 2", - DataTypeId = dataType.Id, - GroupId = 222, - Label = "Prop 2", - Validation = new PropertyTypeValidation {Mandatory = false, Pattern = null} - } - } - }; - - var contentType = new MemberTypeSave { Id = 0, ParentId = -1, Alias = "alias", Groups = new[] { basic } }; - - // proper group properties mapping takes place when mapping the content type, - // not when mapping the group - because of inherited properties and such - // var result = Mapper.Map(basic); - var result = _sut.Map(contentType).PropertyGroups[0]; - - Assert.AreEqual(basic.Name, result.Name); - Assert.AreEqual(basic.Id, result.Id); - Assert.AreEqual(basic.SortOrder, result.SortOrder); - Assert.AreEqual(basic.Properties.Count(), result.PropertyTypes.Count()); - } - - [Test] - public void PropertyGroupBasic_To_PropertyGroup() - { - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var basic = new PropertyGroupBasic - { - Id = 222, - Alias = "group1", - Name = "Group 1", - SortOrder = 1, - Properties = new[] - { - new PropertyTypeBasic - { - Id = 33, - SortOrder = 1, - Alias = "prop1", - Description = "property 1", - DataTypeId = dataType.Id, - GroupId = 222, - Label = "Prop 1", - Validation = new PropertyTypeValidation {Mandatory = true, Pattern = null} - }, - new PropertyTypeBasic - { - Id = 34, - SortOrder = 2, - Alias = "prop2", - Description = "property 2", - DataTypeId = dataType.Id, - GroupId = 222, - Label = "Prop 2", - Validation = new PropertyTypeValidation {Mandatory = false, Pattern = null} - } - } - }; - - var contentType = new DocumentTypeSave - { - Id = 0, - ParentId = -1, - Alias = "alias", - AllowedTemplates = Enumerable.Empty(), - Groups = new[] { basic } - }; - - // proper group properties mapping takes place when mapping the content type, - // not when mapping the group - because of inherited properties and such - // var result = Mapper.Map(basic); - var result = _sut.Map(contentType).PropertyGroups[0]; - - Assert.AreEqual(basic.Name, result.Name); - Assert.AreEqual(basic.Id, result.Id); - Assert.AreEqual(basic.SortOrder, result.SortOrder); - Assert.AreEqual(basic.Properties.Count(), result.PropertyTypes.Count()); - } - - [Test] - public void MemberPropertyTypeBasic_To_PropertyType() - { - var basic = new MemberPropertyTypeBasic - { - Id = 33, - SortOrder = 1, - Alias = "prop1", - Description = "property 1", - DataTypeId = -88, - GroupId = 222, - Label = "Prop 1", - Validation = new PropertyTypeValidation - { - Mandatory = true, - MandatoryMessage = "Please enter a value", - Pattern = "xyz", - PatternMessage = "Please match the pattern" - } - }; - - var result = _sut.Map(basic); - - Assert.AreEqual(basic.Id, result.Id); - Assert.AreEqual(basic.SortOrder, result.SortOrder); - Assert.AreEqual(basic.Alias, result.Alias); - Assert.AreEqual(basic.Description, result.Description); - Assert.AreEqual(basic.DataTypeId, result.DataTypeId); - Assert.AreEqual(basic.Label, result.Name); - Assert.AreEqual(basic.Validation.Mandatory, result.Mandatory); - Assert.AreEqual(basic.Validation.MandatoryMessage, result.MandatoryMessage); - Assert.AreEqual(basic.Validation.Pattern, result.ValidationRegExp); - Assert.AreEqual(basic.Validation.PatternMessage, result.ValidationRegExpMessage); - Assert.AreEqual(basic.LabelOnTop, result.LabelOnTop); - } - - [Test] - public void PropertyTypeBasic_To_PropertyType() - { - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - _dataTypeService.Save(dataType); - - var basic = new PropertyTypeBasic - { - Id = 33, - SortOrder = 1, - Alias = "prop1", - Description = "property 1", - DataTypeId = dataType.Id, - GroupId = 222, - Label = "Prop 1", - Validation = new PropertyTypeValidation - { - Mandatory = true, - MandatoryMessage = "Please enter a value", - Pattern = "xyz", - PatternMessage = "Please match the pattern" - } - }; - - var result = _sut.Map(basic); - - Assert.AreEqual(basic.Id, result.Id); - Assert.AreEqual(basic.SortOrder, result.SortOrder); - Assert.AreEqual(basic.Alias, result.Alias); - Assert.AreEqual(basic.Description, result.Description); - Assert.AreEqual(basic.DataTypeId, result.DataTypeId); - Assert.AreEqual(basic.Label, result.Name); - Assert.AreEqual(basic.Validation.Mandatory, result.Mandatory); - Assert.AreEqual(basic.Validation.MandatoryMessage, result.MandatoryMessage); - Assert.AreEqual(basic.Validation.Pattern, result.ValidationRegExp); - Assert.AreEqual(basic.Validation.PatternMessage, result.ValidationRegExpMessage); - Assert.AreEqual(basic.LabelOnTop, result.LabelOnTop); - } - - [Test] - public void IMediaTypeComposition_To_MediaTypeDisplay() - { - // Arrange - var ctMain = MediaTypeBuilder.CreateSimpleMediaType("parent", "Parent"); - - // not assigned to tab - ctMain.AddPropertyType( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) - { - Alias = "umbracoUrlName", - Name = "Slug", - Description = string.Empty, - Mandatory = false, - SortOrder = 1, - DataTypeId = -88 - }); - MediaTypeBuilder.EnsureAllIds(ctMain, 8888); - var ctChild1 = MediaTypeBuilder.CreateSimpleMediaType("child1", "Child 1", ctMain, true); - ctChild1.AddPropertyType( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) - { - Alias = "someProperty", - Name = "Some Property", - Description = string.Empty, - Mandatory = false, - SortOrder = 1, - DataTypeId = -88 - }, - "anotherTab", - "Another tab"); - MediaTypeBuilder.EnsureAllIds(ctChild1, 7777); - var contentType = - MediaTypeBuilder.CreateSimpleMediaType("child2", "Child 2", ctChild1, true, "customGroup", "CustomGroup"); - - // not assigned to tab - contentType.AddPropertyType( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) - { - Alias = "umbracoUrlAlias", - Name = "AltUrl", - Description = string.Empty, - Mandatory = false, - SortOrder = 1, - DataTypeId = -88 - }); - MediaTypeBuilder.EnsureAllIds(contentType, 6666); - - // Act - var result = _sut.Map(contentType); - - // Assert - Assert.AreEqual(contentType.Alias, result.Alias); - Assert.AreEqual(contentType.Description, result.Description); - Assert.AreEqual(contentType.Icon, result.Icon); - Assert.AreEqual(contentType.Id, result.Id); - Assert.AreEqual(contentType.Name, result.Name); - Assert.AreEqual(contentType.ParentId, result.ParentId); - Assert.AreEqual(contentType.Path, result.Path); - Assert.AreEqual(contentType.Thumbnail, result.Thumbnail); - Assert.AreEqual(contentType.ListView, result.ListView); - Assert.AreEqual(contentType.CreateDate, result.CreateDate); - Assert.AreEqual(contentType.UpdateDate, result.UpdateDate); - - Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.IsGenericProperties == false)); - Assert.AreEqual(1, result.Groups.Count(x => x.IsGenericProperties)); - Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.IsGenericProperties == false)); - - var allPropertiesMapped = result.Groups.SelectMany(x => x.Properties).ToArray(); - var allPropertyIdsMapped = allPropertiesMapped.Select(x => x.Id).ToArray(); - var allSourcePropertyIds = contentType.CompositionPropertyTypes.Select(x => x.Id).ToArray(); - - Assert.AreEqual(contentType.PropertyTypes.Count(), allPropertiesMapped.Count(x => x.Inherited == false)); - Assert.AreEqual(allPropertyIdsMapped.Count(), allSourcePropertyIds.Count()); - Assert.IsTrue(allPropertyIdsMapped.ContainsAll(allSourcePropertyIds)); - - Assert.AreEqual(2, result.Groups.Count(x => x.ParentTabContentTypes.Any())); - Assert.IsTrue( - result.Groups.SelectMany(x => x.ParentTabContentTypes).ContainsAll(new[] { ctMain.Id, ctChild1.Id })); - - Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); - } - - [Test] - public void IContentTypeComposition_To_ContentTypeDisplay() - { - // Arrange - var ctMain = ContentTypeBuilder.CreateSimpleContentType(); - - // not assigned to tab - ctMain.AddPropertyType( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) - { - Alias = "umbracoUrlName", - Name = "Slug", - Description = string.Empty, - Mandatory = false, - SortOrder = 1, - DataTypeId = -88 - }); - ContentTypeBuilder.EnsureAllIds(ctMain, 8888); - var ctChild1 = ContentTypeBuilder.CreateSimpleContentType("child1", "Child 1", ctMain, randomizeAliases: true); - ctChild1.AddPropertyType( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) - { - Alias = "someProperty", - Name = "Some Property", - Description = string.Empty, - Mandatory = false, - SortOrder = 1, - DataTypeId = -88 - }, - "anotherTab", - "Another tab"); - ContentTypeBuilder.EnsureAllIds(ctChild1, 7777); - var contentType = ContentTypeBuilder.CreateSimpleContentType("child2", "Child 2", ctChild1, randomizeAliases: true, propertyGroupAlias: "customGroup", propertyGroupName: "CustomGroup"); - - // not assigned to tab - contentType.AddPropertyType( - new PropertyType(ShortStringHelper, Constants.PropertyEditors.Aliases.TextBox, ValueStorageType.Ntext) - { - Alias = "umbracoUrlAlias", - Name = "AltUrl", - Description = string.Empty, - Mandatory = false, - SortOrder = 1, - DataTypeId = -88 - }); - ContentTypeBuilder.EnsureAllIds(contentType, 6666); - - // Act - var result = _sut.Map(contentType); - - // Assert - Assert.AreEqual(contentType.Alias, result.Alias); - Assert.AreEqual(contentType.Description, result.Description); - Assert.AreEqual(contentType.Icon, result.Icon); - Assert.AreEqual(contentType.Id, result.Id); - Assert.AreEqual(contentType.Name, result.Name); - Assert.AreEqual(contentType.ParentId, result.ParentId); - Assert.AreEqual(contentType.Path, result.Path); - Assert.AreEqual(contentType.Thumbnail, result.Thumbnail); - Assert.AreEqual(contentType.ListView, result.ListView); - Assert.AreEqual(contentType.CreateDate, result.CreateDate); - Assert.AreEqual(contentType.UpdateDate, result.UpdateDate); - Assert.AreEqual(contentType.DefaultTemplate.Alias, result.DefaultTemplate.Alias); - - Assert.AreEqual(contentType.CompositionPropertyGroups.Select(x => x.Name).Distinct().Count(), result.Groups.Count(x => x.IsGenericProperties == false)); - Assert.AreEqual(1, result.Groups.Count(x => x.IsGenericProperties)); - Assert.AreEqual(contentType.PropertyGroups.Count(), result.Groups.Count(x => x.Inherited == false && x.IsGenericProperties == false)); - - var allPropertiesMapped = result.Groups.SelectMany(x => x.Properties).ToArray(); - var allPropertyIdsMapped = allPropertiesMapped.Select(x => x.Id).ToArray(); - var allSourcePropertyIds = contentType.CompositionPropertyTypes.Select(x => x.Id).ToArray(); - - Assert.AreEqual(contentType.PropertyTypes.Count(), allPropertiesMapped.Count(x => x.Inherited == false)); - Assert.AreEqual(allPropertyIdsMapped.Count(), allSourcePropertyIds.Count()); - Assert.IsTrue(allPropertyIdsMapped.ContainsAll(allSourcePropertyIds)); - - Assert.AreEqual(2, result.Groups.Count(x => x.ParentTabContentTypes.Any())); - Assert.IsTrue( - result.Groups.SelectMany(x => x.ParentTabContentTypes).ContainsAll(new[] { ctMain.Id, ctChild1.Id })); - - Assert.AreEqual(contentType.AllowedTemplates.Count(), result.AllowedTemplates.Count()); - for (var i = 0; i < contentType.AllowedTemplates.Count(); i++) - { - Assert.AreEqual(contentType.AllowedTemplates.ElementAt(i).Id, result.AllowedTemplates.ElementAt(i).Id); - } - - Assert.AreEqual(contentType.AllowedContentTypes.Count(), result.AllowedContentTypes.Count()); - } - - [Test] - public void MemberPropertyTypeBasic_To_MemberPropertyTypeDisplay() - { - var basic = new MemberPropertyTypeBasic - { - Id = 33, - SortOrder = 1, - Alias = "prop1", - Description = "property 1", - DataTypeId = -88, - GroupId = 222, - Label = "Prop 1", - MemberCanViewProperty = true, - MemberCanEditProperty = true, - IsSensitiveData = true, - Validation = new PropertyTypeValidation { Mandatory = true, Pattern = "xyz" } - }; - - var result = _sut.Map(basic); - - Assert.AreEqual(basic.Id, result.Id); - Assert.AreEqual(basic.SortOrder, result.SortOrder); - Assert.AreEqual(basic.Alias, result.Alias); - Assert.AreEqual(basic.Description, result.Description); - Assert.AreEqual(basic.GroupId, result.GroupId); - Assert.AreEqual(basic.Inherited, result.Inherited); - Assert.AreEqual(basic.Label, result.Label); - Assert.AreEqual(basic.Validation, result.Validation); - Assert.AreEqual(basic.MemberCanViewProperty, result.MemberCanViewProperty); - Assert.AreEqual(basic.MemberCanEditProperty, result.MemberCanEditProperty); - Assert.AreEqual(basic.IsSensitiveData, result.IsSensitiveData); - } - - [Test] - public void PropertyTypeBasic_To_PropertyTypeDisplay() - { - // TODO use builder - var dataType = new DataType(Services.GetRequiredService(), _serializer) { Name = "TODO" }; - - var basic = new PropertyTypeBasic - { - Id = 33, - SortOrder = 1, - Alias = "prop1", - Description = "property 1", - DataTypeId = dataType.Id, - GroupId = 222, - Label = "Prop 1", - Validation = new PropertyTypeValidation { Mandatory = true, Pattern = "xyz" } - }; - - var result = _sut.Map(basic); - - Assert.AreEqual(basic.Id, result.Id); - Assert.AreEqual(basic.SortOrder, result.SortOrder); - Assert.AreEqual(basic.Alias, result.Alias); - Assert.AreEqual(basic.Description, result.Description); - Assert.AreEqual(basic.GroupId, result.GroupId); - Assert.AreEqual(basic.Inherited, result.Inherited); - Assert.AreEqual(basic.Label, result.Label); - Assert.AreEqual(basic.Validation, result.Validation); - } - - private MemberTypeSave CreateMemberTypeSave(int dataTypeId) => - new() - { - Alias = "test", - AllowAsRoot = true, - AllowedContentTypes = new[] { 666, 667 }, - Description = "hello world", - Icon = "tree-icon", - Id = 1234, - Key = new Guid("8A60656B-3866-46AB-824A-48AE85083070"), - Name = "My content type", - Path = "-1,1234", - ParentId = -1, - Thumbnail = "tree-thumb", - ListView = Constants.DataTypes.Guids.ListViewMembersGuid, - Groups = new[] - { - new PropertyGroupBasic - { - Id = 987, - Alias = "tab1", - Name = "Tab 1", - SortOrder = 0, - Inherited = false, - Properties = new[] - { - new MemberPropertyTypeBasic - { - MemberCanEditProperty = true, - MemberCanViewProperty = true, - IsSensitiveData = true, - Alias = "property1", - Description = "this is property 1", - Inherited = false, - Label = "Property 1", - Validation = new PropertyTypeValidation - { - Mandatory = false, Pattern = string.Empty - }, - SortOrder = 0, - DataTypeId = dataTypeId - } - } - } - } - }; - - private MediaTypeSave CreateMediaTypeSave(int dataTypeId) => - new() - { - Alias = "test", - AllowAsRoot = true, - AllowedContentTypes = new[] { 666, 667 }, - Description = "hello world", - Icon = "tree-icon", - Id = 1234, - Key = new Guid("8A60656B-3866-46AB-824A-48AE85083070"), - Name = "My content type", - Path = "-1,1234", - ParentId = -1, - Thumbnail = "tree-thumb", - ListView = Constants.DataTypes.Guids.ListViewMembersGuid, - Groups = new[] - { - new PropertyGroupBasic - { - Id = 987, - Alias = "tab1", - Name = "Tab 1", - SortOrder = 0, - Inherited = false, - Properties = new[] - { - new PropertyTypeBasic - { - Alias = "property1", - Description = "this is property 1", - Inherited = false, - Label = "Property 1", - Validation = new PropertyTypeValidation {Mandatory = false, Pattern = string.Empty}, - SortOrder = 0, - DataTypeId = dataTypeId - } - } - } - } - }; - - private DocumentTypeSave CreateContentTypeSave(int dataTypeId) => - new() - { - Alias = "test", - AllowAsRoot = true, - AllowedTemplates = new[] { "template1", "template2" }, - AllowedContentTypes = new[] { 666, 667 }, - DefaultTemplate = "test", - Description = "hello world", - Icon = "tree-icon", - Id = 1234, - Key = new Guid("8A60656B-3866-46AB-824A-48AE85083070"), - Name = "My content type", - Path = "-1,1234", - ParentId = -1, - Thumbnail = "tree-thumb", - ListView = Constants.DataTypes.Guids.ListViewMembersGuid, - Groups = new[] - { - new PropertyGroupBasic - { - Id = 987, - Alias = "tab1", - Name = "Tab 1", - SortOrder = 0, - Inherited = false, - Properties = new[] - { - new PropertyTypeBasic - { - Alias = "property1", - Description = "this is property 1", - Inherited = false, - Label = "Property 1", - Validation = new PropertyTypeValidation - { - Mandatory = false, Pattern = string.Empty - }, - SortOrder = 0, - LabelOnTop = true, - DataTypeId = dataTypeId - } - } - } - } - }; - - private MediaTypeSave CreateCompositionMediaTypeSave(int dataTypeId) => - new() - { - Alias = "test", - AllowAsRoot = true, - AllowedContentTypes = new[] { 666, 667 }, - Description = "hello world", - Icon = "tree-icon", - Id = 1234, - Key = new Guid("8A60656B-3866-46AB-824A-48AE85083070"), - Name = "My content type", - Path = "-1,1234", - ParentId = -1, - Thumbnail = "tree-thumb", - ListView = Constants.DataTypes.Guids.ListViewMembersGuid, - Groups = new[] - { - new PropertyGroupBasic - { - Id = 987, - Alias = "tab1", - Name = "Tab 1", - SortOrder = 0, - Inherited = false, - Properties = new[] - { - new PropertyTypeBasic - { - Alias = "property1", - Description = "this is property 1", - Inherited = false, - Label = "Property 1", - Validation = new PropertyTypeValidation {Mandatory = false, Pattern = string.Empty}, - SortOrder = 0, - LabelOnTop = true, - DataTypeId = dataTypeId - } - } - }, - new PropertyGroupBasic - { - Id = 894, - Alias = "tab2", - Name = "Tab 2", - SortOrder = 0, - Inherited = true, - Properties = new[] - { - new PropertyTypeBasic - { - Alias = "parentProperty", - Description = "this is a property from the parent", - Inherited = true, - Label = "Parent property", - Validation = new PropertyTypeValidation {Mandatory = false, Pattern = string.Empty}, - SortOrder = 0, - LabelOnTop = false, - DataTypeId = dataTypeId - } - } - } - } - }; - - private DocumentTypeSave CreateCompositionContentTypeSave(int dataTypeId) => - new() - { - Alias = "test", - AllowAsRoot = true, - AllowedTemplates = new[] { "template1", "template2" }, - AllowedContentTypes = new[] { 666, 667 }, - DefaultTemplate = "test", - Description = "hello world", - Icon = "tree-icon", - Id = 1234, - Key = new Guid("8A60656B-3866-46AB-824A-48AE85083070"), - Name = "My content type", - Path = "-1,1234", - ParentId = -1, - Thumbnail = "tree-thumb", - ListView = Constants.DataTypes.Guids.ListViewMembersGuid, - Groups = new[] - { - new PropertyGroupBasic - { - Id = 987, - Alias = "tab1", - Name = "Tab 1", - SortOrder = 0, - Inherited = false, - Properties = new[] - { - new PropertyTypeBasic - { - Alias = "property1", - Description = "this is property 1", - Inherited = false, - Label = "Property 1", - Validation = new PropertyTypeValidation - { - Mandatory = false, Pattern = string.Empty - }, - SortOrder = 0, - LabelOnTop = true, - DataTypeId = dataTypeId - } - } - }, - new PropertyGroupBasic - { - Id = 894, - Alias = "tab2", - Name = "Tab 2", - SortOrder = 0, - Inherited = true, - Properties = new[] - { - new PropertyTypeBasic - { - Alias = "parentProperty", - Description = "this is a property from the parent", - Inherited = true, - Label = "Parent property", - Validation = new PropertyTypeValidation - { - Mandatory = false, Pattern = string.Empty - }, - SortOrder = 0, - LabelOnTop = false, - DataTypeId = dataTypeId - } - } - } - } - }; -} diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UmbracoMapperTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UmbracoMapperTests.cs deleted file mode 100644 index fb9e40ea5756..000000000000 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UmbracoMapperTests.cs +++ /dev/null @@ -1,209 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Globalization; -using System.Linq; -using Microsoft.Extensions.DependencyInjection; -using NUnit.Framework; -using Umbraco.Cms.Core; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.PropertyEditors; -using Umbraco.Cms.Core.Services; -using Umbraco.Cms.Tests.Common.Builders; -using Umbraco.Cms.Tests.Common.Builders.Extensions; -using Umbraco.Cms.Tests.Common.Testing; -using Umbraco.Cms.Tests.Integration.Testing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Mapping; - -[TestFixture] -[UmbracoTest(Mapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerTest)] -public class UmbracoMapperTests : UmbracoIntegrationTest -{ - [SetUp] - public void SetUp() - { - _sut = Services.GetRequiredService(); - - _dataTypeService = Services.GetRequiredService(); - _propertyEditorCollection = Services.GetRequiredService(); - _mediaBuilder = new MediaBuilder(); - _contentBuilder = new ContentBuilder(); - _contentTypeBuilder = new ContentTypeBuilder(); - _contentTypeService = Services.GetRequiredService(); - _localizedTextService = Services.GetRequiredService(); - } - - private IUmbracoMapper _sut; - private IDataTypeService _dataTypeService; - private PropertyEditorCollection _propertyEditorCollection; - private MediaBuilder _mediaBuilder; - private ContentBuilder _contentBuilder; - private ContentTypeBuilder _contentTypeBuilder; - private IContentTypeService _contentTypeService; - private ILocalizedTextService _localizedTextService; - - [Test] - public void To_Media_Item_Simple() - { - var content = _mediaBuilder - .AddMediaType() - .AddPropertyGroup() - .AddPropertyType() - .Done() - .Done() - .Done() - .WithCreatorId(Constants.Security.SuperUserId) - .Build(); - - var result = _sut.Map>(content); - - AssertBasics(result, content); - - foreach (var p in content.Properties) - { - AssertBasicProperty(result, p); - } - } - - [Test] - public void To_Content_Item_Simple() - { - var content = _contentBuilder - .AddContentType() - .AddPropertyGroup() - .AddPropertyType() - .Done() - .Done() - .Done() - .WithCreatorId(Constants.Security.SuperUserId) - .Build(); - - var result = _sut.Map>(content); - - AssertBasics(result, content); - - foreach (var p in content.Properties) - { - AssertBasicProperty(result, p); - } - } - - [Test] - public void To_Content_Item_Dto() - { - var content = _contentBuilder - .AddContentType() - .AddPropertyGroup() - .AddPropertyType() - .Done() - .Done() - .Done() - .WithCreatorId(Constants.Security.SuperUserId) - .Build(); - - var result = _sut.Map(content); - - foreach (var p in content.Properties) - { - AssertProperty(result, p); - } - } - - [Test] - public void To_Media_Item_Dto() - { - var content = _mediaBuilder - .AddMediaType() - .AddPropertyGroup() - .AddPropertyType() - .Done() - .Done() - .Done() - .Build(); - - var result = _sut.Map(content); - - Assert.GreaterOrEqual(result.Properties.Count(), 1); - Assert.AreEqual(content.Properties.Count, result.Properties.Count()); - foreach (var p in content.Properties) - { - AssertProperty(result, p); - } - } - - private void AssertBasics(ContentItemBasic result, TPersisted content) - where T : ContentPropertyBasic - where TPersisted : IContentBase - { - Assert.AreEqual(content.Id, result.Id); - - var ownerId = content.CreatorId; - if (ownerId != 0) - { - Assert.IsNotNull(result.Owner); - Assert.AreEqual(Constants.Security.SuperUserId, result.Owner.UserId); - Assert.AreEqual("Administrator", result.Owner.Name); - } - else - { - Assert.IsNull(result.Owner); // because, 0 is no user - } - - Assert.AreEqual(content.ParentId, result.ParentId); - Assert.AreEqual(content.UpdateDate, result.UpdateDate); - Assert.AreEqual(content.CreateDate, result.CreateDate); - Assert.AreEqual(content.Name, result.Name); - Assert.AreEqual(content.Properties.Count(), result.Properties.Count(x => x.Alias.StartsWith("_umb_") == false)); - } - - private void AssertBasicProperty(IContentProperties result, IProperty p) - where T : ContentPropertyBasic - { - var pDto = result.Properties.SingleOrDefault(x => x.Alias == p.Alias); - Assert.IsNotNull(pDto); - Assert.AreEqual(p.Alias, pDto.Alias); - Assert.AreEqual(p.Id, pDto.Id); - - if (p.GetValue() == null) - { - Assert.AreEqual(pDto.Value, string.Empty); - } - else if (p.GetValue() is decimal decimalValue) - { - Assert.AreEqual(pDto.Value, decimalValue.ToString(NumberFormatInfo.InvariantInfo)); - } - else - { - Assert.AreEqual(pDto.Value, p.GetValue().ToString()); - } - } - - private void AssertProperty(IContentProperties result, IProperty p) - { - AssertBasicProperty(result, p); - - var pDto = result.Properties.SingleOrDefault(x => x.Alias == p.Alias); - Assert.IsNotNull(pDto); - Assert.AreEqual(p.PropertyType.Mandatory, pDto.IsRequired); - Assert.AreEqual(p.PropertyType.ValidationRegExp, pDto.ValidationRegExp); - Assert.AreEqual(p.PropertyType.Description, pDto.Description); - Assert.AreEqual(p.PropertyType.Name, pDto.Label); - Assert.AreEqual(_dataTypeService.GetDataType(p.PropertyType.DataTypeId), pDto.DataType); - Assert.AreEqual(_propertyEditorCollection[p.PropertyType.PropertyEditorAlias], pDto.PropertyEditor); - } - - private void AssertContentItem(ContentItemBasic result, T content) - where T : IContentBase - { - AssertBasics(result, content); - - foreach (var p in content.Properties) - { - AssertProperty(result, p); - } - } -} diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UserModelMapperTests.cs b/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UserModelMapperTests.cs deleted file mode 100644 index 25b5bd786c14..000000000000 --- a/tests/Umbraco.Tests.Integration/Umbraco.Core/Mapping/UserModelMapperTests.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; -using Newtonsoft.Json; -using NUnit.Framework; -using Umbraco.Cms.Core.Mapping; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Cms.Core.Models.Membership; -using Umbraco.Cms.Tests.Common.Testing; -using Umbraco.Cms.Tests.Integration.Testing; - -namespace Umbraco.Cms.Tests.Integration.Umbraco.Core.Mapping; - -[TestFixture] -[UmbracoTest(Mapper = true, Database = UmbracoTestOptions.Database.NewSchemaPerTest)] -public class UserModelMapperTests : UmbracoIntegrationTest -{ - [SetUp] - public void Setup() => _sut = Services.GetRequiredService(); - - private IUmbracoMapper _sut; - - [Test] - public void Map_UserGroupSave_To_IUserGroup() - { - IUserGroup userGroup = - new UserGroup(ShortStringHelper, 0, "alias", "name", "icon") { Id = 42 }; - - userGroup.Permissions = new HashSet() { "c" }; - - const string json = - "{\"id\":@@@ID@@@,\"alias\":\"perm1\",\"name\":\"Perm1\",\"icon\":\"icon-users\",\"sections\":[\"content\"],\"users\":[],\"defaultPermissions\":[\"F\",\"C\",\"A\"],\"assignedPermissions\":{},\"startContentId\":-1,\"startMediaId\":-1,\"action\":\"save\",\"parentId\":-1}"; - var userGroupSave = - JsonConvert.DeserializeObject(json.Replace("@@@ID@@@", userGroup.Id.ToString())); - - // failed, AutoMapper complained, "Unable to cast object of type 'WhereSelectArrayIterator`2[System.Char,System.String]' to type 'System.Collections.IList'". - // TODO: added ToList() in UserGroupFactory - _sut.Map(userGroupSave, userGroup); - } -} diff --git a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs index caa12f74f41d..1644a3b1e4aa 100644 --- a/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs +++ b/tests/Umbraco.Tests.Integration/Umbraco.Infrastructure/Persistence/Repositories/ContentTypeRepositoryTest.cs @@ -292,58 +292,6 @@ public void Can_Perform_Add_On_ContentTypeRepository() } } - [Test] - public void Can_Perform_Add_On_ContentTypeRepository_After_Model_Mapping() - { - // Arrange - var provider = ScopeProvider; - using (var scope = provider.CreateScope()) - { - var repository = ContentTypeRepository; - - // Act - var contentType = (IContentType)ContentTypeBuilder.CreateSimpleContentType2("test", "Test", propertyGroupAlias: "testGroup", propertyGroupName: "testGroup"); - - Assert.AreEqual(4, contentType.PropertyTypes.Count()); - - // remove all templates - since they are not saved, they would break the (!) mapping code - contentType.AllowedTemplates = new ITemplate[0]; - - // there is NO mapping from display to contentType, but only from save - // to contentType, so if we want to test, let's to it properly! - var display = Mapper.Map(contentType); - var save = MapToContentTypeSave(display); - var mapped = Mapper.Map(save); - - Assert.AreEqual(4, mapped.PropertyTypes.Count()); - - repository.Save(mapped); - - Assert.AreEqual(4, mapped.PropertyTypes.Count()); - - // re-get - contentType = repository.Get(mapped.Id); - - Assert.AreEqual(4, contentType.PropertyTypes.Count()); - - // Assert - Assert.That(contentType.HasIdentity, Is.True); - Assert.That(contentType.PropertyGroups.All(x => x.HasIdentity), Is.True); - Assert.That(contentType.PropertyTypes.All(x => x.HasIdentity), Is.True); - Assert.That(contentType.Path.Contains(","), Is.True); - Assert.That(contentType.SortOrder, Is.GreaterThan(0)); - - Assert.That(contentType.PropertyGroups.ElementAt(0).Name == "testGroup", Is.True); - var groupId = contentType.PropertyGroups.ElementAt(0).Id; - - var propertyTypes = contentType.PropertyTypes.ToArray(); - Assert.AreEqual("gen", propertyTypes[0].Alias); // just to be sure - Assert.IsNull(propertyTypes[0].PropertyGroupId); - Assert.IsTrue(propertyTypes.Skip(1).All(x => x.PropertyGroupId.Value == groupId)); - Assert.That(propertyTypes.Single(x => x.Alias == "title").LabelOnTop, Is.True); - } - } - [Test] public void Can_Perform_Update_On_ContentTypeRepository() { @@ -380,113 +328,6 @@ public void Can_Perform_Update_On_ContentTypeRepository() } } - // this is for tests only because it makes no sense at all to have such a - // mapping defined, we only need it for the weird tests that use it - private DocumentTypeSave MapToContentTypeSave(DocumentTypeDisplay display) => - new() - { - // EntityBasic - Name = display.Name, - Icon = display.Icon, - Trashed = display.Trashed, - Key = display.Key, - ParentId = display.ParentId, - //// Alias = display.Alias, - Path = display.Path, - //// AdditionalData = display.AdditionalData, - HistoryCleanup = display.HistoryCleanup, - - // ContentTypeBasic - Alias = display.Alias, - UpdateDate = display.UpdateDate, - CreateDate = display.CreateDate, - Description = display.Description, - Thumbnail = display.Thumbnail, - - // ContentTypeSave - CompositeContentTypes = display.CompositeContentTypes, - ListView = display.ListView, - AllowAsRoot = display.AllowAsRoot, - AllowedTemplates = display.AllowedTemplates.Select(x => x.Alias), - AllowedContentTypes = display.AllowedContentTypes, - DefaultTemplate = display.DefaultTemplate?.Alias, - Groups = display.Groups.Select(x => new PropertyGroupBasic - { - Inherited = x.Inherited, - Id = x.Id, - Key = x.Key, - Type = x.Type, - Name = x.Name, - Alias = x.Alias, - SortOrder = x.SortOrder, - Properties = x.Properties - }).ToArray() - }; - - [Test] - public void Can_Perform_Update_On_ContentTypeRepository_After_Model_Mapping() - { - // Arrange - var provider = ScopeProvider; - using (var scope = provider.CreateScope()) - { - var repository = ContentTypeRepository; - - // Act - var contentType = repository.Get(_textpageContentType.Id); - - // there is NO mapping from display to contentType, but only from save - // to contentType, so if we want to test, let's to it properly! - var display = Mapper.Map(contentType); - var save = MapToContentTypeSave(display); - - // modify... - save.Thumbnail = "Doc2.png"; - var contentGroup = save.Groups.Single(x => x.Name == "Content"); - contentGroup.Properties = contentGroup.Properties.Concat(new[] - { - new PropertyTypeBasic - { - Alias = "subtitle", - Label = "Subtitle", - Description = "Optional Subtitle", - Validation = new PropertyTypeValidation {Mandatory = false, Pattern = string.Empty}, - SortOrder = 1, - DataTypeId = -88, - LabelOnTop = true - } - }); - - var mapped = Mapper.Map(save, contentType); - - // just making sure - Assert.AreEqual(mapped.Thumbnail, "Doc2.png"); - Assert.IsTrue(mapped.PropertyTypes.Any(x => x.Alias == "subtitle")); - Assert.IsTrue(mapped.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop); - - repository.Save(mapped); - - var dirty = mapped.IsDirty(); - - // re-get - contentType = repository.Get(_textpageContentType.Id); - - // Assert - Assert.That(contentType.HasIdentity, Is.True); - Assert.That(dirty, Is.False); - Assert.That(contentType.Thumbnail, Is.EqualTo("Doc2.png")); - Assert.That(contentType.PropertyTypes.Any(x => x.Alias == "subtitle"), Is.True); - - Assert.That(contentType.PropertyTypes.Single(x => x.Alias == "subtitle").LabelOnTop, Is.True); - - foreach (var propertyType in contentType.PropertyTypes) - { - Assert.IsTrue(propertyType.HasIdentity); - Assert.Greater(propertyType.Id, 0); - } - } - } - [Test] public void Can_Perform_Delete_On_ContentTypeRepository() { diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs deleted file mode 100644 index 9d44472a086d..000000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Core/EnumExtensionsTests.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using NUnit.Framework; -using Umbraco.Cms.Core.Trees; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Core; - -[TestFixture] -public class EnumExtensionsTests -{ - [TestCase(TreeUse.Dialog, TreeUse.Dialog, true)] - [TestCase(TreeUse.Dialog, TreeUse.Main, false)] - [TestCase(TreeUse.Dialog | TreeUse.Main, TreeUse.Dialog, true)] - [TestCase(TreeUse.Dialog, TreeUse.Dialog | TreeUse.Main, false)] - public void HasFlagTest(TreeUse value, TreeUse test, bool expected) - { - // The built-in Enum.HasFlag() method determines whether - // all bits from are set (other bits can be set too). - if (expected) - { - Assert.IsTrue(value.HasFlag(test)); - } - else - { - Assert.IsFalse(value.HasFlag(test)); - } - } - - [TestCase(TreeUse.Dialog, TreeUse.Dialog, true)] - [TestCase(TreeUse.Dialog, TreeUse.Main, false)] - [TestCase(TreeUse.Dialog | TreeUse.Main, TreeUse.Dialog, true)] - [TestCase(TreeUse.Dialog, TreeUse.Dialog | TreeUse.Main, true)] - public void HasFlagAnyTest(TreeUse value, TreeUse test, bool expected) - { - // The HasFlagAny() extension method determines whether - // at least one bit from is set. - if (expected) - { - Assert.IsTrue(value.HasFlagAny(test)); - } - else - { - Assert.IsFalse(value.HasFlagAny(test)); - } - } -} diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs index fdcfead517bf..0fe22065a6ae 100644 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs +++ b/tests/Umbraco.Tests.UnitTests/Umbraco.Infrastructure/Mapping/MappingTests.cs @@ -115,17 +115,6 @@ public void InheritedMap() Assert.AreEqual("value", thing2.Value); } - [Test] - public void CollectionsMap() - { - var definitions = new MapDefinitionCollection(() => new IMapDefinition[] { new MapperDefinition2() }); - var mapper = new UmbracoMapper(definitions, _scopeProvider, NullLogger.Instance); - - // can map a PropertyCollection - var source = new PropertyCollection(); - var target = mapper.Map>(source); - } - [Test] [Explicit] public void ConcurrentMap() @@ -285,16 +274,6 @@ public void DefineMaps(IUmbracoMapper mapper) => private void Map(Thing1 source, Thing2 target, MapperContext context) => target.Value = source.Value; } - private class MapperDefinition2 : IMapDefinition - { - public void DefineMaps(IUmbracoMapper mapper) => - mapper.Define((source, context) => new ContentPropertyDto(), Map); - - private static void Map(IProperty source, ContentPropertyDto target, MapperContext context) - { - } - } - private class MapperDefinition3 : IMapDefinition { public void DefineMaps(IUmbracoMapper mapper) diff --git a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs b/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs deleted file mode 100644 index 8bfc48daa8a8..000000000000 --- a/tests/Umbraco.Tests.UnitTests/Umbraco.Web.Common/AngularIntegration/ContentModelSerializationTests.cs +++ /dev/null @@ -1,77 +0,0 @@ -// Copyright (c) Umbraco. -// See LICENSE for more details. - -using System.Collections.Generic; -using System.Linq; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; -using NUnit.Framework; -using Umbraco.Cms.Core.Models.ContentEditing; -using Umbraco.Extensions; - -namespace Umbraco.Cms.Tests.UnitTests.Umbraco.Web.Common.AngularIntegration; - -[TestFixture] -public class ContentModelSerializationTests -{ - [Test] - public void Content_Display_To_Json() - { - // create 3 tabs with 3 properties each - var tabs = new List>(); - for (var tabIndex = 0; tabIndex < 3; tabIndex++) - { - var props = new List(); - for (var propertyIndex = 0; propertyIndex < 3; propertyIndex++) - { - props.Add(new ContentPropertyDisplay - { - Alias = "property" + propertyIndex, - Label = "Property " + propertyIndex, - Id = propertyIndex, - Value = "value" + propertyIndex, - Config = new Dictionary { { propertyIndex.ToInvariantString(), "value" } }, - Description = "Description " + propertyIndex, - }); - } - - tabs.Add(new Tab - { - Alias = "Tab" + tabIndex, - Label = "Tab" + tabIndex, - Properties = props, - }); - } - - var displayModel = new ContentItemDisplay - { - Id = 1234, - Variants = new List { new() { Name = "Test", Tabs = tabs } }, - }; - - var json = JsonConvert.SerializeObject(displayModel); - - var jObject = JObject.Parse(json); - - Assert.AreEqual("1234", jObject["id"].ToString()); - Assert.AreEqual("Test", jObject["variants"][0]["name"].ToString()); - - var jsonTabs = jObject["variants"][0]["tabs"]; - Assert.AreEqual(3, jsonTabs.Count()); - for (var tab = 0; tab < jsonTabs.Count(); tab++) - { - Assert.AreEqual("Tab" + tab, jsonTabs[tab]["alias"].ToString()); - Assert.AreEqual("Tab" + tab, jsonTabs[tab]["label"].ToString()); - Assert.AreEqual(3, jsonTabs[tab]["properties"].Count()); - for (var prop = 0; prop < jsonTabs[tab]["properties"].Count(); prop++) - { - Assert.AreEqual("property" + prop, jsonTabs[tab]["properties"][prop]["alias"].ToString()); - Assert.AreEqual("Property " + prop, jsonTabs[tab]["properties"][prop]["label"].ToString()); - Assert.AreEqual(prop, jsonTabs[tab]["properties"][prop]["id"].Value()); - Assert.AreEqual("value" + prop, jsonTabs[tab]["properties"][prop]["value"].ToString()); - Assert.AreEqual("{\"" + prop + "\":\"value\"}", jsonTabs[tab]["properties"][prop]["config"].ToString(Formatting.None)); - Assert.AreEqual("Description " + prop, jsonTabs[tab]["properties"][prop]["description"].ToString()); - } - } - } -}