1
0
mirror of https://github.com/bitwarden/server.git synced 2024-12-23 17:07:42 +01:00

Null org, org user ids, and friendly name to indicate invalid, unused sponsorship state (#1738)

* Null org, org user ids, and friendly name to indicate invalid, unused sponsorship state

* Match EF queries to MSSQL sprocs
This commit is contained in:
Matt Gibson 2021-12-01 14:34:56 -06:00 committed by GitHub
parent ad18adf471
commit 757927e02a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 83 additions and 0 deletions

View File

@ -113,6 +113,7 @@ namespace Bit.Core.Repositories.EntityFramework
{
sponsorship.SponsoredOrganizationId = UpdatedOrgId(sponsorship.SponsoredOrganizationId);
sponsorship.SponsoringOrganizationId = UpdatedOrgId(sponsorship.SponsoringOrganizationId);
sponsorship.FriendlyName = null;
}
dbContext.Remove(orgEntity);

View File

@ -80,6 +80,7 @@ namespace Bit.Core.Repositories.EntityFramework
foreach (var sponsorship in sponsorships)
{
sponsorship.SponsoringOrganizationUserId = null;
sponsorship.FriendlyName = null;
}
dbContext.Remove(orgUser);
@ -99,6 +100,7 @@ namespace Bit.Core.Repositories.EntityFramework
foreach (var sponsorship in sponsorships)
{
sponsorship.SponsoringOrganizationUserId = null;
sponsorship.FriendlyName = null;
}
dbContext.RemoveRange(entities);

View File

@ -0,0 +1,80 @@
-- OrganizationSponsorship_OrganizationDeleted
IF OBJECT_ID('[dbo].[OrganizationSponsorship_OrganizationDeleted]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[OrganizationSponsorship_OrganizationDeleted]
END
GO
CREATE PROCEDURE [dbo].[OrganizationSponsorship_OrganizationDeleted]
@OrganizationId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
UPDATE
[dbo].[OrganizationSponsorship]
SET
[SponsoringOrganizationId] = NULL,
[FriendlyName] = NULL
WHERE
[SponsoringOrganizationId] = @OrganizationId
UPDATE
[dbo].[OrganizationSponsorship]
SET
[SponsoredOrganizationId] = NULL,
[FriendlyName] = NULL
WHERE
[SponsoredOrganizationId] = @OrganizationId
END
GO
-- OrganizationSponsorship_OrganizationUserDeleted
IF OBJECT_ID('[dbo].[OrganizationSponsorship_OrganizationUserDeleted]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[OrganizationSponsorship_OrganizationUserDeleted]
END
GO
CREATE PROCEDURE [dbo].[OrganizationSponsorship_OrganizationUserDeleted]
@OrganizationUserId UNIQUEIDENTIFIER
AS
BEGIN
SET NOCOUNT ON
UPDATE
OS
SET
[SponsoringOrganizationUserId] = NULL,
[FriendlyName] = NULL
FROM
[dbo].[OrganizationSponsorship] OS
WHERE
[SponsoringOrganizationUserId] = @OrganizationUserId
END
GO
-- OrganizationSponsorship_OrganizationUsersDeleted
IF OBJECT_ID('[dbo].[OrganizationSponsorship_OrganizationUsersDeleted]') IS NOT NULL
BEGIN
DROP PROCEDURE [dbo].[OrganizationSponsorship_OrganizationUsersDeleted]
END
GO
CREATE PROCEDURE [dbo].[OrganizationSponsorship_OrganizationUsersDeleted]
@SponsoringOrganizationUserIds [dbo].[GuidIdArray] READONLY
AS
BEGIN
SET NOCOUNT ON
UPDATE
OS
SET
[SponsoringOrganizationUserId] = NULL,
[FriendlyName] = NULL
FROM
[dbo].[OrganizationSponsorship] OS
INNER JOIN
@SponsoringOrganizationUserIds I ON I.Id = OS.SponsoringOrganizationUserId
END
GO