From 83e9468502cc69b9d1bc14477abaecf285976cb4 Mon Sep 17 00:00:00 2001 From: Chad Scharf <3904944+cscharf@users.noreply.github.com> Date: Mon, 20 Jul 2020 15:19:46 -0400 Subject: [PATCH] Transition reference id to data (#828) * Transition reference id to data * field length and request model updates --- .../Request/Accounts/RegisterRequestModel.cs | 10 +- src/Core/Models/Business/ReferenceEvent.cs | 4 +- .../Models/Business/ReferenceEventData.cs | 16 + src/Core/Models/Table/IReferenceable.cs | 2 +- src/Core/Models/Table/Organization.cs | 2 +- src/Core/Models/Table/User.cs | 2 +- .../AzureQueueReferenceEventService.cs | 4 +- .../Implementations/OrganizationService.cs | 4 +- .../Stored Procedures/Organization_Create.sql | 6 +- .../Stored Procedures/Organization_Update.sql | 4 +- src/Sql/dbo/Stored Procedures/User_Create.sql | 6 +- src/Sql/dbo/Stored Procedures/User_Update.sql | 4 +- src/Sql/dbo/Tables/Organization.sql | 2 +- src/Sql/dbo/Tables/User.sql | 2 +- .../DbScripts/2020-07-17_00_ReferenceData.sql | 465 ++++++++++++++++++ 15 files changed, 510 insertions(+), 23 deletions(-) create mode 100644 src/Core/Models/Business/ReferenceEventData.cs create mode 100644 util/Migrator/DbScripts/2020-07-17_00_ReferenceData.sql diff --git a/src/Core/Models/Api/Request/Accounts/RegisterRequestModel.cs b/src/Core/Models/Api/Request/Accounts/RegisterRequestModel.cs index b9b8ac9b7..c93c4c548 100644 --- a/src/Core/Models/Api/Request/Accounts/RegisterRequestModel.cs +++ b/src/Core/Models/Api/Request/Accounts/RegisterRequestModel.cs @@ -2,7 +2,9 @@ using System.Collections.Generic; using System.ComponentModel.DataAnnotations; using Bit.Core.Enums; +using Bit.Core.Models.Business; using Bit.Core.Models.Table; +using Newtonsoft.Json; namespace Bit.Core.Models.Api { @@ -25,7 +27,7 @@ namespace Bit.Core.Models.Api public Guid? OrganizationUserId { get; set; } public KdfType? Kdf { get; set; } public int? KdfIterations { get; set; } - public string ReferenceId { get; set; } + public Dictionary ReferenceData { get; set; } public User ToUser() { @@ -36,9 +38,13 @@ namespace Bit.Core.Models.Api MasterPasswordHint = MasterPasswordHint, Kdf = Kdf.GetValueOrDefault(KdfType.PBKDF2_SHA256), KdfIterations = KdfIterations.GetValueOrDefault(5000), - ReferenceId = ReferenceId, }; + if (ReferenceData != null) + { + user.ReferenceData = JsonConvert.SerializeObject(ReferenceData); + } + if (Key != null) { user.Key = Key; diff --git a/src/Core/Models/Business/ReferenceEvent.cs b/src/Core/Models/Business/ReferenceEvent.cs index 83e44cc64..14b8de6c5 100644 --- a/src/Core/Models/Business/ReferenceEvent.cs +++ b/src/Core/Models/Business/ReferenceEvent.cs @@ -18,7 +18,7 @@ namespace Bit.Core.Models.Business { Source = source.IsUser() ? ReferenceEventSource.User : ReferenceEventSource.Organization; Id = source.Id; - ReferenceId = source.ReferenceId; + ReferenceData = source.ReferenceData; } } @@ -30,7 +30,7 @@ namespace Bit.Core.Models.Business public Guid Id { get; set; } - public string ReferenceId { get; set; } + public string ReferenceData { get; set; } public DateTime EventDate { get; set; } = DateTime.UtcNow; diff --git a/src/Core/Models/Business/ReferenceEventData.cs b/src/Core/Models/Business/ReferenceEventData.cs new file mode 100644 index 000000000..5a8d5a92b --- /dev/null +++ b/src/Core/Models/Business/ReferenceEventData.cs @@ -0,0 +1,16 @@ +using System; +using Newtonsoft.Json; +using Newtonsoft.Json.Serialization; + +namespace Bit.Core.Models.Business +{ + [JsonObject(NamingStrategyType = typeof(CamelCaseNamingStrategy))] + public class ReferenceEventData + { + public string Id { get; set; } + + public string Layout { get; set; } + + public string Flow { get; set; } + } +} diff --git a/src/Core/Models/Table/IReferenceable.cs b/src/Core/Models/Table/IReferenceable.cs index e412c9b52..d207a7a7b 100644 --- a/src/Core/Models/Table/IReferenceable.cs +++ b/src/Core/Models/Table/IReferenceable.cs @@ -5,7 +5,7 @@ namespace Bit.Core.Models public interface IReferenceable { Guid Id { get; set; } - string ReferenceId { get; set; } + string ReferenceData { get; set; } bool IsUser(); } } diff --git a/src/Core/Models/Table/Organization.cs b/src/Core/Models/Table/Organization.cs index 57843ddb5..75b8c380b 100644 --- a/src/Core/Models/Table/Organization.cs +++ b/src/Core/Models/Table/Organization.cs @@ -39,7 +39,7 @@ namespace Bit.Core.Models.Table public GatewayType? Gateway { get; set; } public string GatewayCustomerId { get; set; } public string GatewaySubscriptionId { get; set; } - public string ReferenceId { get; set; } + public string ReferenceData { get; set; } public bool Enabled { get; set; } = true; public string LicenseKey { get; set; } public string ApiKey { get; set; } diff --git a/src/Core/Models/Table/User.cs b/src/Core/Models/Table/User.cs index e53731513..85417adab 100644 --- a/src/Core/Models/Table/User.cs +++ b/src/Core/Models/Table/User.cs @@ -37,7 +37,7 @@ namespace Bit.Core.Models.Table public GatewayType? Gateway { get; set; } public string GatewayCustomerId { get; set; } public string GatewaySubscriptionId { get; set; } - public string ReferenceId { get; set; } + public string ReferenceData { get; set; } public string LicenseKey { get; set; } public KdfType Kdf { get; set; } = KdfType.PBKDF2_SHA256; public int KdfIterations { get; set; } = 5000; diff --git a/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs b/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs index 13d3c6626..a99552b21 100644 --- a/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs +++ b/src/Core/Services/Implementations/AzureQueueReferenceEventService.cs @@ -30,9 +30,9 @@ namespace Bit.Core.Services private async Task SendMessageAsync(ReferenceEvent referenceEvent) { - if (_globalSettings.SelfHosted || string.IsNullOrWhiteSpace(referenceEvent.ReferenceId)) + if (_globalSettings.SelfHosted) { - // Ignore for self-hosted, OR, where there is no ReferenceId + // Ignore for self-hosted return; } try diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index 749b4d6da..8ec6703de 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -514,7 +514,7 @@ namespace Bit.Core.Services UsersGetPremium = plan.UsersGetPremium || signup.PremiumAccessAddon, Plan = plan.Name, Gateway = null, - ReferenceId = signup.Owner.ReferenceId, + ReferenceData = signup.Owner.ReferenceData, Enabled = true, LicenseKey = CoreHelpers.SecureRandomString(20), ApiKey = CoreHelpers.SecureRandomString(30), @@ -598,7 +598,7 @@ namespace Bit.Core.Services Gateway = null, GatewayCustomerId = null, GatewaySubscriptionId = null, - ReferenceId = owner.ReferenceId, + ReferenceData = owner.ReferenceData, Enabled = license.Enabled, ExpirationDate = license.Expires, LicenseKey = license.LicenseKey, diff --git a/src/Sql/dbo/Stored Procedures/Organization_Create.sql b/src/Sql/dbo/Stored Procedures/Organization_Create.sql index 1e6290522..78530541a 100644 --- a/src/Sql/dbo/Stored Procedures/Organization_Create.sql +++ b/src/Sql/dbo/Stored Procedures/Organization_Create.sql @@ -27,7 +27,7 @@ @Gateway TINYINT, @GatewayCustomerId VARCHAR(50), @GatewaySubscriptionId VARCHAR(50), - @ReferenceId VARCHAR(50), + @ReferenceData VARCHAR(MAX), @Enabled BIT, @LicenseKey VARCHAR(100), @ApiKey VARCHAR(30), @@ -69,7 +69,7 @@ BEGIN [Gateway], [GatewayCustomerId], [GatewaySubscriptionId], - [ReferenceId], + [ReferenceData], [Enabled], [LicenseKey], [ApiKey], @@ -108,7 +108,7 @@ BEGIN @Gateway, @GatewayCustomerId, @GatewaySubscriptionId, - @ReferenceId, + @ReferenceData, @Enabled, @LicenseKey, @ApiKey, diff --git a/src/Sql/dbo/Stored Procedures/Organization_Update.sql b/src/Sql/dbo/Stored Procedures/Organization_Update.sql index f32b5c06b..ba3e53bdc 100644 --- a/src/Sql/dbo/Stored Procedures/Organization_Update.sql +++ b/src/Sql/dbo/Stored Procedures/Organization_Update.sql @@ -27,7 +27,7 @@ @Gateway TINYINT, @GatewayCustomerId VARCHAR(50), @GatewaySubscriptionId VARCHAR(50), - @ReferenceId VARCHAR(50), + @ReferenceData VARCHAR(MAX), @Enabled BIT, @LicenseKey VARCHAR(100), @ApiKey VARCHAR(30), @@ -69,7 +69,7 @@ BEGIN [Gateway] = @Gateway, [GatewayCustomerId] = @GatewayCustomerId, [GatewaySubscriptionId] = @GatewaySubscriptionId, - [ReferenceId] = @ReferenceId, + [ReferenceData] = @ReferenceData, [Enabled] = @Enabled, [LicenseKey] = @LicenseKey, [ApiKey] = @ApiKey, diff --git a/src/Sql/dbo/Stored Procedures/User_Create.sql b/src/Sql/dbo/Stored Procedures/User_Create.sql index 9f18af7dd..07f75516d 100644 --- a/src/Sql/dbo/Stored Procedures/User_Create.sql +++ b/src/Sql/dbo/Stored Procedures/User_Create.sql @@ -23,7 +23,7 @@ @Gateway TINYINT, @GatewayCustomerId VARCHAR(50), @GatewaySubscriptionId VARCHAR(50), - @ReferenceId VARCHAR(50), + @ReferenceData VARCHAR(MAX), @LicenseKey VARCHAR(100), @Kdf TINYINT, @KdfIterations INT, @@ -59,7 +59,7 @@ BEGIN [Gateway], [GatewayCustomerId], [GatewaySubscriptionId], - [ReferenceId], + [ReferenceData], [LicenseKey], [Kdf], [KdfIterations], @@ -92,7 +92,7 @@ BEGIN @Gateway, @GatewayCustomerId, @GatewaySubscriptionId, - @ReferenceId, + @ReferenceData, @LicenseKey, @Kdf, @KdfIterations, diff --git a/src/Sql/dbo/Stored Procedures/User_Update.sql b/src/Sql/dbo/Stored Procedures/User_Update.sql index 53bbd7df2..d484cf0ce 100644 --- a/src/Sql/dbo/Stored Procedures/User_Update.sql +++ b/src/Sql/dbo/Stored Procedures/User_Update.sql @@ -23,7 +23,7 @@ @Gateway TINYINT, @GatewayCustomerId VARCHAR(50), @GatewaySubscriptionId VARCHAR(50), - @ReferenceId VARCHAR(50), + @ReferenceData VARCHAR(MAX), @LicenseKey VARCHAR(100), @Kdf TINYINT, @KdfIterations INT, @@ -59,7 +59,7 @@ BEGIN [Gateway] = @Gateway, [GatewayCustomerId] = @GatewayCustomerId, [GatewaySubscriptionId] = @GatewaySubscriptionId, - [ReferenceId] = @ReferenceId, + [ReferenceData] = @ReferenceData, [LicenseKey] = @LicenseKey, [Kdf] = @Kdf, [KdfIterations] = @KdfIterations, diff --git a/src/Sql/dbo/Tables/Organization.sql b/src/Sql/dbo/Tables/Organization.sql index 1fce250b6..8432e8afc 100644 --- a/src/Sql/dbo/Tables/Organization.sql +++ b/src/Sql/dbo/Tables/Organization.sql @@ -27,7 +27,7 @@ [Gateway] TINYINT NULL, [GatewayCustomerId] VARCHAR (50) NULL, [GatewaySubscriptionId] VARCHAR (50) NULL, - [ReferenceId] NVARCHAR (50) NULL, + [ReferenceData] NVARCHAR (MAX) NULL, [Enabled] BIT NOT NULL, [LicenseKey] VARCHAR (100) NULL, [ApiKey] VARCHAR (30) NOT NULL, diff --git a/src/Sql/dbo/Tables/User.sql b/src/Sql/dbo/Tables/User.sql index e3ee5f660..f967b9dc2 100644 --- a/src/Sql/dbo/Tables/User.sql +++ b/src/Sql/dbo/Tables/User.sql @@ -23,7 +23,7 @@ [Gateway] TINYINT NULL, [GatewayCustomerId] VARCHAR (50) NULL, [GatewaySubscriptionId] VARCHAR (50) NULL, - [ReferenceId] NVARCHAR (50) NULL, + [ReferenceData] NVARCHAR (MAX) NULL, [LicenseKey] VARCHAR (100) NULL, [Kdf] TINYINT NOT NULL, [KdfIterations] INT NOT NULL, diff --git a/util/Migrator/DbScripts/2020-07-17_00_ReferenceData.sql b/util/Migrator/DbScripts/2020-07-17_00_ReferenceData.sql new file mode 100644 index 000000000..717f57185 --- /dev/null +++ b/util/Migrator/DbScripts/2020-07-17_00_ReferenceData.sql @@ -0,0 +1,465 @@ +IF COL_LENGTH('[dbo].[User]', 'ReferenceId') IS NOT NULL +BEGIN + ALTER TABLE [dbo].[User] + DROP COLUMN [ReferenceId]; +END +GO + +IF COL_LENGTH('[dbo].[Organization]', 'ReferenceId') IS NOT NULL +BEGIN + ALTER TABLE [dbo].[Organization] + DROP COLUMN [ReferenceId]; +END +GO + +IF COL_LENGTH('[dbo].[User]', 'ReferenceData') IS NULL +BEGIN + ALTER TABLE + [dbo].[User] + ADD + [ReferenceData] NVARCHAR (MAX) NULL; +END +GO + +IF COL_LENGTH('[dbo].[Organization]', 'ReferenceData') IS NULL +BEGIN + ALTER TABLE + [dbo].[Organization] + ADD + [ReferenceData] NVARCHAR (MAX) NULL; +END +GO + +IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'UserView') +BEGIN + DROP VIEW [dbo].[UserView]; +END +GO + +CREATE VIEW [dbo].[UserView] +AS +SELECT + * +FROM + [dbo].[User] +GO + +IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'OrganizationView') +BEGIN + DROP VIEW [dbo].[OrganizationView]; +END +GO + +CREATE VIEW [dbo].[OrganizationView] +AS +SELECT + * +FROM + [dbo].[Organization] +GO + +IF OBJECT_ID('[dbo].[User_Create]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_Create] +END +GO + +CREATE PROCEDURE [dbo].[User_Create] + @Id UNIQUEIDENTIFIER, + @Name NVARCHAR(50), + @Email NVARCHAR(50), + @EmailVerified BIT, + @MasterPassword NVARCHAR(300), + @MasterPasswordHint NVARCHAR(50), + @Culture NVARCHAR(10), + @SecurityStamp NVARCHAR(50), + @TwoFactorProviders NVARCHAR(MAX), + @TwoFactorRecoveryCode NVARCHAR(32), + @EquivalentDomains NVARCHAR(MAX), + @ExcludedGlobalEquivalentDomains NVARCHAR(MAX), + @AccountRevisionDate DATETIME2(7), + @Key NVARCHAR(MAX), + @PublicKey NVARCHAR(MAX), + @PrivateKey NVARCHAR(MAX), + @Premium BIT, + @PremiumExpirationDate DATETIME2(7), + @RenewalReminderDate DATETIME2(7), + @Storage BIGINT, + @MaxStorageGb SMALLINT, + @Gateway TINYINT, + @GatewayCustomerId VARCHAR(50), + @GatewaySubscriptionId VARCHAR(50), + @ReferenceData VARCHAR(MAX), + @LicenseKey VARCHAR(100), + @Kdf TINYINT, + @KdfIterations INT, + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + INSERT INTO [dbo].[User] + ( + [Id], + [Name], + [Email], + [EmailVerified], + [MasterPassword], + [MasterPasswordHint], + [Culture], + [SecurityStamp], + [TwoFactorProviders], + [TwoFactorRecoveryCode], + [EquivalentDomains], + [ExcludedGlobalEquivalentDomains], + [AccountRevisionDate], + [Key], + [PublicKey], + [PrivateKey], + [Premium], + [PremiumExpirationDate], + [RenewalReminderDate], + [Storage], + [MaxStorageGb], + [Gateway], + [GatewayCustomerId], + [GatewaySubscriptionId], + [ReferenceData], + [LicenseKey], + [Kdf], + [KdfIterations], + [CreationDate], + [RevisionDate] + ) + VALUES + ( + @Id, + @Name, + @Email, + @EmailVerified, + @MasterPassword, + @MasterPasswordHint, + @Culture, + @SecurityStamp, + @TwoFactorProviders, + @TwoFactorRecoveryCode, + @EquivalentDomains, + @ExcludedGlobalEquivalentDomains, + @AccountRevisionDate, + @Key, + @PublicKey, + @PrivateKey, + @Premium, + @PremiumExpirationDate, + @RenewalReminderDate, + @Storage, + @MaxStorageGb, + @Gateway, + @GatewayCustomerId, + @GatewaySubscriptionId, + @ReferenceData, + @LicenseKey, + @Kdf, + @KdfIterations, + @CreationDate, + @RevisionDate + ) +END +GO + +IF OBJECT_ID('[dbo].[User_Update]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[User_Update] +END +GO + +CREATE PROCEDURE [dbo].[User_Update] + @Id UNIQUEIDENTIFIER, + @Name NVARCHAR(50), + @Email NVARCHAR(50), + @EmailVerified BIT, + @MasterPassword NVARCHAR(300), + @MasterPasswordHint NVARCHAR(50), + @Culture NVARCHAR(10), + @SecurityStamp NVARCHAR(50), + @TwoFactorProviders NVARCHAR(MAX), + @TwoFactorRecoveryCode NVARCHAR(32), + @EquivalentDomains NVARCHAR(MAX), + @ExcludedGlobalEquivalentDomains NVARCHAR(MAX), + @AccountRevisionDate DATETIME2(7), + @Key NVARCHAR(MAX), + @PublicKey NVARCHAR(MAX), + @PrivateKey NVARCHAR(MAX), + @Premium BIT, + @PremiumExpirationDate DATETIME2(7), + @RenewalReminderDate DATETIME2(7), + @Storage BIGINT, + @MaxStorageGb SMALLINT, + @Gateway TINYINT, + @GatewayCustomerId VARCHAR(50), + @GatewaySubscriptionId VARCHAR(50), + @ReferenceData VARCHAR(MAX), + @LicenseKey VARCHAR(100), + @Kdf TINYINT, + @KdfIterations INT, + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + UPDATE + [dbo].[User] + SET + [Name] = @Name, + [Email] = @Email, + [EmailVerified] = @EmailVerified, + [MasterPassword] = @MasterPassword, + [MasterPasswordHint] = @MasterPasswordHint, + [Culture] = @Culture, + [SecurityStamp] = @SecurityStamp, + [TwoFactorProviders] = @TwoFactorProviders, + [TwoFactorRecoveryCode] = @TwoFactorRecoveryCode, + [EquivalentDomains] = @EquivalentDomains, + [ExcludedGlobalEquivalentDomains] = @ExcludedGlobalEquivalentDomains, + [AccountRevisionDate] = @AccountRevisionDate, + [Key] = @Key, + [PublicKey] = @PublicKey, + [PrivateKey] = @PrivateKey, + [Premium] = @Premium, + [PremiumExpirationDate] = @PremiumExpirationDate, + [RenewalReminderDate] = @RenewalReminderDate, + [Storage] = @Storage, + [MaxStorageGb] = @MaxStorageGb, + [Gateway] = @Gateway, + [GatewayCustomerId] = @GatewayCustomerId, + [GatewaySubscriptionId] = @GatewaySubscriptionId, + [ReferenceData] = @ReferenceData, + [LicenseKey] = @LicenseKey, + [Kdf] = @Kdf, + [KdfIterations] = @KdfIterations, + [CreationDate] = @CreationDate, + [RevisionDate] = @RevisionDate + WHERE + [Id] = @Id +END +GO + +IF OBJECT_ID('[dbo].[Organization_Create]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[Organization_Create] +END +GO + +CREATE PROCEDURE [dbo].[Organization_Create] + @Id UNIQUEIDENTIFIER, + @Identifier NVARCHAR(50), + @Name NVARCHAR(50), + @BusinessName NVARCHAR(50), + @BusinessAddress1 NVARCHAR(50), + @BusinessAddress2 NVARCHAR(50), + @BusinessAddress3 NVARCHAR(50), + @BusinessCountry VARCHAR(2), + @BusinessTaxNumber NVARCHAR(30), + @BillingEmail NVARCHAR(50), + @Plan NVARCHAR(50), + @PlanType TINYINT, + @Seats SMALLINT, + @MaxCollections SMALLINT, + @UsePolicies BIT, + @UseGroups BIT, + @UseDirectory BIT, + @UseEvents BIT, + @UseTotp BIT, + @Use2fa BIT, + @UseApi BIT, + @SelfHost BIT, + @UsersGetPremium BIT, + @Storage BIGINT, + @MaxStorageGb SMALLINT, + @Gateway TINYINT, + @GatewayCustomerId VARCHAR(50), + @GatewaySubscriptionId VARCHAR(50), + @ReferenceData VARCHAR(MAX), + @Enabled BIT, + @LicenseKey VARCHAR(100), + @ApiKey VARCHAR(30), + @TwoFactorProviders NVARCHAR(MAX), + @ExpirationDate DATETIME2(7), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + INSERT INTO [dbo].[Organization] + ( + [Id], + [Identifier], + [Name], + [BusinessName], + [BusinessAddress1], + [BusinessAddress2], + [BusinessAddress3], + [BusinessCountry], + [BusinessTaxNumber], + [BillingEmail], + [Plan], + [PlanType], + [Seats], + [MaxCollections], + [UsePolicies], + [UseGroups], + [UseDirectory], + [UseEvents], + [UseTotp], + [Use2fa], + [UseApi], + [SelfHost], + [UsersGetPremium], + [Storage], + [MaxStorageGb], + [Gateway], + [GatewayCustomerId], + [GatewaySubscriptionId], + [ReferenceData], + [Enabled], + [LicenseKey], + [ApiKey], + [TwoFactorProviders], + [ExpirationDate], + [CreationDate], + [RevisionDate] + ) + VALUES + ( + @Id, + @Identifier, + @Name, + @BusinessName, + @BusinessAddress1, + @BusinessAddress2, + @BusinessAddress3, + @BusinessCountry, + @BusinessTaxNumber, + @BillingEmail, + @Plan, + @PlanType, + @Seats, + @MaxCollections, + @UsePolicies, + @UseGroups, + @UseDirectory, + @UseEvents, + @UseTotp, + @Use2fa, + @UseApi, + @SelfHost, + @UsersGetPremium, + @Storage, + @MaxStorageGb, + @Gateway, + @GatewayCustomerId, + @GatewaySubscriptionId, + @ReferenceData, + @Enabled, + @LicenseKey, + @ApiKey, + @TwoFactorProviders, + @ExpirationDate, + @CreationDate, + @RevisionDate + ) +END +GO + +IF OBJECT_ID('[dbo].[Organization_Update]') IS NOT NULL +BEGIN + DROP PROCEDURE [dbo].[Organization_Update] +END +GO + +CREATE PROCEDURE [dbo].[Organization_Update] + @Id UNIQUEIDENTIFIER, + @Identifier NVARCHAR(50), + @Name NVARCHAR(50), + @BusinessName NVARCHAR(50), + @BusinessAddress1 NVARCHAR(50), + @BusinessAddress2 NVARCHAR(50), + @BusinessAddress3 NVARCHAR(50), + @BusinessCountry VARCHAR(2), + @BusinessTaxNumber NVARCHAR(30), + @BillingEmail NVARCHAR(50), + @Plan NVARCHAR(50), + @PlanType TINYINT, + @Seats SMALLINT, + @MaxCollections SMALLINT, + @UsePolicies BIT, + @UseGroups BIT, + @UseDirectory BIT, + @UseEvents BIT, + @UseTotp BIT, + @Use2fa BIT, + @UseApi BIT, + @SelfHost BIT, + @UsersGetPremium BIT, + @Storage BIGINT, + @MaxStorageGb SMALLINT, + @Gateway TINYINT, + @GatewayCustomerId VARCHAR(50), + @GatewaySubscriptionId VARCHAR(50), + @ReferenceData VARCHAR(MAX), + @Enabled BIT, + @LicenseKey VARCHAR(100), + @ApiKey VARCHAR(30), + @TwoFactorProviders NVARCHAR(MAX), + @ExpirationDate DATETIME2(7), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + UPDATE + [dbo].[Organization] + SET + [Identifier] = @Identifier, + [Name] = @Name, + [BusinessName] = @BusinessName, + [BusinessAddress1] = @BusinessAddress1, + [BusinessAddress2] = @BusinessAddress2, + [BusinessAddress3] = @BusinessAddress3, + [BusinessCountry] = @BusinessCountry, + [BusinessTaxNumber] = @BusinessTaxNumber, + [BillingEmail] = @BillingEmail, + [Plan] = @Plan, + [PlanType] = @PlanType, + [Seats] = @Seats, + [MaxCollections] = @MaxCollections, + [UsePolicies] = @UsePolicies, + [UseGroups] = @UseGroups, + [UseDirectory] = @UseDirectory, + [UseEvents] = @UseEvents, + [UseTotp] = @UseTotp, + [Use2fa] = @Use2fa, + [UseApi] = @UseApi, + [SelfHost] = @SelfHost, + [UsersGetPremium] = @UsersGetPremium, + [Storage] = @Storage, + [MaxStorageGb] = @MaxStorageGb, + [Gateway] = @Gateway, + [GatewayCustomerId] = @GatewayCustomerId, + [GatewaySubscriptionId] = @GatewaySubscriptionId, + [ReferenceData] = @ReferenceData, + [Enabled] = @Enabled, + [LicenseKey] = @LicenseKey, + [ApiKey] = @ApiKey, + [TwoFactorProviders] = @TwoFactorProviders, + [ExpirationDate] = @ExpirationDate, + [CreationDate] = @CreationDate, + [RevisionDate] = @RevisionDate + WHERE + [Id] = @Id +END +GO