diff --git a/src/Core/Models/Api/Response/OrganizationResponseModel.cs b/src/Core/Models/Api/Response/OrganizationResponseModel.cs index b20fc8ff9c..7a1bf65204 100644 --- a/src/Core/Models/Api/Response/OrganizationResponseModel.cs +++ b/src/Core/Models/Api/Response/OrganizationResponseModel.cs @@ -31,6 +31,7 @@ namespace Bit.Core.Models.Api MaxCollections = organization.MaxCollections; UseGroups = organization.UseGroups; UseDirectory = organization.UseDirectory; + UseEvents = organization.UseEvents; UseTotp = organization.UseTotp; } @@ -49,6 +50,7 @@ namespace Bit.Core.Models.Api public short? MaxCollections { get; set; } public bool UseGroups { get; set; } public bool UseDirectory { get; set; } + public bool UseEvents { get; set; } public bool UseTotp { get; set; } } diff --git a/src/Core/Models/Api/Response/ProfileOrganizationResponseModel.cs b/src/Core/Models/Api/Response/ProfileOrganizationResponseModel.cs index 15b3cb95e4..bfdc6b9bb0 100644 --- a/src/Core/Models/Api/Response/ProfileOrganizationResponseModel.cs +++ b/src/Core/Models/Api/Response/ProfileOrganizationResponseModel.cs @@ -12,6 +12,7 @@ namespace Bit.Core.Models.Api Name = organization.Name; UseGroups = organization.UseGroups; UseDirectory = organization.UseDirectory; + UseEvents = organization.UseEvents; UseTotp = organization.UseTotp; Seats = organization.Seats; MaxCollections = organization.MaxCollections; @@ -26,6 +27,7 @@ namespace Bit.Core.Models.Api public string Name { get; set; } public bool UseGroups { get; set; } public bool UseDirectory { get; set; } + public bool UseEvents { get; set; } public bool UseTotp { get; set; } public int Seats { get; set; } public int MaxCollections { get; set; } diff --git a/src/Core/Models/Business/OrganizationLicense.cs b/src/Core/Models/Business/OrganizationLicense.cs index 70bb627369..733f945c3a 100644 --- a/src/Core/Models/Business/OrganizationLicense.cs +++ b/src/Core/Models/Business/OrganizationLicense.cs @@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business public OrganizationLicense(Organization org, BillingInfo billingInfo, Guid installationId, ILicensingService licenseService) { - Version = 2; + Version = 3; LicenseKey = org.LicenseKey; InstallationId = installationId; Id = org.Id; @@ -32,6 +32,7 @@ namespace Bit.Core.Models.Business Seats = org.Seats; MaxCollections = org.MaxCollections; UseGroups = org.UseGroups; + UseEvents = org.UseEvents; UseDirectory = org.UseDirectory; UseTotp = org.UseTotp; MaxStorageGb = org.MaxStorageGb; @@ -96,6 +97,7 @@ namespace Bit.Core.Models.Business public short? Seats { get; set; } public short? MaxCollections { get; set; } public bool UseGroups { get; set; } + public bool UseEvents { get; set; } public bool UseDirectory { get; set; } public bool UseTotp { get; set; } public short? MaxStorageGb { get; set; } @@ -114,7 +116,7 @@ namespace Bit.Core.Models.Business public byte[] GetDataBytes(bool forHash = false) { string data = null; - if(Version == 1 || Version == 2) + if(Version >= 1 && Version <= 3) { var props = typeof(OrganizationLicense) .GetProperties(BindingFlags.Public | BindingFlags.Instance) @@ -122,7 +124,9 @@ namespace Bit.Core.Models.Business !p.Name.Equals(nameof(Signature)) && !p.Name.Equals(nameof(SignatureBytes)) && // UsersGetPremium was added in Version 2 - (Version > 1 || !p.Name.Equals(nameof(UsersGetPremium))) && + (Version >= 2 || !p.Name.Equals(nameof(UsersGetPremium))) && + // UseEvents was added in Version 3 + (Version >= 3 || !p.Name.Equals(nameof(UseEvents))) && ( !forHash || ( @@ -159,7 +163,7 @@ namespace Bit.Core.Models.Business return false; } - if(Version == 1 || Version == 2) + if(Version >= 1 && Version <= 3) { return InstallationId == globalSettings.Installation.Id && SelfHost; } @@ -176,7 +180,7 @@ namespace Bit.Core.Models.Business return false; } - if(Version == 1 || Version == 2) + if(Version >= 1 && Version <= 3) { var valid = globalSettings.Installation.Id == InstallationId && @@ -191,11 +195,16 @@ namespace Bit.Core.Models.Business organization.SelfHost == SelfHost && organization.Name.Equals(Name); - if(valid && Version == 2) + if(valid && Version >= 2) { valid = organization.UsersGetPremium == UsersGetPremium; } + if(valid && Version >= 3) + { + valid = organization.UseEvents == UseEvents; + } + return valid; } else diff --git a/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs b/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs index 438236328f..c5bb4ace92 100644 --- a/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs +++ b/src/Core/Models/Data/OrganizationUserOrganizationDetails.cs @@ -9,6 +9,7 @@ namespace Bit.Core.Models.Data public string Name { get; set; } public bool UseGroups { get; set; } public bool UseDirectory { get; set; } + public bool UseEvents { get; set; } public bool UseTotp { get; set; } public bool SelfHost { get; set; } public bool UsersGetPremium { get; set; } diff --git a/src/Core/Models/StaticStore/Plan.cs b/src/Core/Models/StaticStore/Plan.cs index 025994057a..b3c35de61a 100644 --- a/src/Core/Models/StaticStore/Plan.cs +++ b/src/Core/Models/StaticStore/Plan.cs @@ -14,6 +14,7 @@ namespace Bit.Core.Models.StaticStore public short? MaxAdditionalSeats { get; set; } public bool UseGroups { get; set; } public bool UseDirectory { get; set; } + public bool UseEvents { get; set; } public bool UseTotp { get; set; } public short? MaxStorageGb { get; set; } public decimal BasePrice { get; set; } diff --git a/src/Core/Models/Table/Organization.cs b/src/Core/Models/Table/Organization.cs index 63a5ac88d5..f56fd398b2 100644 --- a/src/Core/Models/Table/Organization.cs +++ b/src/Core/Models/Table/Organization.cs @@ -23,6 +23,7 @@ namespace Bit.Core.Models.Table public short? MaxCollections { get; set; } public bool UseGroups { get; set; } public bool UseDirectory { get; set; } + public bool UseEvents { get; set; } public bool UseTotp { get; set; } public bool SelfHost { get; set; } public bool UsersGetPremium { get; set; } diff --git a/src/Core/Services/Implementations/OrganizationService.cs b/src/Core/Services/Implementations/OrganizationService.cs index 6eeed646aa..8da972c8e7 100644 --- a/src/Core/Services/Implementations/OrganizationService.cs +++ b/src/Core/Services/Implementations/OrganizationService.cs @@ -527,6 +527,7 @@ namespace Bit.Core.Services MaxStorageGb = !plan.MaxStorageGb.HasValue ? (short?)null : (short)(plan.MaxStorageGb.Value + signup.AdditionalStorageGb), UseGroups = plan.UseGroups, + UseEvents = plan.UseEvents, UseDirectory = plan.UseDirectory, UseTotp = plan.UseTotp, SelfHost = plan.SelfHost, @@ -582,6 +583,7 @@ namespace Bit.Core.Services MaxStorageGb = _globalSettings.SelfHosted ? 10240 : license.MaxStorageGb, // 10 TB UseGroups = license.UseGroups, UseDirectory = license.UseDirectory, + UseEvents = license.UseEvents, UseTotp = license.UseTotp, Plan = license.Plan, SelfHost = license.SelfHost, @@ -744,6 +746,7 @@ namespace Bit.Core.Services organization.MaxCollections = license.MaxCollections; organization.UseGroups = license.UseGroups; organization.UseDirectory = license.UseDirectory; + organization.UseEvents = license.UseEvents; organization.UseTotp = license.UseTotp; organization.Plan = license.Plan; organization.Enabled = license.Enabled; diff --git a/src/Core/Utilities/StaticStore.cs b/src/Core/Utilities/StaticStore.cs index 03ade3e4c9..0d80917a2d 100644 --- a/src/Core/Utilities/StaticStore.cs +++ b/src/Core/Utilities/StaticStore.cs @@ -161,6 +161,7 @@ namespace Bit.Core.Utilities TrialPeriodDays = 7, UseGroups = true, UseDirectory = true, + UseEvents = true, UseTotp = true, MaxStorageGb = 1, SelfHost = true, @@ -181,6 +182,7 @@ namespace Bit.Core.Utilities TrialPeriodDays = 7, UseGroups = true, UseDirectory = true, + UseEvents = true, UseTotp = true, MaxStorageGb = 1, SelfHost = true, diff --git a/src/Sql/Sql.sqlproj b/src/Sql/Sql.sqlproj index 04dd70b5b5..2ce8d2cd0f 100644 --- a/src/Sql/Sql.sqlproj +++ b/src/Sql/Sql.sqlproj @@ -218,5 +218,6 @@ + \ No newline at end of file diff --git a/src/Sql/dbo/Stored Procedures/Organization_Create.sql b/src/Sql/dbo/Stored Procedures/Organization_Create.sql index d8b68ddd4d..c66572aafa 100644 --- a/src/Sql/dbo/Stored Procedures/Organization_Create.sql +++ b/src/Sql/dbo/Stored Procedures/Organization_Create.sql @@ -14,6 +14,7 @@ @MaxCollections SMALLINT, @UseGroups BIT, @UseDirectory BIT, + @UseEvents BIT, @UseTotp BIT, @SelfHost BIT, @UsersGetPremium BIT, @@ -48,6 +49,7 @@ BEGIN [MaxCollections], [UseGroups], [UseDirectory], + [UseEvents], [UseTotp], [SelfHost], [UsersGetPremium], @@ -79,6 +81,7 @@ BEGIN @MaxCollections, @UseGroups, @UseDirectory, + @UseEvents, @UseTotp, @SelfHost, @UsersGetPremium, diff --git a/src/Sql/dbo/Stored Procedures/Organization_Update.sql b/src/Sql/dbo/Stored Procedures/Organization_Update.sql index 3c672c36f8..47252610c1 100644 --- a/src/Sql/dbo/Stored Procedures/Organization_Update.sql +++ b/src/Sql/dbo/Stored Procedures/Organization_Update.sql @@ -14,6 +14,7 @@ @MaxCollections SMALLINT, @UseGroups BIT, @UseDirectory BIT, + @UseEvents BIT, @UseTotp BIT, @SelfHost BIT, @UsersGetPremium BIT, @@ -48,6 +49,7 @@ BEGIN [MaxCollections] = @MaxCollections, [UseGroups] = @UseGroups, [UseDirectory] = @UseDirectory, + [UseEvents] = @UseEvents, [UseTotp] = @UseTotp, [SelfHost] = @SelfHost, [UsersGetPremium] = @UsersGetPremium, diff --git a/src/Sql/dbo/Tables/Organization.sql b/src/Sql/dbo/Tables/Organization.sql index 80e46b327c..6c6a19aacd 100644 --- a/src/Sql/dbo/Tables/Organization.sql +++ b/src/Sql/dbo/Tables/Organization.sql @@ -14,6 +14,7 @@ [MaxCollections] SMALLINT NULL, [UseGroups] BIT NOT NULL, [UseDirectory] BIT NOT NULL, + [UseEvents] BIT NOT NULL, [UseTotp] BIT NOT NULL, [SelfHost] BIT NOT NULL, [UsersGetPremium] BIT NOT NULL, diff --git a/src/Sql/dbo/Views/EventView.sql b/src/Sql/dbo/Views/EventView.sql new file mode 100644 index 0000000000..dcb6a3b251 --- /dev/null +++ b/src/Sql/dbo/Views/EventView.sql @@ -0,0 +1,6 @@ +CREATE VIEW [dbo].[EventView] +AS +SELECT + * +FROM + [dbo].[Event] \ No newline at end of file diff --git a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql index c79322e88c..721d095e9d 100644 --- a/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql +++ b/src/Sql/dbo/Views/OrganizationUserOrganizationDetailsView.sql @@ -7,6 +7,7 @@ SELECT O.[Enabled], O.[UseGroups], O.[UseDirectory], + O.[UseEvents], O.[UseTotp], O.[SelfHost], O.[UsersGetPremium], diff --git a/util/Setup/DbScripts/2017-12-12_00_Events.sql b/util/Setup/DbScripts/2017-12-12_00_Events.sql index c1b1e2997b..9181508625 100644 --- a/util/Setup/DbScripts/2017-12-12_00_Events.sql +++ b/util/Setup/DbScripts/2017-12-12_00_Events.sql @@ -1,4 +1,253 @@ -IF OBJECT_ID('[dbo].[Event]') IS NULL +IF COL_LENGTH('[dbo].[Organization]', 'UseEvents') IS NULL +BEGIN + ALTER TABLE + [dbo].[Organization] + ADD + [UseEvents] BIT NULL +END +GO + +UPDATE + [dbo].[Organization] +SET + [UseEvents] = (CASE WHEN [PlanType] = 5 OR [PlanType] = 4 THEN 1 ELSE 0 END) +GO + +ALTER TABLE + [dbo].[Organization] +ALTER COLUMN + [UseEvents] BIT NOT NULL +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, + @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, + @UseGroups BIT, + @UseDirectory BIT, + @UseEvents BIT, + @UseTotp BIT, + @SelfHost BIT, + @UsersGetPremium BIT, + @Storage BIGINT, + @MaxStorageGb SMALLINT, + @Gateway TINYINT, + @GatewayCustomerId VARCHAR(50), + @GatewaySubscriptionId VARCHAR(50), + @Enabled BIT, + @LicenseKey VARCHAR(100), + @ExpirationDate DATETIME2(7), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + INSERT INTO [dbo].[Organization] + ( + [Id], + [Name], + [BusinessName], + [BusinessAddress1], + [BusinessAddress2], + [BusinessAddress3], + [BusinessCountry], + [BusinessTaxNumber], + [BillingEmail], + [Plan], + [PlanType], + [Seats], + [MaxCollections], + [UseGroups], + [UseDirectory], + [UseEvents], + [UseTotp], + [SelfHost], + [UsersGetPremium], + [Storage], + [MaxStorageGb], + [Gateway], + [GatewayCustomerId], + [GatewaySubscriptionId], + [Enabled], + [LicenseKey], + [ExpirationDate], + [CreationDate], + [RevisionDate] + ) + VALUES + ( + @Id, + @Name, + @BusinessName, + @BusinessAddress1, + @BusinessAddress2, + @BusinessAddress3, + @BusinessCountry, + @BusinessTaxNumber, + @BillingEmail, + @Plan, + @PlanType, + @Seats, + @MaxCollections, + @UseGroups, + @UseDirectory, + @UseEvents, + @UseTotp, + @SelfHost, + @UsersGetPremium, + @Storage, + @MaxStorageGb, + @Gateway, + @GatewayCustomerId, + @GatewaySubscriptionId, + @Enabled, + @LicenseKey, + @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, + @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, + @UseGroups BIT, + @UseDirectory BIT, + @UseEvents BIT, + @UseTotp BIT, + @SelfHost BIT, + @UsersGetPremium BIT, + @Storage BIGINT, + @MaxStorageGb SMALLINT, + @Gateway TINYINT, + @GatewayCustomerId VARCHAR(50), + @GatewaySubscriptionId VARCHAR(50), + @Enabled BIT, + @LicenseKey VARCHAR(100), + @ExpirationDate DATETIME2(7), + @CreationDate DATETIME2(7), + @RevisionDate DATETIME2(7) +AS +BEGIN + SET NOCOUNT ON + + UPDATE + [dbo].[Organization] + SET + [Name] = @Name, + [BusinessName] = @BusinessName, + [BusinessAddress1] = @BusinessAddress1, + [BusinessAddress2] = @BusinessAddress2, + [BusinessAddress3] = @BusinessAddress3, + [BusinessCountry] = @BusinessCountry, + [BusinessTaxNumber] = @BusinessTaxNumber, + [BillingEmail] = @BillingEmail, + [Plan] = @Plan, + [PlanType] = @PlanType, + [Seats] = @Seats, + [MaxCollections] = @MaxCollections, + [UseGroups] = @UseGroups, + [UseDirectory] = @UseDirectory, + [UseEvents] = @UseEvents, + [UseTotp] = @UseTotp, + [SelfHost] = @SelfHost, + [UsersGetPremium] = @UsersGetPremium, + [Storage] = @Storage, + [MaxStorageGb] = @MaxStorageGb, + [Gateway] = @Gateway, + [GatewayCustomerId] = @GatewayCustomerId, + [GatewaySubscriptionId] = @GatewaySubscriptionId, + [Enabled] = @Enabled, + [LicenseKey] = @LicenseKey, + [ExpirationDate] = @ExpirationDate, + [CreationDate] = @CreationDate, + [RevisionDate] = @RevisionDate + WHERE + [Id] = @Id +END +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 EXISTS(SELECT * FROM sys.views WHERE [Name] = 'OrganizationUserOrganizationDetailsView') +BEGIN + DROP VIEW [dbo].[OrganizationUserOrganizationDetailsView] +END +GO + +CREATE VIEW [dbo].[OrganizationUserOrganizationDetailsView] +AS +SELECT + OU.[UserId], + OU.[OrganizationId], + O.[Name], + O.[Enabled], + O.[UseGroups], + O.[UseDirectory], + O.[UseEvents], + O.[UseTotp], + O.[SelfHost], + O.[UsersGetPremium], + O.[Seats], + O.[MaxCollections], + O.[MaxStorageGb], + OU.[Key], + OU.[Status], + OU.[Type] +FROM + [dbo].[OrganizationUser] OU +INNER JOIN + [dbo].[Organization] O ON O.[Id] = OU.[OrganizationId] +GO + +IF OBJECT_ID('[dbo].[Event]') IS NULL BEGIN CREATE TABLE [dbo].[Event] ( [Id] UNIQUEIDENTIFIER NOT NULL, @@ -68,3 +317,17 @@ BEGIN ) END GO + +IF EXISTS(SELECT * FROM sys.views WHERE [Name] = 'EventView') +BEGIN + DROP VIEW [dbo].[EventView] +END +GO + +CREATE VIEW [dbo].[EventView] +AS +SELECT + * +FROM + [dbo].[Event] +GO