mirror of
https://github.com/bitwarden/server.git
synced 2024-11-25 12:45:18 +01:00
change personal plan to family. allow self host
This commit is contained in:
parent
dccdef6db5
commit
0fdb9b3d2f
@ -3,7 +3,7 @@
|
||||
public enum PlanType : byte
|
||||
{
|
||||
Free = 0,
|
||||
PersonalAnnually = 1,
|
||||
FamilyAnnually = 1,
|
||||
TeamsMonthly = 2,
|
||||
TeamsAnnually = 3,
|
||||
EnterpriseMonthly = 4,
|
||||
|
@ -19,7 +19,7 @@ namespace Bit.Core.Models.Business
|
||||
public OrganizationLicense(Organization org, BillingInfo billingInfo, Guid installationId,
|
||||
ILicensingService licenseService)
|
||||
{
|
||||
Version = 1;
|
||||
Version = 2;
|
||||
LicenseKey = org.LicenseKey;
|
||||
InstallationId = installationId;
|
||||
Id = org.Id;
|
||||
@ -36,6 +36,7 @@ namespace Bit.Core.Models.Business
|
||||
UseTotp = org.UseTotp;
|
||||
MaxStorageGb = org.MaxStorageGb;
|
||||
SelfHost = org.SelfHost;
|
||||
UsersGetPremium = org.UsersGetPremium;
|
||||
Issued = DateTime.UtcNow;
|
||||
|
||||
if(billingInfo?.Subscription == null)
|
||||
@ -91,6 +92,7 @@ namespace Bit.Core.Models.Business
|
||||
public bool UseTotp { get; set; }
|
||||
public short? MaxStorageGb { get; set; }
|
||||
public bool SelfHost { get; set; }
|
||||
public bool UsersGetPremium { get; set; }
|
||||
public int Version { get; set; }
|
||||
public DateTime Issued { get; set; }
|
||||
public DateTime? Refresh { get; set; }
|
||||
@ -104,7 +106,7 @@ namespace Bit.Core.Models.Business
|
||||
public byte[] GetDataBytes(bool forHash = false)
|
||||
{
|
||||
string data = null;
|
||||
if(Version == 1)
|
||||
if(Version == 1 || Version == 2)
|
||||
{
|
||||
var props = typeof(OrganizationLicense)
|
||||
.GetProperties(BindingFlags.Public | BindingFlags.Instance)
|
||||
@ -147,7 +149,7 @@ namespace Bit.Core.Models.Business
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version == 1)
|
||||
if(Version == 1 || Version == 2)
|
||||
{
|
||||
return InstallationId == globalSettings.Installation.Id && SelfHost;
|
||||
}
|
||||
@ -164,9 +166,9 @@ namespace Bit.Core.Models.Business
|
||||
return false;
|
||||
}
|
||||
|
||||
if(Version == 1)
|
||||
if(Version == 1 || Version == 2)
|
||||
{
|
||||
return
|
||||
var valid =
|
||||
globalSettings.Installation.Id == InstallationId &&
|
||||
organization.LicenseKey.Equals(LicenseKey) &&
|
||||
organization.Enabled == Enabled &&
|
||||
@ -178,6 +180,13 @@ namespace Bit.Core.Models.Business
|
||||
organization.UseTotp == UseTotp &&
|
||||
organization.SelfHost == SelfHost &&
|
||||
organization.Name.Equals(Name);
|
||||
|
||||
if(valid && Version == 2)
|
||||
{
|
||||
valid = organization.UsersGetPremium = UsersGetPremium;
|
||||
}
|
||||
|
||||
return valid;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -10,6 +10,8 @@ namespace Bit.Core.Models.Data
|
||||
public bool UseGroups { get; set; }
|
||||
public bool UseDirectory { get; set; }
|
||||
public bool UseTotp { get; set; }
|
||||
public bool SelfHost { get; set; }
|
||||
public bool UsersGetPremium { get; set; }
|
||||
public int Seats { get; set; }
|
||||
public int MaxCollections { get; set; }
|
||||
public short? MaxStorageGb { get; set; }
|
||||
|
@ -23,5 +23,6 @@ namespace Bit.Core.Models.StaticStore
|
||||
public bool Disabled { get; set; }
|
||||
public int? TrialPeriodDays { get; set; }
|
||||
public bool SelfHost { get; set; }
|
||||
public bool UsersGetPremium { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ namespace Bit.Core.Models.Table
|
||||
public bool UseDirectory { get; set; }
|
||||
public bool UseTotp { get; set; }
|
||||
public bool SelfHost { get; set; }
|
||||
public bool UsersGetPremium { get; set; }
|
||||
public long? Storage { get; set; }
|
||||
public short? MaxStorageGb { get; set; }
|
||||
public GatewayType? Gateway { get; set; }
|
||||
|
@ -112,10 +112,10 @@ namespace Bit.Core.Services
|
||||
foreach(var user in nonPremiumUsers)
|
||||
{
|
||||
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.",
|
||||
user.Id, user.Email);
|
||||
_logger.LogInformation("Granting premium to user {0}({1}) because they are in an active organization " +
|
||||
"with premium features.", user.Id, user.Email);
|
||||
|
||||
user.Premium = true;
|
||||
user.MaxStorageGb = 10240; // 10 TB
|
||||
@ -170,7 +170,7 @@ namespace Bit.Core.Services
|
||||
if(!valid)
|
||||
{
|
||||
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))
|
||||
{
|
||||
|
@ -527,6 +527,7 @@ namespace Bit.Core.Services
|
||||
UseDirectory = plan.UseDirectory,
|
||||
UseTotp = plan.UseTotp,
|
||||
SelfHost = plan.SelfHost,
|
||||
UsersGetPremium = plan.UsersGetPremium,
|
||||
Plan = plan.Name,
|
||||
Gateway = plan.Type == PlanType.Free ? null : (GatewayType?)GatewayType.Stripe,
|
||||
GatewayCustomerId = customer?.Id,
|
||||
@ -581,6 +582,7 @@ namespace Bit.Core.Services
|
||||
UseTotp = license.UseTotp,
|
||||
Plan = license.Plan,
|
||||
SelfHost = license.SelfHost,
|
||||
UsersGetPremium = license.UsersGetPremium,
|
||||
Gateway = null,
|
||||
GatewayCustomerId = null,
|
||||
GatewaySubscriptionId = null,
|
||||
@ -597,8 +599,8 @@ namespace Bit.Core.Services
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText($"{dir}/{organization.Id}.json", JsonConvert.SerializeObject(license, Formatting.Indented));
|
||||
|
||||
// self-hosted org users get premium access
|
||||
if(!owner.Premium && result.Item1.Enabled)
|
||||
// self-hosted org users get premium access on some plans
|
||||
if(organization.UsersGetPremium && !owner.Premium && result.Item1.Enabled)
|
||||
{
|
||||
owner.Premium = true;
|
||||
owner.MaxStorageGb = 10240; // 10 TB
|
||||
@ -1003,7 +1005,7 @@ namespace Bit.Core.Services
|
||||
await _mailService.SendOrganizationConfirmedEmailAsync(org.Name, user.Email);
|
||||
|
||||
// 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.MaxStorageGb = 10240; // 10 TB
|
||||
|
@ -101,20 +101,18 @@ namespace Bit.Core.Utilities
|
||||
},
|
||||
new Plan
|
||||
{
|
||||
Type = PlanType.PersonalAnnually,
|
||||
Type = PlanType.FamilyAnnually,
|
||||
BaseSeats = 5,
|
||||
BasePrice = 12,
|
||||
SeatPrice = 12,
|
||||
CanBuyAdditionalSeats = true,
|
||||
MaxAdditionalSeats = 5,
|
||||
Name = "Personal",
|
||||
CanBuyAdditionalSeats = false,
|
||||
Name = "Family",
|
||||
StripePlanId = "personal-org-annually",
|
||||
StripeSeatPlanId = "personal-org-seat-annually",
|
||||
StripStoragePlanId = "storage-gb-annually",
|
||||
UpgradeSortOrder = 1,
|
||||
TrialPeriodDays = 7,
|
||||
UseTotp = true,
|
||||
MaxStorageGb = 1
|
||||
MaxStorageGb = 1,
|
||||
SelfHost = true
|
||||
},
|
||||
new Plan
|
||||
{
|
||||
@ -165,7 +163,8 @@ namespace Bit.Core.Utilities
|
||||
UseDirectory = true,
|
||||
UseTotp = true,
|
||||
MaxStorageGb = 1,
|
||||
SelfHost = true
|
||||
SelfHost = true,
|
||||
UsersGetPremium = true
|
||||
},
|
||||
new Plan
|
||||
{
|
||||
@ -184,7 +183,8 @@ namespace Bit.Core.Utilities
|
||||
UseDirectory = true,
|
||||
UseTotp = true,
|
||||
MaxStorageGb = 1,
|
||||
SelfHost = true
|
||||
SelfHost = true,
|
||||
UsersGetPremium = true
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
@UseDirectory BIT,
|
||||
@UseTotp BIT,
|
||||
@SelfHost BIT,
|
||||
@UsersGetPremium BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@Gateway TINYINT,
|
||||
@ -49,6 +50,7 @@ BEGIN
|
||||
[UseDirectory],
|
||||
[UseTotp],
|
||||
[SelfHost],
|
||||
[UsersGetPremium],
|
||||
[Storage],
|
||||
[MaxStorageGb],
|
||||
[Gateway],
|
||||
@ -79,6 +81,7 @@ BEGIN
|
||||
@UseDirectory,
|
||||
@UseTotp,
|
||||
@SelfHost,
|
||||
@UsersGetPremium,
|
||||
@Storage,
|
||||
@MaxStorageGb,
|
||||
@Gateway,
|
||||
|
@ -16,6 +16,7 @@
|
||||
@UseDirectory BIT,
|
||||
@UseTotp BIT,
|
||||
@SelfHost BIT,
|
||||
@UsersGetPremium BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@Gateway TINYINT,
|
||||
@ -26,7 +27,6 @@
|
||||
@ExpirationDate DATETIME2(7),
|
||||
@CreationDate DATETIME2(7),
|
||||
@RevisionDate DATETIME2(7)
|
||||
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@ -50,6 +50,7 @@ BEGIN
|
||||
[UseDirectory] = @UseDirectory,
|
||||
[UseTotp] = @UseTotp,
|
||||
[SelfHost] = @SelfHost,
|
||||
[UsersGetPremium] = @UsersGetPremium,
|
||||
[Storage] = @Storage,
|
||||
[MaxStorageGb] = @MaxStorageGb,
|
||||
[Gateway] = @Gateway,
|
||||
|
@ -16,6 +16,7 @@
|
||||
[UseDirectory] BIT NOT NULL,
|
||||
[UseTotp] BIT NOT NULL,
|
||||
[SelfHost] BIT NOT NULL,
|
||||
[UsersGetPremium] BIT NOT NULL,
|
||||
[Storage] BIGINT NULL,
|
||||
[MaxStorageGb] SMALLINT NULL,
|
||||
[Gateway] TINYINT NULL,
|
||||
|
@ -8,6 +8,8 @@ SELECT
|
||||
O.[UseGroups],
|
||||
O.[UseDirectory],
|
||||
O.[UseTotp],
|
||||
O.[SelfHost],
|
||||
O.[UsersGetPremium],
|
||||
O.[Seats],
|
||||
O.[MaxCollections],
|
||||
O.[MaxStorageGb],
|
||||
|
236
util/Setup/DbScripts/2017-11-06_00_FamilyPlanAdjustments.sql
Normal file
236
util/Setup/DbScripts/2017-11-06_00_FamilyPlanAdjustments.sql
Normal 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
|
@ -8,6 +8,7 @@
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="DbScripts\2017-11-06_00_FamilyPlanAdjustments.sql" />
|
||||
<EmbeddedResource Include="DbScripts\2017-10-25_00_OrgUserUpdates.sql" />
|
||||
<EmbeddedResource Include="DbScripts\2017-09-08_00_OrgUserCounts.sql" />
|
||||
<EmbeddedResource Include="DbScripts\2017-09-06_00_CipherDetails.sql" />
|
||||
|
Loading…
Reference in New Issue
Block a user