mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
PM-10560: Adding Cascades back to Notification Center (#4769)
* PM-10560: Adding Cascades back * PM-10560: Add missing Notification FK with CASCADE * PM-10560: Delete Notification cascades fix * PM-10560: Further cascades removal, simplifications * PM-10560: Cleanup * PM-10560: Cleanup * PM-10560: Sql migrations fix * PM-10560: EF revert
This commit is contained in:
@ -199,6 +199,11 @@ public class OrganizationRepository : Repository<Core.AdminConsole.Entities.Orga
|
||||
await dbContext.ServiceAccount.Where(sa => sa.OrganizationId == organization.Id)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
await dbContext.NotificationStatuses.Where(ns => ns.Notification.OrganizationId == organization.Id)
|
||||
.ExecuteDeleteAsync();
|
||||
await dbContext.Notifications.Where(n => n.OrganizationId == organization.Id)
|
||||
.ExecuteDeleteAsync();
|
||||
|
||||
// The below section are 3 SPROCS in SQL Server but are only called by here
|
||||
await dbContext.OrganizationApiKeys.Where(oa => oa.OrganizationId == organization.Id)
|
||||
.ExecuteDeleteAsync();
|
||||
|
@ -255,6 +255,8 @@ public class UserRepository : Repository<Core.Entities.User, User, Guid>, IUserR
|
||||
dbContext.EmergencyAccesses.RemoveRange(
|
||||
dbContext.EmergencyAccesses.Where(ea => ea.GrantorId == user.Id || ea.GranteeId == user.Id));
|
||||
dbContext.Sends.RemoveRange(dbContext.Sends.Where(s => s.UserId == user.Id));
|
||||
dbContext.NotificationStatuses.RemoveRange(dbContext.NotificationStatuses.Where(ns => ns.UserId == user.Id));
|
||||
dbContext.Notifications.RemoveRange(dbContext.Notifications.Where(n => n.UserId == user.Id));
|
||||
|
||||
var mappedUser = Mapper.Map<User>(user);
|
||||
dbContext.Users.Remove(mappedUser);
|
||||
|
@ -5,5 +5,11 @@ CREATE TABLE [dbo].[NotificationStatus]
|
||||
[ReadDate] DATETIME2 (7) NULL,
|
||||
[DeletedDate] DATETIME2 (7) NULL,
|
||||
CONSTRAINT [PK_NotificationStatus] PRIMARY KEY CLUSTERED ([NotificationId] ASC, [UserId] ASC),
|
||||
CONSTRAINT [FK_NotificationStatus_Notification] FOREIGN KEY ([NotificationId]) REFERENCES [dbo].[Notification] ([Id]),
|
||||
CONSTRAINT [FK_NotificationStatus_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
|
||||
);
|
||||
|
||||
GO
|
||||
CREATE NONCLUSTERED INDEX [IX_NotificationStatus_UserId]
|
||||
ON [dbo].[NotificationStatus]([UserId] ASC);
|
||||
|
||||
|
@ -119,6 +119,23 @@ BEGIN
|
||||
WHERE
|
||||
[OrganizationId] = @Id
|
||||
|
||||
-- Delete Notification Status
|
||||
DELETE
|
||||
NS
|
||||
FROM
|
||||
[dbo].[NotificationStatus] NS
|
||||
INNER JOIN
|
||||
[dbo].[Notification] N ON N.[Id] = NS.[NotificationId]
|
||||
WHERE
|
||||
N.[OrganizationId] = @Id
|
||||
|
||||
-- Delete Notification
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Notification]
|
||||
WHERE
|
||||
[OrganizationId] = @Id
|
||||
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Organization]
|
||||
|
@ -119,6 +119,20 @@ BEGIN
|
||||
WHERE
|
||||
[UserId] = @Id
|
||||
|
||||
-- Delete Notification Status
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[NotificationStatus]
|
||||
WHERE
|
||||
[UserId] = @Id
|
||||
|
||||
-- Delete Notification
|
||||
DELETE
|
||||
FROM
|
||||
[dbo].[Notification]
|
||||
WHERE
|
||||
[UserId] = @Id
|
||||
|
||||
-- Finally, delete the user
|
||||
DELETE
|
||||
FROM
|
||||
|
Reference in New Issue
Block a user