Skip to content

Commit

Permalink
Merge branch 'main' into ac/pm-15621/refactor-delete-command
Browse files Browse the repository at this point in the history
  • Loading branch information
JimmyVo16 committed Feb 10, 2025
2 parents c47f85c + bde11da commit 0f2356a
Show file tree
Hide file tree
Showing 16 changed files with 9,330 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Core/NotificationCenter/Entities/Notification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public class Notification : ITableObject<Guid>
public string? Body { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public Guid? TaskId { get; set; }

public void SetNewId()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ public void Configure(EntityTypeBuilder<Notification> builder)
.HasIndex(n => n.UserId)
.IsClustered(false);

builder
.HasIndex(n => n.TaskId)
.IsClustered(false);

builder.ToTable(nameof(Notification));
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
using AutoMapper;
using Bit.Infrastructure.EntityFramework.AdminConsole.Models;
using Bit.Infrastructure.EntityFramework.Models;
using Bit.Infrastructure.EntityFramework.Vault.Models;

namespace Bit.Infrastructure.EntityFramework.NotificationCenter.Models;

public class Notification : Core.NotificationCenter.Entities.Notification
{
public virtual User User { get; set; }
public virtual Organization Organization { get; set; }
public virtual SecurityTask Task { get; set; }
}

public class NotificationMapperProfile : Profile
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CREATE PROCEDURE [dbo].[Notification_Create]
@Title NVARCHAR(256),
@Body NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
@RevisionDate DATETIME2(7),
@TaskId UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -23,7 +24,8 @@ BEGIN
[Title],
[Body],
[CreationDate],
[RevisionDate]
[RevisionDate],
[TaskId]
)
VALUES (
@Id,
Expand All @@ -35,6 +37,7 @@ BEGIN
@Title,
@Body,
@CreationDate,
@RevisionDate
@RevisionDate,
@TaskId
)
END
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ CREATE PROCEDURE [dbo].[Notification_Update]
@Title NVARCHAR(256),
@Body NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7)
@RevisionDate DATETIME2(7),
@TaskId UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON
Expand All @@ -22,6 +23,7 @@ BEGIN
[Title] = @Title,
[Body] = @Body,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate
[RevisionDate] = @RevisionDate,
[TaskId] = @TaskId
WHERE [Id] = @Id
END
7 changes: 6 additions & 1 deletion src/Sql/NotificationCenter/dbo/Tables/Notification.sql
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ CREATE TABLE [dbo].[Notification]
[Body] NVARCHAR (MAX) NULL,
[CreationDate] DATETIME2 (7) NOT NULL,
[RevisionDate] DATETIME2 (7) NOT NULL,
[TaskId] UNIQUEIDENTIFIER NULL,
CONSTRAINT [PK_Notification] PRIMARY KEY CLUSTERED ([Id] ASC),
CONSTRAINT [FK_Notification_Organization] FOREIGN KEY ([OrganizationId]) REFERENCES [dbo].[Organization] ([Id]),
CONSTRAINT [FK_Notification_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id])
CONSTRAINT [FK_Notification_User] FOREIGN KEY ([UserId]) REFERENCES [dbo].[User] ([Id]),
CONSTRAINT [FK_Notification_SecurityTask] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[SecurityTask] ([Id])
);


Expand All @@ -30,3 +32,6 @@ GO
CREATE NONCLUSTERED INDEX [IX_Notification_OrganizationId]
ON [dbo].[Notification]([OrganizationId] ASC) WHERE OrganizationId IS NOT NULL;

GO
CREATE NONCLUSTERED INDEX [IX_Notification_TaskId]
ON [dbo].[Notification] ([TaskId] ASC) WHERE TaskId IS NOT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
-- Add optional TaskId column to Notification table
IF COL_LENGTH('[dbo].[Notification]', 'TaskId') IS NULL
BEGIN
ALTER TABLE [dbo].[Notification]
ADD [TaskId] UNIQUEIDENTIFIER NULL

ALTER TABLE [dbo].[Notification]
ADD CONSTRAINT [FK_Notification_SecurityTask] FOREIGN KEY ([TaskId]) REFERENCES [dbo].[SecurityTask] ([Id])
END
GO

IF NOT EXISTS (SELECT *
FROM sys.indexes
WHERE name = 'IX_Notification_TaskId')
BEGIN
CREATE NONCLUSTERED INDEX [IX_Notification_TaskId]
ON [dbo].[Notification] ([TaskId] ASC) WHERE TaskId IS NOT NULL;
END
GO

-- Alter Notification_Create and Notification_Update stored procedures to include TaskId
CREATE OR ALTER PROCEDURE [dbo].[Notification_Create]
@Id UNIQUEIDENTIFIER OUTPUT,
@Priority TINYINT,
@Global BIT,
@ClientType TINYINT,
@UserId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Title NVARCHAR(256),
@Body NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@TaskId UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON

INSERT INTO [dbo].[Notification] (
[Id],
[Priority],
[Global],
[ClientType],
[UserId],
[OrganizationId],
[Title],
[Body],
[CreationDate],
[RevisionDate],
[TaskId]
)
VALUES (
@Id,
@Priority,
@Global,
@ClientType,
@UserId,
@OrganizationId,
@Title,
@Body,
@CreationDate,
@RevisionDate,
@TaskId
)
END
GO

CREATE OR ALTER PROCEDURE [dbo].[Notification_Update]
@Id UNIQUEIDENTIFIER,
@Priority TINYINT,
@Global BIT,
@ClientType TINYINT,
@UserId UNIQUEIDENTIFIER,
@OrganizationId UNIQUEIDENTIFIER,
@Title NVARCHAR(256),
@Body NVARCHAR(MAX),
@CreationDate DATETIME2(7),
@RevisionDate DATETIME2(7),
@TaskId UNIQUEIDENTIFIER = NULL
AS
BEGIN
SET NOCOUNT ON

UPDATE [dbo].[Notification]
SET [Priority] = @Priority,
[Global] = @Global,
[ClientType] = @ClientType,
[UserId] = @UserId,
[OrganizationId] = @OrganizationId,
[Title] = @Title,
[Body] = @Body,
[CreationDate] = @CreationDate,
[RevisionDate] = @RevisionDate,
[TaskId] = @TaskId
WHERE [Id] = @Id
END
GO

-- Recreate NotificationView
CREATE OR ALTER VIEW [dbo].[NotificationView]
AS
SELECT
*
FROM
[dbo].[Notification]
GO


Loading

0 comments on commit 0f2356a

Please sign in to comment.