mirror of
https://github.com/bitwarden/server
synced 2026-01-08 11:33:26 +00:00
[PM-17830] Backend changes for admin initiated sponsorships (#5531)
* WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * WIP * Add `Notes` column to `OrganizationSponsorships` table * Add feature flag to `CreateAdminInitiatedSponsorshipHandler` * Unit tests for `CreateSponsorshipHandler` * More tests for `CreateSponsorshipHandler` * Forgot to add `Notes` column to `OrganizationSponsorships` table in the migration script * `CreateAdminInitiatedSponsorshipHandler` unit tests * Fix `CreateSponsorshipCommandTests` * Encrypt the notes field * Wrong business logic checking for invalid permissions. * Wrong business logic checking for invalid permissions. * Remove design patterns * duplicate definition in Constants.cs * Allow rollback * Fix stored procedures & type * Fix stored procedures & type * Properly encapsulating this PR behind its feature flag * Removed comments * Updated ValidateSponsorshipCommand to validate admin initiated requirements --------- Co-authored-by: Conner Turnbull <133619638+cturnbull-bitwarden@users.noreply.github.com> Co-authored-by: Conner Turnbull <cturnbull@bitwarden.com>
This commit is contained in:
@@ -8,7 +8,9 @@ CREATE PROCEDURE [dbo].[OrganizationSponsorship_Create]
|
||||
@PlanSponsorshipType TINYINT,
|
||||
@ToDelete BIT,
|
||||
@LastSyncDate DATETIME2 (7),
|
||||
@ValidUntil DATETIME2 (7)
|
||||
@ValidUntil DATETIME2 (7),
|
||||
@IsAdminInitiated BIT = 0,
|
||||
@Notes NVARCHAR(512) = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@@ -24,7 +26,9 @@ BEGIN
|
||||
[PlanSponsorshipType],
|
||||
[ToDelete],
|
||||
[LastSyncDate],
|
||||
[ValidUntil]
|
||||
[ValidUntil],
|
||||
[IsAdminInitiated],
|
||||
[Notes]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@@ -37,7 +41,9 @@ BEGIN
|
||||
@PlanSponsorshipType,
|
||||
@ToDelete,
|
||||
@LastSyncDate,
|
||||
@ValidUntil
|
||||
@ValidUntil,
|
||||
@IsAdminInitiated,
|
||||
@Notes
|
||||
)
|
||||
END
|
||||
GO
|
||||
|
||||
@@ -15,7 +15,9 @@ BEGIN
|
||||
[PlanSponsorshipType],
|
||||
[ToDelete],
|
||||
[LastSyncDate],
|
||||
[ValidUntil]
|
||||
[ValidUntil],
|
||||
[IsAdminInitiated],
|
||||
[Notes]
|
||||
)
|
||||
SELECT
|
||||
OS.[Id],
|
||||
@@ -27,7 +29,9 @@ BEGIN
|
||||
OS.[PlanSponsorshipType],
|
||||
OS.[ToDelete],
|
||||
OS.[LastSyncDate],
|
||||
OS.[ValidUntil]
|
||||
OS.[ValidUntil],
|
||||
OS.[IsAdminInitiated],
|
||||
OS.[Notes]
|
||||
FROM
|
||||
@OrganizationSponsorshipsInput OS
|
||||
END
|
||||
END
|
||||
|
||||
@@ -8,7 +8,9 @@ CREATE PROCEDURE [dbo].[OrganizationSponsorship_Update]
|
||||
@PlanSponsorshipType TINYINT,
|
||||
@ToDelete BIT,
|
||||
@LastSyncDate DATETIME2 (7),
|
||||
@ValidUntil DATETIME2 (7)
|
||||
@ValidUntil DATETIME2 (7),
|
||||
@IsAdminInitiated BIT = 0,
|
||||
@Notes NVARCHAR(512) = NULL
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@@ -24,7 +26,9 @@ BEGIN
|
||||
[PlanSponsorshipType] = @PlanSponsorshipType,
|
||||
[ToDelete] = @ToDelete,
|
||||
[LastSyncDate] = @LastSyncDate,
|
||||
[ValidUntil] = @ValidUntil
|
||||
[ValidUntil] = @ValidUntil,
|
||||
[IsAdminInitiated] = @IsAdminInitiated,
|
||||
[Notes] = @Notes
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
|
||||
@@ -6,7 +6,7 @@ BEGIN
|
||||
|
||||
UPDATE
|
||||
OS
|
||||
SET
|
||||
SET
|
||||
[Id] = OSI.[Id],
|
||||
[SponsoringOrganizationId] = OSI.[SponsoringOrganizationId],
|
||||
[SponsoringOrganizationUserID] = OSI.[SponsoringOrganizationUserID],
|
||||
@@ -16,10 +16,12 @@ BEGIN
|
||||
[PlanSponsorshipType] = OSI.[PlanSponsorshipType],
|
||||
[ToDelete] = OSI.[ToDelete],
|
||||
[LastSyncDate] = OSI.[LastSyncDate],
|
||||
[ValidUntil] = OSI.[ValidUntil]
|
||||
[ValidUntil] = OSI.[ValidUntil],
|
||||
[IsAdminInitiated] = OSI.[IsAdminInitiated],
|
||||
[Notes] = OSI.[Notes]
|
||||
FROM
|
||||
[dbo].[OrganizationSponsorship] OS
|
||||
INNER JOIN
|
||||
@OrganizationSponsorshipsInput OSI ON OS.Id = OSI.Id
|
||||
|
||||
END
|
||||
END
|
||||
|
||||
@@ -55,7 +55,8 @@ CREATE PROCEDURE [dbo].[Organization_Create]
|
||||
@LimitCollectionDeletion BIT = NULL,
|
||||
@AllowAdminAccessToAllCollectionItems BIT = 0,
|
||||
@UseRiskInsights BIT = 0,
|
||||
@LimitItemDeletion BIT = 0
|
||||
@LimitItemDeletion BIT = 0,
|
||||
@UseAdminSponsoredFamilies BIT = 0
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@@ -118,7 +119,8 @@ BEGIN
|
||||
[LimitCollectionDeletion],
|
||||
[AllowAdminAccessToAllCollectionItems],
|
||||
[UseRiskInsights],
|
||||
[LimitItemDeletion]
|
||||
[LimitItemDeletion],
|
||||
[UseAdminSponsoredFamilies]
|
||||
)
|
||||
VALUES
|
||||
(
|
||||
@@ -178,6 +180,7 @@ BEGIN
|
||||
@LimitCollectionDeletion,
|
||||
@AllowAdminAccessToAllCollectionItems,
|
||||
@UseRiskInsights,
|
||||
@LimitItemDeletion
|
||||
@LimitItemDeletion,
|
||||
@UseAdminSponsoredFamilies
|
||||
)
|
||||
END
|
||||
|
||||
@@ -25,7 +25,8 @@ BEGIN
|
||||
[LimitCollectionDeletion],
|
||||
[AllowAdminAccessToAllCollectionItems],
|
||||
[UseRiskInsights],
|
||||
[LimitItemDeletion]
|
||||
[LimitItemDeletion],
|
||||
[UseAdminSponsoredFamilies]
|
||||
FROM
|
||||
[dbo].[Organization]
|
||||
END
|
||||
|
||||
@@ -55,7 +55,8 @@ CREATE PROCEDURE [dbo].[Organization_Update]
|
||||
@LimitCollectionDeletion BIT = null,
|
||||
@AllowAdminAccessToAllCollectionItems BIT = 0,
|
||||
@UseRiskInsights BIT = 0,
|
||||
@LimitItemDeletion BIT = 0
|
||||
@LimitItemDeletion BIT = 0,
|
||||
@UseAdminSponsoredFamilies BIT = 0
|
||||
AS
|
||||
BEGIN
|
||||
SET NOCOUNT ON
|
||||
@@ -118,7 +119,8 @@ BEGIN
|
||||
[LimitCollectionDeletion] = @LimitCollectionDeletion,
|
||||
[AllowAdminAccessToAllCollectionItems] = @AllowAdminAccessToAllCollectionItems,
|
||||
[UseRiskInsights] = @UseRiskInsights,
|
||||
[LimitItemDeletion] = @LimitItemDeletion
|
||||
[LimitItemDeletion] = @LimitItemDeletion,
|
||||
[UseAdminSponsoredFamilies] = @UseAdminSponsoredFamilies
|
||||
WHERE
|
||||
[Id] = @Id
|
||||
END
|
||||
|
||||
@@ -56,6 +56,7 @@ CREATE TABLE [dbo].[Organization] (
|
||||
[LimitItemDeletion] BIT NOT NULL CONSTRAINT [DF_Organization_LimitItemDeletion] DEFAULT (0),
|
||||
[AllowAdminAccessToAllCollectionItems] BIT NOT NULL CONSTRAINT [DF_Organization_AllowAdminAccessToAllCollectionItems] DEFAULT (0),
|
||||
[UseRiskInsights] BIT NOT NULL CONSTRAINT [DF_Organization_UseRiskInsights] DEFAULT (0),
|
||||
[UseAdminSponsoredFamilies] BIT NOT NULL CONSTRAINT [DF_Organization_UseAdminSponsoredFamilies] DEFAULT (0),
|
||||
CONSTRAINT [PK_Organization] PRIMARY KEY CLUSTERED ([Id] ASC)
|
||||
);
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@ CREATE TABLE [dbo].[OrganizationSponsorship] (
|
||||
[ToDelete] BIT DEFAULT (0) NOT NULL,
|
||||
[LastSyncDate] DATETIME2 (7) NULL,
|
||||
[ValidUntil] DATETIME2 (7) NULL,
|
||||
[IsAdminInitiated] BIT NOT NULL CONSTRAINT [DF_OrganizationSponsorship_IsAdminInitiated] DEFAULT (0),
|
||||
[Notes] NVARCHAR(512) NULL,
|
||||
CONSTRAINT [PK_OrganizationSponsorship] PRIMARY KEY CLUSTERED ([Id] ASC),
|
||||
CONSTRAINT [FK_OrganizationSponsorship_SponsoringOrg] FOREIGN KEY ([SponsoringOrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||
CONSTRAINT [FK_OrganizationSponsorship_SponsoredOrg] FOREIGN KEY ([SponsoredOrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
|
||||
|
||||
@@ -8,5 +8,7 @@ CREATE TYPE [dbo].[OrganizationSponsorshipType] AS TABLE(
|
||||
[PlanSponsorshipType] TINYINT,
|
||||
[LastSyncDate] DATETIME2(7),
|
||||
[ValidUntil] DATETIME2(7),
|
||||
[ToDelete] BIT
|
||||
)
|
||||
[ToDelete] BIT,
|
||||
[IsAdminInitiated] BIT DEFAULT 0,
|
||||
[Notes] NVARCHAR(512) NULL
|
||||
)
|
||||
|
||||
@@ -50,6 +50,7 @@ SELECT
|
||||
O.[LimitCollectionDeletion],
|
||||
O.[AllowAdminAccessToAllCollectionItems],
|
||||
O.[UseRiskInsights],
|
||||
O.[UseAdminSponsoredFamilies],
|
||||
O.[LimitItemDeletion]
|
||||
FROM
|
||||
[dbo].[OrganizationUser] OU
|
||||
|
||||
@@ -36,6 +36,7 @@ SELECT
|
||||
O.[LimitCollectionDeletion],
|
||||
O.[AllowAdminAccessToAllCollectionItems],
|
||||
O.[UseRiskInsights],
|
||||
O.[UseAdminSponsoredFamilies],
|
||||
P.[Type] ProviderType,
|
||||
O.[LimitItemDeletion]
|
||||
FROM
|
||||
|
||||
Reference in New Issue
Block a user