mirror of
https://github.com/bitwarden/server.git
synced 2025-04-05 21:18:13 -05:00
db changes for org api
This commit is contained in:
parent
92d686ba36
commit
c4ac86d4f4
@ -17,6 +17,7 @@
|
||||
@UseEvents BIT,
|
||||
@UseTotp BIT,
|
||||
@Use2fa BIT,
|
||||
@UseApi BIT,
|
||||
@SelfHost BIT,
|
||||
@UsersGetPremium BIT,
|
||||
@Storage BIGINT,
|
||||
@ -26,6 +27,7 @@
|
||||
@GatewaySubscriptionId VARCHAR(50),
|
||||
@Enabled BIT,
|
||||
@LicenseKey VARCHAR(100),
|
||||
@ApiKey VARCHAR(30),
|
||||
@TwoFactorProviders NVARCHAR(MAX),
|
||||
@ExpirationDate DATETIME2(7),
|
||||
@CreationDate DATETIME2(7),
|
||||
@ -54,6 +56,7 @@ BEGIN
|
||||
[UseEvents],
|
||||
[UseTotp],
|
||||
[Use2fa],
|
||||
[UseApi],
|
||||
[SelfHost],
|
||||
[UsersGetPremium],
|
||||
[Storage],
|
||||
@ -63,6 +66,7 @@ BEGIN
|
||||
[GatewaySubscriptionId],
|
||||
[Enabled],
|
||||
[LicenseKey],
|
||||
[ApiKey],
|
||||
[TwoFactorProviders],
|
||||
[ExpirationDate],
|
||||
[CreationDate],
|
||||
@ -88,6 +92,7 @@ BEGIN
|
||||
@UseEvents,
|
||||
@UseTotp,
|
||||
@Use2fa,
|
||||
@UseApi,
|
||||
@SelfHost,
|
||||
@UsersGetPremium,
|
||||
@Storage,
|
||||
@ -97,6 +102,7 @@ BEGIN
|
||||
@GatewaySubscriptionId,
|
||||
@Enabled,
|
||||
@LicenseKey,
|
||||
@ApiKey,
|
||||
@TwoFactorProviders,
|
||||
@ExpirationDate,
|
||||
@CreationDate,
|
||||
|
@ -17,6 +17,7 @@
|
||||
@UseEvents BIT,
|
||||
@UseTotp BIT,
|
||||
@Use2fa BIT,
|
||||
@UseApi BIT,
|
||||
@SelfHost BIT,
|
||||
@UsersGetPremium BIT,
|
||||
@Storage BIGINT,
|
||||
@ -26,6 +27,7 @@
|
||||
@GatewaySubscriptionId VARCHAR(50),
|
||||
@Enabled BIT,
|
||||
@LicenseKey VARCHAR(100),
|
||||
@ApiKey VARCHAR(30),
|
||||
@TwoFactorProviders NVARCHAR(MAX),
|
||||
@ExpirationDate DATETIME2(7),
|
||||
@CreationDate DATETIME2(7),
|
||||
@ -54,6 +56,7 @@ BEGIN
|
||||
[UseEvents] = @UseEvents,
|
||||
[UseTotp] = @UseTotp,
|
||||
[Use2fa] = @Use2fa,
|
||||
[UseApi] = @UseApi,
|
||||
[SelfHost] = @SelfHost,
|
||||
[UsersGetPremium] = @UsersGetPremium,
|
||||
[Storage] = @Storage,
|
||||
@ -63,6 +66,7 @@ BEGIN
|
||||
[GatewaySubscriptionId] = @GatewaySubscriptionId,
|
||||
[Enabled] = @Enabled,
|
||||
[LicenseKey] = @LicenseKey,
|
||||
[ApiKey] = @ApiKey,
|
||||
[TwoFactorProviders] = @TwoFactorProviders,
|
||||
[ExpirationDate] = @ExpirationDate,
|
||||
[CreationDate] = @CreationDate,
|
||||
|
@ -17,6 +17,7 @@
|
||||
[UseEvents] BIT NOT NULL,
|
||||
[UseTotp] BIT NOT NULL,
|
||||
[Use2fa] BIT NOT NULL,
|
||||
[UseApi] BIT NOT NULL,
|
||||
[SelfHost] BIT NOT NULL,
|
||||
[UsersGetPremium] BIT NOT NULL,
|
||||
[Storage] BIGINT NULL,
|
||||
@ -26,6 +27,7 @@
|
||||
[GatewaySubscriptionId] VARCHAR (50) NULL,
|
||||
[Enabled] BIT NOT NULL,
|
||||
[LicenseKey] VARCHAR (100) NULL,
|
||||
[ApiKey] VARCHAR (30) NOT NULL,
|
||||
[TwoFactorProviders] NVARCHAR (MAX) NULL,
|
||||
[ExpirationDate] DATETIME2 (7) NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
|
@ -10,6 +10,7 @@ SELECT
|
||||
O.[UseEvents],
|
||||
O.[UseTotp],
|
||||
O.[Use2fa],
|
||||
O.[UseApi],
|
||||
O.[SelfHost],
|
||||
O.[UsersGetPremium],
|
||||
O.[Seats],
|
||||
|
339
util/Setup/DbScripts/2019-03-01_00_OrgApi.sql
Normal file
339
util/Setup/DbScripts/2019-03-01_00_OrgApi.sql
Normal file
@ -0,0 +1,339 @@
|
||||
-- Setup for random string generation
|
||||
|
||||
CREATE VIEW [dbo].[SecureRandomBytes]
|
||||
AS
|
||||
SELECT [RandBytes] = CRYPT_GEN_RANDOM(2)
|
||||
GO
|
||||
|
||||
CREATE FUNCTION [dbo].[SecureRandomString]()
|
||||
RETURNS varchar(30)
|
||||
AS
|
||||
BEGIN
|
||||
declare @sLength tinyint
|
||||
declare @randomString varchar(30)
|
||||
declare @counter tinyint
|
||||
declare @nextChar char(1)
|
||||
declare @rnd as float
|
||||
declare @bytes binary(2)
|
||||
|
||||
set @sLength = 30
|
||||
set @counter = 1
|
||||
set @randomString = ''
|
||||
|
||||
while @counter <= @sLength
|
||||
begin
|
||||
select @bytes = [RandBytes] from [dbo].[SecureRandomBytes]
|
||||
select @rnd = cast(cast(cast(@bytes as int) as float) / 65535 as float)
|
||||
select @nextChar = char(48 + convert(int, (122-48+1) * @rnd))
|
||||
if ascii(@nextChar) not in (58,59,60,61,62,63,64,91,92,93,94,95,96)
|
||||
begin
|
||||
select @randomString = @randomString + @nextChar
|
||||
set @counter = @counter + 1
|
||||
end
|
||||
end
|
||||
return @randomString
|
||||
END
|
||||
GO
|
||||
|
||||
-- End setup
|
||||
|
||||
IF COL_LENGTH('[dbo].[Organization]', 'UseApi') IS NULL
|
||||
BEGIN
|
||||
ALTER TABLE
|
||||
[dbo].[Organization]
|
||||
ADD
|
||||
[UseApi] BIT NULL
|
||||
END
|
||||
GO
|
||||
|
||||
UPDATE
|
||||
[dbo].[Organization]
|
||||
SET
|
||||
[UseApi] = (CASE WHEN [PlanType] = 5 OR [PlanType] = 4 THEN 1 ELSE 0 END)
|
||||
GO
|
||||
|
||||
ALTER TABLE
|
||||
[dbo].[Organization]
|
||||
ALTER COLUMN
|
||||
[UseApi] BIT NOT NULL
|
||||
GO
|
||||
|
||||
IF COL_LENGTH('[dbo].[Organization]', 'ApiKey') IS NULL
|
||||
BEGIN
|
||||
ALTER TABLE
|
||||
[dbo].[Organization]
|
||||
ADD
|
||||
[ApiKey] VARCHAR(30) NULL
|
||||
END
|
||||
GO
|
||||
|
||||
UPDATE
|
||||
[dbo].[Organization]
|
||||
SET
|
||||
[ApiKey] = (SELECT [dbo].[SecureRandomString]())
|
||||
GO
|
||||
|
||||
ALTER TABLE
|
||||
[dbo].[Organization]
|
||||
ALTER COLUMN
|
||||
[ApiKey] VARCHAR(30) NOT NULL
|
||||
GO
|
||||
|
||||
-- Cleanup random string generation
|
||||
|
||||
DROP VIEW [dbo].[SecureRandomBytes]
|
||||
GO
|
||||
DROP FUNCTION [dbo].[SecureRandomString]
|
||||
GO
|
||||
|
||||
-- End
|
||||
|
||||
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,
|
||||
@Use2fa BIT,
|
||||
@UseApi BIT,
|
||||
@SelfHost BIT,
|
||||
@UsersGetPremium BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@Gateway TINYINT,
|
||||
@GatewayCustomerId VARCHAR(50),
|
||||
@GatewaySubscriptionId VARCHAR(50),
|
||||
@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],
|
||||
[Name],
|
||||
[BusinessName],
|
||||
[BusinessAddress1],
|
||||
[BusinessAddress2],
|
||||
[BusinessAddress3],
|
||||
[BusinessCountry],
|
||||
[BusinessTaxNumber],
|
||||
[BillingEmail],
|
||||
[Plan],
|
||||
[PlanType],
|
||||
[Seats],
|
||||
[MaxCollections],
|
||||
[UseGroups],
|
||||
[UseDirectory],
|
||||
[UseEvents],
|
||||
[UseTotp],
|
||||
[Use2fa],
|
||||
[UseApi],
|
||||
[SelfHost],
|
||||
[UsersGetPremium],
|
||||
[Storage],
|
||||
[MaxStorageGb],
|
||||
[Gateway],
|
||||
[GatewayCustomerId],
|
||||
[GatewaySubscriptionId],
|
||||
[Enabled],
|
||||
[LicenseKey],
|
||||
[ApiKey],
|
||||
[TwoFactorProviders],
|
||||
[ExpirationDate],
|
||||
[CreationDate],
|
||||
[RevisionDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@Name,
|
||||
@BusinessName,
|
||||
@BusinessAddress1,
|
||||
@BusinessAddress2,
|
||||
@BusinessAddress3,
|
||||
@BusinessCountry,
|
||||
@BusinessTaxNumber,
|
||||
@BillingEmail,
|
||||
@Plan,
|
||||
@PlanType,
|
||||
@Seats,
|
||||
@MaxCollections,
|
||||
@UseGroups,
|
||||
@UseDirectory,
|
||||
@UseEvents,
|
||||
@UseTotp,
|
||||
@Use2fa,
|
||||
@UseApi,
|
||||
@SelfHost,
|
||||
@UsersGetPremium,
|
||||
@Storage,
|
||||
@MaxStorageGb,
|
||||
@Gateway,
|
||||
@GatewayCustomerId,
|
||||
@GatewaySubscriptionId,
|
||||
@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,
|
||||
@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,
|
||||
@Use2fa BIT,
|
||||
@UseApi BIT,
|
||||
@SelfHost BIT,
|
||||
@UsersGetPremium BIT,
|
||||
@Storage BIGINT,
|
||||
@MaxStorageGb SMALLINT,
|
||||
@Gateway TINYINT,
|
||||
@GatewayCustomerId VARCHAR(50),
|
||||
@GatewaySubscriptionId VARCHAR(50),
|
||||
@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
|
||||
[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,
|
||||
[Use2fa] = @Use2fa,
|
||||
[UseApi] = @UseApi,
|
||||
[SelfHost] = @SelfHost,
|
||||
[UsersGetPremium] = @UsersGetPremium,
|
||||
[Storage] = @Storage,
|
||||
[MaxStorageGb] = @MaxStorageGb,
|
||||
[Gateway] = @Gateway,
|
||||
[GatewayCustomerId] = @GatewayCustomerId,
|
||||
[GatewaySubscriptionId] = @GatewaySubscriptionId,
|
||||
[Enabled] = @Enabled,
|
||||
[LicenseKey] = @LicenseKey,
|
||||
[ApiKey] = @ApiKey,
|
||||
[TwoFactorProviders] = @TwoFactorProviders,
|
||||
[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.[Use2fa],
|
||||
O.[UseApi],
|
||||
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
|
@ -12,13 +12,6 @@
|
||||
<EmbeddedResource Include="Templates\**\*.hbs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="DbScripts\2018-09-25_00_OrgPurge.sql" />
|
||||
<None Remove="DbScripts\2018-10-17_00_ManagerRole.sql" />
|
||||
<None Remove="DbScripts\2018-12-19_00_OrgUserTwoFactorEnabled.sql" />
|
||||
<None Remove="DbScripts\2019-01-31_00_Transactions.sql" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Handlebars.Net" Version="1.9.5" />
|
||||
<PackageReference Include="System.Data.SqlClient" Version="4.5.1" />
|
||||
|
Loading…
x
Reference in New Issue
Block a user