mirror of
https://github.com/bitwarden/server
synced 2026-01-09 03:53:42 +00:00
Merge branch 'master' into feature/billing-obfuscation
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
CREATE PROCEDURE [dbo].[ApiKey_DeleteByIds]
|
||||
@Ids [dbo].[GuidIdArray] READONLY
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @BatchSize INT = 100
|
||||
|
||||
WHILE @BatchSize > 0
|
||||
BEGIN
|
||||
BEGIN TRANSACTION ApiKey_DeleteMany
|
||||
|
||||
DELETE TOP(@BatchSize) AK
|
||||
FROM
|
||||
[dbo].[ApiKey] AK
|
||||
INNER JOIN
|
||||
@Ids I ON I.Id = AK.Id
|
||||
|
||||
SET @BatchSize = @@ROWCOUNT
|
||||
|
||||
COMMIT TRANSACTION ApiKey_DeleteMany
|
||||
END
|
||||
END
|
||||
@@ -128,22 +128,29 @@
|
||||
<Build Include="dbo\Stored Procedures\CollectionGroup_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CollectionUser_Delete.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CollectionUser_ReadByCollectionId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CollectionUser_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CollectionUser_ReadByOrganizationUserIds.sql" />
|
||||
<Build Include="dbo\Stored Procedures\CollectionUser_UpdateUsers.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_Create.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_CreateWithGroups.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_CreateWithGroupsAndUsers.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_DeleteById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_DeleteByIds.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadByIdUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadByIds.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadCountByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsAndUsersById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsAndUsersByIdUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsAndUsersByOrganizationId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsAndUsersByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_ReadWithGroupsByIdUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_UpdateWithGroups.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Collection_UpdateWithGroupsAndUsers.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Device_ClearPushTokenById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Device_Create.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Device_DeleteById.sql" />
|
||||
@@ -438,6 +445,7 @@
|
||||
<Build Include="dbo\Views\UserView.sql" />
|
||||
<Build Include="SecretsManager\dbo\Stored Procedures\ApiKey\ApiKeyDetails_ReadById.sql" />
|
||||
<Build Include="SecretsManager\dbo\Stored Procedures\ApiKey\ApiKey_Create.sql" />
|
||||
<Build Include="SecretsManager\dbo\Stored Procedures\ApiKey\ApiKey_DeleteByIds.sql" />
|
||||
<Build Include="SecretsManager\dbo\Stored Procedures\ApiKey\ApiKey_ReadByServiceAccountId.sql" />
|
||||
<Build Include="SecretsManager\dbo\Tables\AccessPolicy.sql" />
|
||||
<Build Include="SecretsManager\dbo\Tables\ApiKey.sql" />
|
||||
@@ -447,5 +455,24 @@
|
||||
<Build Include="SecretsManager\dbo\Tables\ServiceAccount.sql" />
|
||||
<Build Include="SecretsManager\dbo\Views\ApiKeyDetailsView.sql" />
|
||||
<Build Include="SecretsManager\dbo\Views\ApiKeyView.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_ReadByLicenseKey.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Organization_ReadSelfHostedDetailsById.sql" />
|
||||
<Build Include="dbo\Stored Procedures\OrganizationUser_ReadOccupiedSeatCountByOrganizationId.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
<ItemGroup>
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_Create.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_DeleteById.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_DeleteIfExpired.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_OrganizationDeleted.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_ReadByClaimedDomain.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_ReadByNextRunDate.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_ReadById.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_ReadByOrganizationId.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_ReadDomainByOrgIdAndDomainName.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_ReadIfExpired.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomain_Update.sql" />
|
||||
<Content Include="dbo\Stored Procedures\OrganizationDomainSsoDetails_ReadByEmail.sql" />
|
||||
<Content Include="dbo\Tables\OrganizationDomain.sql" />
|
||||
<Content Include="dbo\Views\OrganizationDomainView.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
||||
@@ -16,7 +16,10 @@
|
||||
@DeviceType SMALLINT,
|
||||
@IpAddress VARCHAR(50),
|
||||
@Date DATETIME2(7),
|
||||
@SystemUser TINYINT = null
|
||||
@SystemUser TINYINT = null,
|
||||
@DomainName VARCHAR(256),
|
||||
@SecretId UNIQUEIDENTIFIER = null,
|
||||
@ServiceAccountId UNIQUEIDENTIFIER = null
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@@ -40,7 +43,10 @@ BEGIN
|
||||
[DeviceType],
|
||||
[IpAddress],
|
||||
[Date],
|
||||
[SystemUser]
|
||||
[SystemUser],
|
||||
[DomainName],
|
||||
[SecretId],
|
||||
[ServiceAccountId]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@@ -61,6 +67,9 @@ BEGIN
|
||||
@DeviceType,
|
||||
@IpAddress,
|
||||
@Date,
|
||||
@SystemUser
|
||||
@SystemUser,
|
||||
@DomainName,
|
||||
@SecretId,
|
||||
@ServiceAccountId
|
||||
)
|
||||
END
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
CREATE PROCEDURE [dbo].[Event_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[Event]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[Group_ReadCountByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
[dbo].[Group]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
END
|
||||
@@ -0,0 +1,31 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomainSsoDetails_ReadByEmail]
|
||||
@Email NVARCHAR(256)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DECLARE @Domain NVARCHAR(256)
|
||||
|
||||
SELECT @Domain = SUBSTRING(@Email, CHARINDEX( '@', @Email) + 1, LEN(@Email))
|
||||
|
||||
SELECT
|
||||
O.Id AS OrganizationId,
|
||||
O.[Name] AS OrganizationName,
|
||||
S.Enabled AS SsoAvailable,
|
||||
P.Enabled AS SsoRequired,
|
||||
O.Identifier AS OrganizationIdentifier,
|
||||
OD.VerifiedDate,
|
||||
P.[Type] AS PolicyType,
|
||||
OD.DomainName
|
||||
FROM
|
||||
[dbo].[OrganizationView] O
|
||||
INNER JOIN [dbo].[OrganizationDomainView] OD
|
||||
ON O.Id = OD.OrganizationId
|
||||
LEFT JOIN [dbo].[PolicyView] P
|
||||
ON O.Id = P.OrganizationId
|
||||
LEFT JOIN [dbo].[Ssoconfig] S
|
||||
ON O.Id = S.OrganizationId
|
||||
WHERE OD.DomainName = @Domain
|
||||
AND O.Enabled = 1
|
||||
AND (P.Id is NULL OR (P.Id IS NOT NULL AND P.[Type] = 4)) -- SSO Type
|
||||
END
|
||||
39
src/Sql/dbo/Stored Procedures/OrganizationDomain_Create.sql
Normal file
39
src/Sql/dbo/Stored Procedures/OrganizationDomain_Create.sql
Normal file
@@ -0,0 +1,39 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Txt VARCHAR(MAX),
|
||||
@DomainName NVARCHAR(255),
|
||||
@CreationDate DATETIME2(7),
|
||||
@VerifiedDate DATETIME2(7),
|
||||
@LastCheckedDate DATETIME2(7),
|
||||
@NextRunDate DATETIME2(7),
|
||||
@JobRunCount TINYINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[OrganizationDomain]
|
||||
(
|
||||
[Id],
|
||||
[OrganizationId],
|
||||
[Txt],
|
||||
[DomainName],
|
||||
[CreationDate],
|
||||
[VerifiedDate],
|
||||
[LastCheckedDate],
|
||||
[NextRunDate],
|
||||
[JobRunCount]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@Id,
|
||||
@OrganizationId,
|
||||
@Txt,
|
||||
@DomainName,
|
||||
@CreationDate,
|
||||
@VerifiedDate,
|
||||
@LastCheckedDate,
|
||||
@NextRunDate,
|
||||
@JobRunCount
|
||||
)
|
||||
END
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_DeleteById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
@@ -0,0 +1,10 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_DeleteIfExpired]
|
||||
@ExpirationPeriod TINYINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT OFF
|
||||
|
||||
DELETE FROM [dbo].[OrganizationDomain]
|
||||
WHERE DATEDIFF(DAY, [LastCheckedDate], GETUTCDATE()) >= @ExpirationPeriod
|
||||
AND [VerifiedDate] IS NULL
|
||||
END
|
||||
@@ -0,0 +1,12 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_OrganizationDeleted]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
END
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_ReadByClaimedDomain]
|
||||
@DomainName NVARCHAR(255)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
[DomainName] = @DomainName
|
||||
AND
|
||||
[VerifiedDate] IS NOT NULL
|
||||
END
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_ReadById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
@@ -0,0 +1,25 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_ReadByNextRunDate]
|
||||
@Date DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE [VerifiedDate] IS NULL
|
||||
AND [JobRunCount] != 3
|
||||
AND DATEPART(year, [NextRunDate]) = DATEPART(year, @Date)
|
||||
AND DATEPART(month, [NextRunDate]) = DATEPART(month, @Date)
|
||||
AND DATEPART(day, [NextRunDate]) = DATEPART(day, @Date)
|
||||
AND DATEPART(hour, [NextRunDate]) = DATEPART(hour, @Date)
|
||||
UNION
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE DATEDIFF(hour, [NextRunDate], @Date) > 36
|
||||
AND [VerifiedDate] IS NULL
|
||||
AND [JobRunCount] != 3
|
||||
END
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_ReadByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
END
|
||||
@@ -0,0 +1,16 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_ReadDomainByOrgIdAndDomainName]
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@DomainName NVARCHAR(255)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
[OrganizationId] = @OrganizationId
|
||||
AND
|
||||
[DomainName] = @DomainName
|
||||
END
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_ReadIfExpired]
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT OFF
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
WHERE
|
||||
DATEDIFF(DAY, [CreationDate], GETUTCDATE()) = 4 --Get domains that have not been verified after 3 days (72 hours)
|
||||
AND
|
||||
[VerifiedDate] IS NULL
|
||||
END
|
||||
28
src/Sql/dbo/Stored Procedures/OrganizationDomain_Update.sql
Normal file
28
src/Sql/dbo/Stored Procedures/OrganizationDomain_Update.sql
Normal file
@@ -0,0 +1,28 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationDomain_Update]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@Txt VARCHAR(MAX),
|
||||
@DomainName NVARCHAR(255),
|
||||
@CreationDate DATETIME2(7),
|
||||
@VerifiedDate DATETIME2(7),
|
||||
@LastCheckedDate DATETIME2(7),
|
||||
@NextRunDate DATETIME2(7),
|
||||
@JobRunCount TINYINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[OrganizationDomain]
|
||||
SET
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[Txt] = @Txt,
|
||||
[DomainName] = @DomainName,
|
||||
[CreationDate] = @CreationDate,
|
||||
[VerifiedDate] = @VerifiedDate,
|
||||
[LastCheckedDate] = @LastCheckedDate
|
||||
[NextRunDate] = @NextRunDate,
|
||||
[JobRunCount] = @JobRunCount
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
@@ -0,0 +1,14 @@
|
||||
CREATE PROCEDURE [dbo].[OrganizationUser_ReadOccupiedSeatCountByOrganizationId]
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
COUNT(1)
|
||||
FROM
|
||||
[dbo].[OrganizationUserView]
|
||||
WHERE
|
||||
OrganizationId = @OrganizationId
|
||||
AND Status >= 0 --Invited
|
||||
END
|
||||
@@ -60,6 +60,7 @@ BEGIN
|
||||
EXEC [dbo].[OrganizationApiKey_OrganizationDeleted] @Id
|
||||
EXEC [dbo].[OrganizationConnection_OrganizationDeleted] @Id
|
||||
EXEC [dbo].[OrganizationSponsorship_OrganizationDeleted] @Id
|
||||
EXEC [dbo].[OrganizationDomain_OrganizationDeleted] @Id
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[Organization_ReadByLicenseKey]
|
||||
@LicenseKey VARCHAR (100)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationView]
|
||||
WHERE
|
||||
[LicenseKey] = @LicenseKey
|
||||
END
|
||||
@@ -0,0 +1,15 @@
|
||||
CREATE PROCEDURE [dbo].[Organization_ReadSelfHostedDetailsById]
|
||||
@Id UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
EXEC [dbo].[Organization_ReadById] @Id
|
||||
EXEC [dbo].[OrganizationUser_ReadOccupiedSeatCountByOrganizationId] @Id
|
||||
EXEC [dbo].[Collection_ReadCountByOrganizationId] @Id
|
||||
EXEC [dbo].[Group_ReadCountByOrganizationId] @Id
|
||||
EXEC [dbo].[OrganizationUser_ReadByOrganizationId] @Id, NULL
|
||||
EXEC [dbo].[Policy_ReadByOrganizationId] @Id
|
||||
EXEC [dbo].[SsoConfig_ReadByOrganizationId] @Id
|
||||
EXEC [dbo].[OrganizationConnection_ReadByOrganizationIdType] @Id, 2 --Scim connection type
|
||||
END
|
||||
@@ -17,6 +17,9 @@
|
||||
[ProviderUserId] UNIQUEIDENTIFIER NULL,
|
||||
[ProviderOrganizationId] UNIQUEIDENTIFIER NULL,
|
||||
[SystemUser] TINYINT NULL,
|
||||
[DomainName] VARCHAR(256) NULL,
|
||||
[SecretId] UNIQUEIDENTIFIER NULL,
|
||||
[ServiceAccountId] UNIQUEIDENTIFIER NULL,
|
||||
CONSTRAINT [PK_Event] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
);
|
||||
|
||||
|
||||
15
src/Sql/dbo/Tables/OrganizationDomain.sql
Normal file
15
src/Sql/dbo/Tables/OrganizationDomain.sql
Normal file
@@ -0,0 +1,15 @@
|
||||
CREATE TABLE [dbo].[OrganizationDomain] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Txt] VARCHAR(MAX) NOT NULL,
|
||||
[DomainName] NVARCHAR(255) NOT NULL,
|
||||
[CreationDate] DATETIME2(7) NOT NULL,
|
||||
[VerifiedDate] DATETIME2(7) NULL,
|
||||
[LastCheckedDate] DATETIME2(7) NULL,
|
||||
[NextRunDate] DATETIME2(7) NOT NULL,
|
||||
[JobRunCount] TINYINT NOT NULL
|
||||
CONSTRAINT [PK_OrganizationDomain] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_OrganzationDomain_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
|
||||
);
|
||||
|
||||
GO
|
||||
6
src/Sql/dbo/Views/OrganizationDomainView.sql
Normal file
6
src/Sql/dbo/Views/OrganizationDomainView.sql
Normal file
@@ -0,0 +1,6 @@
|
||||
CREATE VIEW [dbo].[OrganizationDomainView]
|
||||
AS
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[OrganizationDomain]
|
||||
@@ -6,6 +6,7 @@ SELECT
|
||||
OU.[OrganizationId],
|
||||
U.[Name],
|
||||
ISNULL(U.[Email], OU.[Email]) Email,
|
||||
U.[AvatarColor],
|
||||
U.[TwoFactorProviders],
|
||||
U.[Premium],
|
||||
OU.[Status],
|
||||
|
||||
120
src/Sql/dbo_future/Stored Procedures/User_Create.sql
Normal file
120
src/Sql/dbo_future/Stored Procedures/User_Create.sql
Normal file
@@ -0,0 +1,120 @@
|
||||
CREATE PROCEDURE [dbo].[User_Create]
|
||||
@Id UNIQUEIDENTIFIER OUTPUT,
|
||||
@Name NVARCHAR(50),
|
||||
@Email NVARCHAR(256),
|
||||
@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),
|
||||
@ApiKey VARCHAR(30),
|
||||
@ForcePasswordReset BIT = 0,
|
||||
@UsesKeyConnector BIT = 0,
|
||||
@FailedLoginCount INT = 0,
|
||||
@LastFailedLoginDate DATETIME2(7),
|
||||
@AvatarColor VARCHAR(7) = NULL
|
||||
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],
|
||||
[ApiKey],
|
||||
[ForcePasswordReset],
|
||||
[UsesKeyConnector],
|
||||
[FailedLoginCount],
|
||||
[LastFailedLoginDate],
|
||||
[AvatarColor]
|
||||
)
|
||||
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,
|
||||
@ApiKey,
|
||||
@ForcePasswordReset,
|
||||
@UsesKeyConnector,
|
||||
@FailedLoginCount,
|
||||
@LastFailedLoginDate,
|
||||
@AvatarColor
|
||||
)
|
||||
END
|
||||
82
src/Sql/dbo_future/Stored Procedures/User_Update.sql
Normal file
82
src/Sql/dbo_future/Stored Procedures/User_Update.sql
Normal file
@@ -0,0 +1,82 @@
|
||||
CREATE PROCEDURE [dbo].[User_Update]
|
||||
@Id UNIQUEIDENTIFIER,
|
||||
@Name NVARCHAR(50),
|
||||
@Email NVARCHAR(256),
|
||||
@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),
|
||||
@ApiKey VARCHAR(30),
|
||||
@ForcePasswordReset BIT = 0,
|
||||
@UsesKeyConnector BIT = 0,
|
||||
@FailedLoginCount INT,
|
||||
@LastFailedLoginDate DATETIME2(7),
|
||||
@AvatarColor VARCHAR(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,
|
||||
[ApiKey] = @ApiKey,
|
||||
[ForcePasswordReset] = @ForcePasswordReset,
|
||||
[UsesKeyConnector] = @UsesKeyConnector,
|
||||
[FailedLoginCount] = @FailedLoginCount,
|
||||
[LastFailedLoginDate] = @LastFailedLoginDate,
|
||||
[AvatarColor] = @AvatarColor
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
49
src/Sql/dbo_future/Tables/User.sql
Normal file
49
src/Sql/dbo_future/Tables/User.sql
Normal file
@@ -0,0 +1,49 @@
|
||||
CREATE TABLE [dbo].[User] (
|
||||
[Id] UNIQUEIDENTIFIER NOT NULL,
|
||||
[Name] NVARCHAR (50) NULL,
|
||||
[Email] NVARCHAR (256) NOT NULL,
|
||||
[EmailVerified] BIT NOT NULL,
|
||||
[MasterPassword] NVARCHAR (300) NULL,
|
||||
[MasterPasswordHint] NVARCHAR (50) NULL,
|
||||
[Culture] NVARCHAR (10) NOT NULL,
|
||||
[SecurityStamp] NVARCHAR (50) NOT NULL,
|
||||
[TwoFactorProviders] NVARCHAR (MAX) NULL,
|
||||
[TwoFactorRecoveryCode] NVARCHAR (32) NULL,
|
||||
[EquivalentDomains] NVARCHAR (MAX) NULL,
|
||||
[ExcludedGlobalEquivalentDomains] NVARCHAR (MAX) NULL,
|
||||
[AccountRevisionDate] DATETIME2 (7) NOT NULL,
|
||||
[Key] VARCHAR (MAX) NULL,
|
||||
[PublicKey] VARCHAR (MAX) NULL,
|
||||
[PrivateKey] VARCHAR (MAX) NULL,
|
||||
[Premium] BIT NOT NULL,
|
||||
[PremiumExpirationDate] DATETIME2 (7) NULL,
|
||||
[RenewalReminderDate] DATETIME2 (7) NULL,
|
||||
[Storage] BIGINT NULL,
|
||||
[MaxStorageGb] SMALLINT NULL,
|
||||
[Gateway] TINYINT NULL,
|
||||
[GatewayCustomerId] VARCHAR (50) NULL,
|
||||
[GatewaySubscriptionId] VARCHAR (50) NULL,
|
||||
[ReferenceData] NVARCHAR (MAX) NULL,
|
||||
[LicenseKey] VARCHAR (100) NULL,
|
||||
[Kdf] TINYINT NOT NULL,
|
||||
[KdfIterations] INT NOT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
[RevisionDate] DATETIME2 (7) NOT NULL,
|
||||
[ApiKey] VARCHAR (30) NOT NULL,
|
||||
[ForcePasswordReset] BIT NOT NULL,
|
||||
[UsesKeyConnector] BIT NOT NULL,
|
||||
[FailedLoginCount] INT CONSTRAINT [D_User_FailedLoginCount] DEFAULT ((0)) NOT NULL,
|
||||
[LastFailedLoginDate] DATETIME2 (7) NULL,
|
||||
[AvatarColor] VARCHAR(7) NULL,
|
||||
CONSTRAINT [PK_User] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
);
|
||||
|
||||
|
||||
GO
|
||||
CREATE UNIQUE NONCLUSTERED INDEX [IX_User_Email]
|
||||
ON [dbo].[User]([Email] ASC);
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_User_Premium_PremiumExpirationDate_RenewalReminderDate]
|
||||
ON [dbo].[User]([Premium] ASC, [PremiumExpirationDate] ASC, [RenewalReminderDate] ASC);
|
||||
|
||||
Reference in New Issue
Block a user