mirror of
https://github.com/bitwarden/server.git
synced 2025-07-10 12:24:50 -05:00
Sso user table, model and repo stubbed out (#837)
* Sso user table, model and repo stubbed out * switch to nullable org id, bigint id * update GetBySsoUserAsync * cleanup migrator file * fix EF user repo * fix pg repo * is `IS NULL` checks * unique indexes * update migration scripts * add another unique index * remove old script
This commit is contained in:
@ -269,5 +269,11 @@
|
||||
<Build Include="dbo\Stored Procedures\Policy_ReadByUserId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Cipher_Restore.sql" />
|
||||
<Build Include="dbo\Stored Procedures\Cipher_SoftDelete.sql" />
|
||||
<Build Include="dbo\Tables\SsoUser.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SsoUser_Delete.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SsoUser_Create.sql" />
|
||||
<Build Include="dbo\Stored Procedures\User_ReadBySsoUserOrganizationIdExternalId.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SsoUser_Update.sql" />
|
||||
<Build Include="dbo\Stored Procedures\SsoUser_ReadById.sql" />
|
||||
</ItemGroup>
|
||||
</Project>
|
27
src/Sql/dbo/Stored Procedures/SsoUser_Create.sql
Normal file
27
src/Sql/dbo/Stored Procedures/SsoUser_Create.sql
Normal file
@ -0,0 +1,27 @@
|
||||
CREATE PROCEDURE [dbo].[SsoUser_Create]
|
||||
@Id BIGINT OUTPUT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ExternalId NVARCHAR(50),
|
||||
@CreationDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
INSERT INTO [dbo].[SsoUser]
|
||||
(
|
||||
[UserId],
|
||||
[OrganizationId],
|
||||
[ExternalId],
|
||||
[CreationDate]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@UserId,
|
||||
@OrganizationId,
|
||||
@ExternalId,
|
||||
@CreationDate
|
||||
)
|
||||
|
||||
SET @Id = SCOPE_IDENTITY();
|
||||
END
|
14
src/Sql/dbo/Stored Procedures/SsoUser_Delete.sql
Normal file
14
src/Sql/dbo/Stored Procedures/SsoUser_Delete.sql
Normal file
@ -0,0 +1,14 @@
|
||||
CREATE PROCEDURE [dbo].[SsoUser_Delete]
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[SsoUser]
|
||||
WHERE
|
||||
[UserId] = @UserId
|
||||
AND [OrganizationId] = @OrganizationId
|
||||
END
|
13
src/Sql/dbo/Stored Procedures/SsoUser_ReadById.sql
Normal file
13
src/Sql/dbo/Stored Procedures/SsoUser_ReadById.sql
Normal file
@ -0,0 +1,13 @@
|
||||
CREATE PROCEDURE [dbo].[SsoUser_ReadById]
|
||||
@Id BIGINT
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
*
|
||||
FROM
|
||||
[dbo].[SsoUserView]
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
20
src/Sql/dbo/Stored Procedures/SsoUser_Update.sql
Normal file
20
src/Sql/dbo/Stored Procedures/SsoUser_Update.sql
Normal file
@ -0,0 +1,20 @@
|
||||
CREATE PROCEDURE [dbo].[SsoUser_Update]
|
||||
@Id BIGINT OUTPUT,
|
||||
@UserId UNIQUEIDENTIFIER,
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ExternalId NVARCHAR(50),
|
||||
@CreationDate DATETIME2(7)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
UPDATE
|
||||
[dbo].[SsoUser]
|
||||
SET
|
||||
[UserId] = @UserId,
|
||||
[OrganizationId] = @OrganizationId,
|
||||
[ExternalId] = @ExternalId,
|
||||
[CreationDate] = @CreationDate
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
@ -0,0 +1,20 @@
|
||||
CREATE PROCEDURE [dbo].[User_ReadBySsoUserOrganizationIdExternalId]
|
||||
@OrganizationId UNIQUEIDENTIFIER,
|
||||
@ExternalId NVARCHAR(50)
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
|
||||
SELECT
|
||||
U.*
|
||||
FROM
|
||||
[dbo].[UserView] U
|
||||
INNER JOIN
|
||||
[dbo].[SsoUser] SU ON SU.[UserId] = U.[Id]
|
||||
WHERE
|
||||
(
|
||||
(@OrganizationId IS NULL AND SU.[OrganizationId] IS NULL)
|
||||
OR (@OrganizationId IS NOT NULL AND SU.[OrganizationId] = @OrganizationId)
|
||||
)
|
||||
AND SU.[ExternalId] = @ExternalId
|
||||
END
|
22
src/Sql/dbo/Tables/SsoUser.sql
Normal file
22
src/Sql/dbo/Tables/SsoUser.sql
Normal file
@ -0,0 +1,22 @@
|
||||
CREATE TABLE [dbo].[SsoUser] (
|
||||
[Id] BIGINT IDENTITY (1, 1) NOT NULL,
|
||||
[UserId] UNIQUEIDENTIFIER NOT NULL,
|
||||
[OrganizationId] UNIQUEIDENTIFIER NULL,
|
||||
[ExternalId] NVARCHAR(50) NOT NULL,
|
||||
[CreationDate] DATETIME2 (7) NOT NULL,
|
||||
CONSTRAINT [PK_SsoUser] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_SsoUser_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]) ON DELETE CASCADE,
|
||||
CONSTRAINT [FK_SsoUser_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id])
|
||||
);
|
||||
|
||||
|
||||
GO
|
||||
CREATE UNIQUE NONCLUSTERED INDEX [IX_SsoUser_OrganizationIdExternalId]
|
||||
ON [dbo].[SsoUser]([OrganizationId] ASC, [ExternalId] ASC)
|
||||
INCLUDE ([UserId]);
|
||||
|
||||
GO
|
||||
CREATE UNIQUE NONCLUSTERED INDEX [IX_SsoUser_OrganizationIdUserId]
|
||||
ON [dbo].[SsoUser]([OrganizationId] ASC, [UserId] ASC);
|
||||
|
||||
|
Reference in New Issue
Block a user