From 7315f619456fe482f2477453778d8f9b961e036a Mon Sep 17 00:00:00 2001 From: Kevin Jump Date: Wed, 17 Apr 2024 12:42:35 +0100 Subject: [PATCH] From v13: Add serializers and handlers for webhooks. (#613) --- uSync.BackOffice/BackOfficeConstants.cs | 486 +++++++++--------- .../SyncHandlers/Handlers/WebhookHandler.cs | 9 +- .../uSyncBackOfficeBuilderExtensions.cs | 4 +- .../Serializers/WebhookSerializer.cs | 6 +- uSync.Core/uSyncConstants.cs | 238 ++++----- 5 files changed, 372 insertions(+), 371 deletions(-) diff --git a/uSync.BackOffice/BackOfficeConstants.cs b/uSync.BackOffice/BackOfficeConstants.cs index 5a8b5923..f0b41bb6 100644 --- a/uSync.BackOffice/BackOfficeConstants.cs +++ b/uSync.BackOffice/BackOfficeConstants.cs @@ -7,247 +7,247 @@ namespace uSync.BackOffice; /// public static partial class uSyncConstants { - /// - /// Information about the package name/files - /// - public static class Package - { - /// - /// Name of the Package - /// - public const string Name = "uSync"; - - /// - /// Virtual path to the plugin files - /// - public const string PluginPath = "/App_Plugins/uSync"; - } - - /// - /// Suffix to place on any release strings - /// - public const string ReleaseSuffix = ""; - - /// - /// ordering of the handler items (what gets done when) - /// - public static class Priorites - { - /// - /// Lower bound of uSync's reserved priority range - /// - public const int USYNC_RESERVED_LOWER = 1000; - - /// - /// Upper bound of uSync's reserved priority range - /// - public const int USYNC_RESERVED_UPPER = 2000; - - /// - /// DataTypes priority - /// - public const int DataTypes = USYNC_RESERVED_LOWER + 10; - - /// - /// Templates priority - /// - public const int Templates = USYNC_RESERVED_LOWER + 20; - - /// - /// ContentTypes priority - /// - public const int ContentTypes = USYNC_RESERVED_LOWER + 30; - - /// - /// MediaTypes priority - /// - public const int MediaTypes = USYNC_RESERVED_LOWER + 40; - - /// - /// MemberTypes priority - /// - public const int MemberTypes = USYNC_RESERVED_LOWER + 45; - - /// - /// Languages priority - /// - public const int Languages = USYNC_RESERVED_LOWER + 5; - - /// - /// DictionaryItems priority - /// - public const int DictionaryItems = USYNC_RESERVED_LOWER + 6; - - /// - /// Macros priority - /// - public const int Macros = USYNC_RESERVED_LOWER + 70; - - /// - /// Media priority - /// - public const int Media = USYNC_RESERVED_LOWER + 200; - - /// - /// Content priority - /// - public const int Content = USYNC_RESERVED_LOWER + 210; - - /// - /// ContentTemplate priority - /// - public const int ContentTemplate = USYNC_RESERVED_LOWER + 215; - - /// - /// DomainSettings priority - /// - public const int DomainSettings = USYNC_RESERVED_LOWER + 219; - - /// - /// DataTypeMappings priority - /// - public const int DataTypeMappings = USYNC_RESERVED_LOWER + 220; - - /// - /// RelationTypes priority - /// - public const int RelationTypes = USYNC_RESERVED_LOWER + 230; - - /// - /// Webhooks priority. - /// - public const int Webhooks = USYNC_RESERVED_LOWER + 250; - } - - /// - /// Default group names - /// - public static class Groups - { - /// - /// Name for the settings group of handlers - /// - public const string Settings = "Settings"; - - /// - /// Name for the Content group of handlers - /// - public const string Content = "Content"; - - /// - /// Name for the Members group of handlers - /// - public const string Members = "Members"; - - /// - /// Name for the > group of handlers - /// - public const string Users = "Users"; - - /// - /// Name for the Forms group of handlers - /// - public const string Forms = "Forms"; - - /// - /// Name for the Files group of handlers - /// - public const string Files = "Files"; - - /// - /// Name for the default group (used for loading default global config) - /// - public const string Default = "__default__"; - - /// - /// Icons for the well known handler groups. - /// - public static Dictionary Icons = new Dictionary { - { Settings, "icon-settings-alt color-blue" }, - { Content, "icon-documents color-purple" }, - { Members, "icon-users" }, - { Users, "icon-users color-green"}, - { Default, "icon-settings" }, - { Forms, "icon-umb-contour" }, - { Files, "icon-script-alt" } - }; - } - - /// - /// names of the well know handlers - /// - public static class Handlers - { - /// - /// ContentHandler Name - /// - public const string ContentHandler = "ContentHandler"; - - /// - /// ContentTemplateHandler Name - /// - public const string ContentTemplateHandler = "ContentTemplateHandler"; - - /// - /// ContentTypeHandler Name - /// - public const string ContentTypeHandler = "ContentTypeHandler"; - - /// - /// DataTypeHandler Name - /// - public const string DataTypeHandler = "DataTypeHandler"; - - /// - /// DictionaryHandler Name - /// - public const string DictionaryHandler = "DictionaryHandler"; - - /// - /// DomainHandler Name - /// - public const string DomainHandler = "DomainHandler"; - - /// - /// LanguageHandler Name - /// - public const string LanguageHandler = "LanguageHandler"; - - /// - /// MacroHandler Name - /// - public const string MacroHandler = "MacroHandler"; - - /// - /// MediaHandler Name - /// - public const string MediaHandler = "MediaHandler"; - - /// - /// MediaTypeHandler Name - /// - public const string MediaTypeHandler = "MediaTypeHandler"; - - /// - /// MemberTypeHandler Name - /// - public const string MemberTypeHandler = "MemberTypeHandler"; - - /// - /// RelationTypeHandler Name - /// - public const string RelationTypeHandler = "RelationTypeHandler"; - - /// - /// TemplateHandler Name - /// - public const string TemplateHandler = "TemplateHandler"; - - /// - /// WebhooksHandler name - /// - public const string WebhookHandler = "WebhookHandler"; - - - } + /// + /// Information about the package name/files + /// + public static class Package + { + /// + /// Name of the Package + /// + public const string Name = "uSync"; + + /// + /// Virtual path to the plugin files + /// + public const string PluginPath = "/App_Plugins/uSync"; + } + + /// + /// Suffix to place on any release strings + /// + public const string ReleaseSuffix = ""; + + /// + /// ordering of the handler items (what gets done when) + /// + public static class Priorites + { + /// + /// Lower bound of uSync's reserved priority range + /// + public const int USYNC_RESERVED_LOWER = 1000; + + /// + /// Upper bound of uSync's reserved priority range + /// + public const int USYNC_RESERVED_UPPER = 2000; + + /// + /// DataTypes priority + /// + public const int DataTypes = USYNC_RESERVED_LOWER + 10; + + /// + /// Templates priority + /// + public const int Templates = USYNC_RESERVED_LOWER + 20; + + /// + /// ContentTypes priority + /// + public const int ContentTypes = USYNC_RESERVED_LOWER + 30; + + /// + /// MediaTypes priority + /// + public const int MediaTypes = USYNC_RESERVED_LOWER + 40; + + /// + /// MemberTypes priority + /// + public const int MemberTypes = USYNC_RESERVED_LOWER + 45; + + /// + /// Languages priority + /// + public const int Languages = USYNC_RESERVED_LOWER + 5; + + /// + /// DictionaryItems priority + /// + public const int DictionaryItems = USYNC_RESERVED_LOWER + 6; + + /// + /// Macros priority + /// + public const int Macros = USYNC_RESERVED_LOWER + 70; + + /// + /// Media priority + /// + public const int Media = USYNC_RESERVED_LOWER + 200; + + /// + /// Content priority + /// + public const int Content = USYNC_RESERVED_LOWER + 210; + + /// + /// ContentTemplate priority + /// + public const int ContentTemplate = USYNC_RESERVED_LOWER + 215; + + /// + /// DomainSettings priority + /// + public const int DomainSettings = USYNC_RESERVED_LOWER + 219; + + /// + /// DataTypeMappings priority + /// + public const int DataTypeMappings = USYNC_RESERVED_LOWER + 220; + + /// + /// RelationTypes priority + /// + public const int RelationTypes = USYNC_RESERVED_LOWER + 230; + + /// + /// Webhooks priority. + /// + public const int Webhooks = USYNC_RESERVED_LOWER + 250; + } + + /// + /// Default group names + /// + public static class Groups + { + /// + /// Name for the settings group of handlers + /// + public const string Settings = "Settings"; + + /// + /// Name for the Content group of handlers + /// + public const string Content = "Content"; + + /// + /// Name for the Members group of handlers + /// + public const string Members = "Members"; + + /// + /// Name for the > group of handlers + /// + public const string Users = "Users"; + + /// + /// Name for the Forms group of handlers + /// + public const string Forms = "Forms"; + + /// + /// Name for the Files group of handlers + /// + public const string Files = "Files"; + + /// + /// Name for the default group (used for loading default global config) + /// + public const string Default = "__default__"; + + /// + /// Icons for the well known handler groups. + /// + public static Dictionary Icons = new Dictionary { + { Settings, "icon-settings-alt color-blue" }, + { Content, "icon-documents color-purple" }, + { Members, "icon-users" }, + { Users, "icon-users color-green"}, + { Default, "icon-settings" }, + { Forms, "icon-umb-contour" }, + { Files, "icon-script-alt" } + }; + } + + /// + /// names of the well know handlers + /// + public static class Handlers + { + /// + /// ContentHandler Name + /// + public const string ContentHandler = "ContentHandler"; + + /// + /// ContentTemplateHandler Name + /// + public const string ContentTemplateHandler = "ContentTemplateHandler"; + + /// + /// ContentTypeHandler Name + /// + public const string ContentTypeHandler = "ContentTypeHandler"; + + /// + /// DataTypeHandler Name + /// + public const string DataTypeHandler = "DataTypeHandler"; + + /// + /// DictionaryHandler Name + /// + public const string DictionaryHandler = "DictionaryHandler"; + + /// + /// DomainHandler Name + /// + public const string DomainHandler = "DomainHandler"; + + /// + /// LanguageHandler Name + /// + public const string LanguageHandler = "LanguageHandler"; + + /// + /// MacroHandler Name + /// + public const string MacroHandler = "MacroHandler"; + + /// + /// MediaHandler Name + /// + public const string MediaHandler = "MediaHandler"; + + /// + /// MediaTypeHandler Name + /// + public const string MediaTypeHandler = "MediaTypeHandler"; + + /// + /// MemberTypeHandler Name + /// + public const string MemberTypeHandler = "MemberTypeHandler"; + + /// + /// RelationTypeHandler Name + /// + public const string RelationTypeHandler = "RelationTypeHandler"; + + /// + /// TemplateHandler Name + /// + public const string TemplateHandler = "TemplateHandler"; + + /// + /// WebhooksHandler name + /// + public const string WebhookHandler = "WebhookHandler"; + + + } } diff --git a/uSync.BackOffice/SyncHandlers/Handlers/WebhookHandler.cs b/uSync.BackOffice/SyncHandlers/Handlers/WebhookHandler.cs index ce90a3f7..0e96a401 100644 --- a/uSync.BackOffice/SyncHandlers/Handlers/WebhookHandler.cs +++ b/uSync.BackOffice/SyncHandlers/Handlers/WebhookHandler.cs @@ -61,8 +61,9 @@ protected override IEnumerable DeleteMissingItems(IWebhook parent, return []; } + /// - protected override IEnumerable GetChildItems(IWebhook parent) + protected override IEnumerable GetChildItems(IWebhook? parent) { if (parent == null) { @@ -73,11 +74,11 @@ protected override IEnumerable GetChildItems(IWebhook parent) } /// - protected override IEnumerable GetFolders(IWebhook parent) => []; + protected override IEnumerable GetFolders(IWebhook? parent) => []; /// - protected override IWebhook GetFromService(IWebhook item) - => _webhookService.GetAsync(item.Key).Result; + protected override IWebhook? GetFromService(IWebhook? item) + => item is null ? null : _webhookService.GetAsync(item.Key).Result; /// protected override string GetItemName(IWebhook item) => item.Key.ToString(); diff --git a/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs b/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs index e3c10542..dff53518 100644 --- a/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs +++ b/uSync.BackOffice/uSyncBackOfficeBuilderExtensions.cs @@ -160,8 +160,8 @@ internal static void AddHandlerNotifications(this IUmbracoBuilder builder) builder.AddNotificationHandler(); builder.AddNotificationHandler(); - builder.AddNotificationHandler(); - builder.AddNotificationHandler(); + builder.AddNotificationHandler(); + builder.AddNotificationHandler(); // roots - pre-notifications for stopping things builder diff --git a/uSync.Core/Serialization/Serializers/WebhookSerializer.cs b/uSync.Core/Serialization/Serializers/WebhookSerializer.cs index 55c6174b..85f97dca 100644 --- a/uSync.Core/Serialization/Serializers/WebhookSerializer.cs +++ b/uSync.Core/Serialization/Serializers/WebhookSerializer.cs @@ -36,14 +36,14 @@ public override void DeleteItem(IWebhook item) } /// - public override IWebhook FindItem(int id) => null; + public override IWebhook? FindItem(int id) => null; /// - public override IWebhook FindItem(Guid key) + public override IWebhook? FindItem(Guid key) => _webhookService.GetAsync(key).Result; /// - public override IWebhook FindItem(string alias) + public override IWebhook? FindItem(string alias) { if (Guid.TryParse(alias, out Guid key)) return FindItem(key); diff --git a/uSync.Core/uSyncConstants.cs b/uSync.Core/uSyncConstants.cs index 36b42edd..b7bd9e0f 100644 --- a/uSync.Core/uSyncConstants.cs +++ b/uSync.Core/uSyncConstants.cs @@ -2,123 +2,123 @@ public static partial class uSyncConstants { - public static class Xml - { - public const string Key = "Key"; - public const string Alias = "Alias"; - public const string Level = "Level"; - public const string Change = "Change"; - - public const string Parent = "Parent"; - public const string Path = "Path"; + public static class Xml + { + public const string Key = "Key"; + public const string Alias = "Alias"; + public const string Level = "Level"; + public const string Change = "Change"; + + public const string Parent = "Parent"; + public const string Path = "Path"; - public const string Info = "Info"; - public const string Name = "Name"; - - public const string SortOrder = "SortOrder"; - - public const string ItemType = "itemType"; - - public const string Template = "Template"; - - } - - // this is our format 'version' - - // it only changes when the format of the .config files change - // we use it to prompt people to do an uptodate export. - public const string FormatVersion = "10.7.0"; - - /// - /// names of the root xml elements that are seralized in/out - /// - public static class Serialization - { - public const string ContentType = "ContentType"; - public const string MediaType = "MediaType"; - public const string DataType = "DataType"; - public const string MemberType = "MemberType"; - public const string Template = "Template"; - public const string Macro = "Macro"; - public const string Language = "Language"; - - public const string Dictionary = "Dictionary"; - public const string Content = "Content"; - public const string Media = "Media"; - public const string Users = "Users"; - public const string Members = "Members"; - - public const string Domain = "Domain"; - - public const string Empty = "Empty"; - - public const string RelationType = "RelationType"; - public const string Relation = "Relation"; - - public const string Webhook = "Webhook"; - } - - /// - /// Key used in settings and xml to indicate only partial cultures are included in file - /// - public const string CultureKey = "Cultures"; - - /// - /// Key used in settings and in xml to indicate only partial segments are included in file - /// - public const string SegmentKey = "Segments"; - - /// - /// Key used in settings and in xml to indicate if partial file also includes fallback values. - /// - public const string DefaultsKey = "DefaultValues"; - - - /// - /// constant values for default settings in handlers/serializers. - /// - /// - /// these are checked within the serializers if the config is not present the default values - /// are used. - /// - public static class DefaultSettings - { - // don't remove properties or items (e.g no delete) - public const string NoRemove = "NoRemove"; - public const bool NoRemove_Default = false; - - // only create new items (existing items are not touched) - public const string CreateOnly = "CreateOnly"; - public const string OneWay = "OneWay"; // legacy config name - public const bool CreateOnly_Default = false; - - // new properties only (so existing properties are left) - public const string NewPropertiesOnly = "NewPropertiesOnly"; - public const bool NewPropertiesOnly_Default = false; - - // only publish content when we thing it is dirty - public const string OnlyPublishDirty = "OnlyPublishDirty"; - public const bool OnlyPublishDirty_Default = false; - - // editors we don't want the config importing for. - public const string NoConfigEditors = "NoConfigEditors"; - public const string NoConfigEditors_Default = ""; - - // item names we don't want the config importing for. - public const string NoConfigNames = "NoConfigNames"; - public const string NoConfigNames_Default = ""; - - } + public const string Info = "Info"; + public const string Name = "Name"; + + public const string SortOrder = "SortOrder"; + + public const string ItemType = "itemType"; + + public const string Template = "Template"; + + } + + // this is our format 'version' - + // it only changes when the format of the .config files change + // we use it to prompt people to do an uptodate export. + public const string FormatVersion = "10.7.0"; + + /// + /// names of the root xml elements that are seralized in/out + /// + public static class Serialization + { + public const string ContentType = "ContentType"; + public const string MediaType = "MediaType"; + public const string DataType = "DataType"; + public const string MemberType = "MemberType"; + public const string Template = "Template"; + public const string Macro = "Macro"; + public const string Language = "Language"; + + public const string Dictionary = "Dictionary"; + public const string Content = "Content"; + public const string Media = "Media"; + public const string Users = "Users"; + public const string Members = "Members"; + + public const string Domain = "Domain"; + + public const string Empty = "Empty"; + + public const string RelationType = "RelationType"; + public const string Relation = "Relation"; + + public const string Webhook = "Webhook"; + } + + /// + /// Key used in settings and xml to indicate only partial cultures are included in file + /// + public const string CultureKey = "Cultures"; + + /// + /// Key used in settings and in xml to indicate only partial segments are included in file + /// + public const string SegmentKey = "Segments"; + + /// + /// Key used in settings and in xml to indicate if partial file also includes fallback values. + /// + public const string DefaultsKey = "DefaultValues"; + + + /// + /// constant values for default settings in handlers/serializers. + /// + /// + /// these are checked within the serializers if the config is not present the default values + /// are used. + /// + public static class DefaultSettings + { + // don't remove properties or items (e.g no delete) + public const string NoRemove = "NoRemove"; + public const bool NoRemove_Default = false; + + // only create new items (existing items are not touched) + public const string CreateOnly = "CreateOnly"; + public const string OneWay = "OneWay"; // legacy config name + public const bool CreateOnly_Default = false; + + // new properties only (so existing properties are left) + public const string NewPropertiesOnly = "NewPropertiesOnly"; + public const bool NewPropertiesOnly_Default = false; + + // only publish content when we thing it is dirty + public const string OnlyPublishDirty = "OnlyPublishDirty"; + public const bool OnlyPublishDirty_Default = false; + + // editors we don't want the config importing for. + public const string NoConfigEditors = "NoConfigEditors"; + public const string NoConfigEditors_Default = ""; + + // item names we don't want the config importing for. + public const string NoConfigNames = "NoConfigNames"; + public const string NoConfigNames_Default = ""; + + } - public const int DependencyCountMax = 204800; - - - public static class Conventions - { - /// - /// setting to tell a serializer to include the file content in anything it is sending over. - /// - public const string IncludeContent = "IncludeContent"; - } + public const int DependencyCountMax = 204800; + + + public static class Conventions + { + /// + /// setting to tell a serializer to include the file content in anything it is sending over. + /// + public const string IncludeContent = "IncludeContent"; + } } /// @@ -129,8 +129,8 @@ public static class Conventions /// public static class SyncLegacyTypes { - public const string NestedContent = "Umbraco.NestedContent"; - public const string OurNestedContent = "Our.Umbraco.NestedContent"; - public const string Grid = "Umbraco.Grid"; - public const string MediaPicker = "Umbraco.MediaPicker"; + public const string NestedContent = "Umbraco.NestedContent"; + public const string OurNestedContent = "Our.Umbraco.NestedContent"; + public const string Grid = "Umbraco.Grid"; + public const string MediaPicker = "Umbraco.MediaPicker"; }