1
0
mirror of https://github.com/bitwarden/server.git synced 2024-11-26 12:55:17 +01:00

change personal plan to family. allow self host

This commit is contained in:
Kyle Spearrin 2017-11-06 16:01:58 -05:00
parent dccdef6db5
commit 0fdb9b3d2f
14 changed files with 282 additions and 23 deletions

View File

@ -3,7 +3,7 @@
public enum PlanType : byte public enum PlanType : byte
{ {
Free = 0, Free = 0,
PersonalAnnually = 1, FamilyAnnually = 1,
TeamsMonthly = 2, TeamsMonthly = 2,
TeamsAnnually = 3, TeamsAnnually = 3,
EnterpriseMonthly = 4, EnterpriseMonthly = 4,

View File

@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business
public OrganizationLicense(Organization org, BillingInfo billingInfo, Guid installationId, public OrganizationLicense(Organization org, BillingInfo billingInfo, Guid installationId,
ILicensingService licenseService) ILicensingService licenseService)
{ {
Version = 1; Version = 2;
LicenseKey = org.LicenseKey; LicenseKey = org.LicenseKey;
InstallationId = installationId; InstallationId = installationId;
Id = org.Id; Id = org.Id;
@ -36,6 +36,7 @@ namespace Bit.Core.Models.Business
UseTotp = org.UseTotp; UseTotp = org.UseTotp;
MaxStorageGb = org.MaxStorageGb; MaxStorageGb = org.MaxStorageGb;
SelfHost = org.SelfHost; SelfHost = org.SelfHost;
UsersGetPremium = org.UsersGetPremium;
Issued = DateTime.UtcNow; Issued = DateTime.UtcNow;
if(billingInfo?.Subscription == null) if(billingInfo?.Subscription == null)
@ -91,6 +92,7 @@ namespace Bit.Core.Models.Business
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public int Version { get; set; } public int Version { get; set; }
public DateTime Issued { get; set; } public DateTime Issued { get; set; }
public DateTime? Refresh { get; set; } public DateTime? Refresh { get; set; }
@ -104,7 +106,7 @@ namespace Bit.Core.Models.Business
public byte[] GetDataBytes(bool forHash = false) public byte[] GetDataBytes(bool forHash = false)
{ {
string data = null; string data = null;
if(Version == 1) if(Version == 1 || Version == 2)
{ {
var props = typeof(OrganizationLicense) var props = typeof(OrganizationLicense)
.GetProperties(BindingFlags.Public | BindingFlags.Instance) .GetProperties(BindingFlags.Public | BindingFlags.Instance)
@ -147,7 +149,7 @@ namespace Bit.Core.Models.Business
return false; return false;
} }
if(Version == 1) if(Version == 1 || Version == 2)
{ {
return InstallationId == globalSettings.Installation.Id && SelfHost; return InstallationId == globalSettings.Installation.Id && SelfHost;
} }
@ -164,9 +166,9 @@ namespace Bit.Core.Models.Business
return false; return false;
} }
if(Version == 1) if(Version == 1 || Version == 2)
{ {
return var valid =
globalSettings.Installation.Id == InstallationId && globalSettings.Installation.Id == InstallationId &&
organization.LicenseKey.Equals(LicenseKey) && organization.LicenseKey.Equals(LicenseKey) &&
organization.Enabled == Enabled && organization.Enabled == Enabled &&
@ -178,6 +180,13 @@ namespace Bit.Core.Models.Business
organization.UseTotp == UseTotp && organization.UseTotp == UseTotp &&
organization.SelfHost == SelfHost && organization.SelfHost == SelfHost &&
organization.Name.Equals(Name); organization.Name.Equals(Name);
if(valid && Version == 2)
{
valid = organization.UsersGetPremium = UsersGetPremium;
}
return valid;
} }
else else
{ {

View File

@ -10,6 +10,8 @@ namespace Bit.Core.Models.Data
public bool UseGroups { get; set; } public bool UseGroups { get; set; }
public bool UseDirectory { get; set; } public bool UseDirectory { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public int Seats { get; set; } public int Seats { get; set; }
public int MaxCollections { get; set; } public int MaxCollections { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }

View File

@ -23,5 +23,6 @@ namespace Bit.Core.Models.StaticStore
public bool Disabled { get; set; } public bool Disabled { get; set; }
public int? TrialPeriodDays { get; set; } public int? TrialPeriodDays { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
} }
} }

View File

@ -25,6 +25,7 @@ namespace Bit.Core.Models.Table
public bool UseDirectory { get; set; } public bool UseDirectory { get; set; }
public bool UseTotp { get; set; } public bool UseTotp { get; set; }
public bool SelfHost { get; set; } public bool SelfHost { get; set; }
public bool UsersGetPremium { get; set; }
public long? Storage { get; set; } public long? Storage { get; set; }
public short? MaxStorageGb { get; set; } public short? MaxStorageGb { get; set; }
public GatewayType? Gateway { get; set; } public GatewayType? Gateway { get; set; }

View File

@ -112,10 +112,10 @@ namespace Bit.Core.Services
foreach(var user in nonPremiumUsers) foreach(var user in nonPremiumUsers)
{ {
var details = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id); var details = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id);
if(details.Any(d => d.Enabled)) if(details.Any(d => d.SelfHost && d.UsersGetPremium && d.Enabled))
{ {
_logger.LogInformation("Granting premium to user {0}({1}) because they are in an active organization.", _logger.LogInformation("Granting premium to user {0}({1}) because they are in an active organization " +
user.Id, user.Email); "with premium features.", user.Id, user.Email);
user.Premium = true; user.Premium = true;
user.MaxStorageGb = 10240; // 10 TB user.MaxStorageGb = 10240; // 10 TB
@ -170,7 +170,7 @@ namespace Bit.Core.Services
if(!valid) if(!valid)
{ {
var details = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id); var details = await _organizationUserRepository.GetManyDetailsByUserAsync(user.Id);
valid = details.Any(d => d.Enabled); valid = details.Any(d => d.SelfHost && d.UsersGetPremium && d.Enabled);
if(valid && (!string.IsNullOrWhiteSpace(user.LicenseKey) || user.PremiumExpirationDate.HasValue)) if(valid && (!string.IsNullOrWhiteSpace(user.LicenseKey) || user.PremiumExpirationDate.HasValue))
{ {

View File

@ -527,6 +527,7 @@ namespace Bit.Core.Services
UseDirectory = plan.UseDirectory, UseDirectory = plan.UseDirectory,
UseTotp = plan.UseTotp, UseTotp = plan.UseTotp,
SelfHost = plan.SelfHost, SelfHost = plan.SelfHost,
UsersGetPremium = plan.UsersGetPremium,
Plan = plan.Name, Plan = plan.Name,
Gateway = plan.Type == PlanType.Free ? null : (GatewayType?)GatewayType.Stripe, Gateway = plan.Type == PlanType.Free ? null : (GatewayType?)GatewayType.Stripe,
GatewayCustomerId = customer?.Id, GatewayCustomerId = customer?.Id,
@ -581,6 +582,7 @@ namespace Bit.Core.Services
UseTotp = license.UseTotp, UseTotp = license.UseTotp,
Plan = license.Plan, Plan = license.Plan,
SelfHost = license.SelfHost, SelfHost = license.SelfHost,
UsersGetPremium = license.UsersGetPremium,
Gateway = null, Gateway = null,
GatewayCustomerId = null, GatewayCustomerId = null,
GatewaySubscriptionId = null, GatewaySubscriptionId = null,
@ -597,8 +599,8 @@ namespace Bit.Core.Services
Directory.CreateDirectory(dir); Directory.CreateDirectory(dir);
File.WriteAllText($"{dir}/{organization.Id}.json", JsonConvert.SerializeObject(license, Formatting.Indented)); File.WriteAllText($"{dir}/{organization.Id}.json", JsonConvert.SerializeObject(license, Formatting.Indented));
// self-hosted org users get premium access // self-hosted org users get premium access on some plans
if(!owner.Premium && result.Item1.Enabled) if(organization.UsersGetPremium && !owner.Premium && result.Item1.Enabled)
{ {
owner.Premium = true; owner.Premium = true;
owner.MaxStorageGb = 10240; // 10 TB owner.MaxStorageGb = 10240; // 10 TB
@ -1003,7 +1005,7 @@ namespace Bit.Core.Services
await _mailService.SendOrganizationConfirmedEmailAsync(org.Name, user.Email); await _mailService.SendOrganizationConfirmedEmailAsync(org.Name, user.Email);
// self-hosted org users get premium access // self-hosted org users get premium access
if(_globalSettings.SelfHosted && !user.Premium && org.Enabled) if(_globalSettings.SelfHosted && !user.Premium && org.UsersGetPremium && org.Enabled)
{ {
user.Premium = true; user.Premium = true;
user.MaxStorageGb = 10240; // 10 TB user.MaxStorageGb = 10240; // 10 TB

View File

@ -101,20 +101,18 @@ namespace Bit.Core.Utilities
}, },
new Plan new Plan
{ {
Type = PlanType.PersonalAnnually, Type = PlanType.FamilyAnnually,
BaseSeats = 5, BaseSeats = 5,
BasePrice = 12, BasePrice = 12,
SeatPrice = 12, CanBuyAdditionalSeats = false,
CanBuyAdditionalSeats = true, Name = "Family",
MaxAdditionalSeats = 5,
Name = "Personal",
StripePlanId = "personal-org-annually", StripePlanId = "personal-org-annually",
StripeSeatPlanId = "personal-org-seat-annually",
StripStoragePlanId = "storage-gb-annually", StripStoragePlanId = "storage-gb-annually",
UpgradeSortOrder = 1, UpgradeSortOrder = 1,
TrialPeriodDays = 7, TrialPeriodDays = 7,
UseTotp = true, UseTotp = true,
MaxStorageGb = 1 MaxStorageGb = 1,
SelfHost = true
}, },
new Plan new Plan
{ {
@ -165,7 +163,8 @@ namespace Bit.Core.Utilities
UseDirectory = true, UseDirectory = true,
UseTotp = true, UseTotp = true,
MaxStorageGb = 1, MaxStorageGb = 1,
SelfHost = true SelfHost = true,
UsersGetPremium = true
}, },
new Plan new Plan
{ {
@ -184,7 +183,8 @@ namespace Bit.Core.Utilities
UseDirectory = true, UseDirectory = true,
UseTotp = true, UseTotp = true,
MaxStorageGb = 1, MaxStorageGb = 1,
SelfHost = true SelfHost = true,
UsersGetPremium = true
} }
}; };

View File

@ -16,6 +16,7 @@
@UseDirectory BIT, @UseDirectory BIT,
@UseTotp BIT, @UseTotp BIT,
@SelfHost BIT, @SelfHost BIT,
@UsersGetPremium BIT,
@Storage BIGINT, @Storage BIGINT,
@MaxStorageGb SMALLINT, @MaxStorageGb SMALLINT,
@Gateway TINYINT, @Gateway TINYINT,
@ -49,6 +50,7 @@ BEGIN
[UseDirectory], [UseDirectory],
[UseTotp], [UseTotp],
[SelfHost], [SelfHost],
[UsersGetPremium],
[Storage], [Storage],
[MaxStorageGb], [MaxStorageGb],
[Gateway], [Gateway],
@ -79,6 +81,7 @@ BEGIN
@UseDirectory, @UseDirectory,
@UseTotp, @UseTotp,
@SelfHost, @SelfHost,
@UsersGetPremium,
@Storage, @Storage,
@MaxStorageGb, @MaxStorageGb,
@Gateway, @Gateway,

View File

@ -16,6 +16,7 @@
@UseDirectory BIT, @UseDirectory BIT,
@UseTotp BIT, @UseTotp BIT,
@SelfHost BIT, @SelfHost BIT,
@UsersGetPremium BIT,
@Storage BIGINT, @Storage BIGINT,
@MaxStorageGb SMALLINT, @MaxStorageGb SMALLINT,
@Gateway TINYINT, @Gateway TINYINT,
@ -26,7 +27,6 @@
@ExpirationDate DATETIME2(7), @ExpirationDate DATETIME2(7),
@CreationDate DATETIME2(7), @CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7) @RevisionDate DATETIME2(7)
AS AS
BEGIN BEGIN
SET NOCOUNT ON SET NOCOUNT ON
@ -50,6 +50,7 @@ BEGIN
[UseDirectory] = @UseDirectory, [UseDirectory] = @UseDirectory,
[UseTotp] = @UseTotp, [UseTotp] = @UseTotp,
[SelfHost] = @SelfHost, [SelfHost] = @SelfHost,
[UsersGetPremium] = @UsersGetPremium,
[Storage] = @Storage, [Storage] = @Storage,
[MaxStorageGb] = @MaxStorageGb, [MaxStorageGb] = @MaxStorageGb,
[Gateway] = @Gateway, [Gateway] = @Gateway,

View File

@ -16,6 +16,7 @@
[UseDirectory] BIT NOT NULL, [UseDirectory] BIT NOT NULL,
[UseTotp] BIT NOT NULL, [UseTotp] BIT NOT NULL,
[SelfHost] BIT NOT NULL, [SelfHost] BIT NOT NULL,
[UsersGetPremium] BIT NOT NULL,
[Storage] BIGINT NULL, [Storage] BIGINT NULL,
[MaxStorageGb] SMALLINT NULL, [MaxStorageGb] SMALLINT NULL,
[Gateway] TINYINT NULL, [Gateway] TINYINT NULL,

View File

@ -8,6 +8,8 @@ SELECT
O.[UseGroups], O.[UseGroups],
O.[UseDirectory], O.[UseDirectory],
O.[UseTotp], O.[UseTotp],
O.[SelfHost],
O.[UsersGetPremium],
O.[Seats], O.[Seats],
O.[MaxCollections], O.[MaxCollections],
O.[MaxStorageGb], O.[MaxStorageGb],

View File

@ -0,0 +1,236 @@
IF COL_LENGTH('[dbo].[Organization]', 'UsersGetPremium') IS NULL
BEGIN
ALTER TABLE
[dbo].[Organization]
ADD
[UsersGetPremium] BIT NULL
END
GO
UPDATE
[dbo].[Organization]
SET
[UsersGetPremium] = (CASE WHEN [PlanType] = 5 OR [PlanType] = 4 THEN 1 ELSE 0 END)
GO
UPDATE
[dbo].[Organization]
SET
[Plan] = 'Family'
WHERE
[PlanType] = 1
GO
ALTER TABLE
[dbo].[Organization]
ALTER COLUMN
[UsersGetPremium] 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,
@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],
[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,
@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,
@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,
[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] = '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.[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

View File

@ -8,6 +8,7 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<EmbeddedResource Include="DbScripts\2017-11-06_00_FamilyPlanAdjustments.sql" />
<EmbeddedResource Include="DbScripts\2017-10-25_00_OrgUserUpdates.sql" /> <EmbeddedResource Include="DbScripts\2017-10-25_00_OrgUserUpdates.sql" />
<EmbeddedResource Include="DbScripts\2017-09-08_00_OrgUserCounts.sql" /> <EmbeddedResource Include="DbScripts\2017-09-08_00_OrgUserCounts.sql" />
<EmbeddedResource Include="DbScripts\2017-09-06_00_CipherDetails.sql" /> <EmbeddedResource Include="DbScripts\2017-09-06_00_CipherDetails.sql" />