1
0
mirror of https://github.com/bitwarden/server.git synced 2025-07-01 16:12:49 -05:00

[PM-10560] Create notification database storage (#4688)

* Add new tables

* Add stored procedures

* Add core entities and models

* Setup EF

* Add repository interfaces

* Add dapper repos

* Add EF repos

* Add order by

* EF updates

* PM-10560: Notifications repository matching requirements.

* PM-10560: Notifications repository matching requirements.

* PM-10560: Migration scripts

* PM-10560: EF index optimizations

* PM-10560: Cleanup

* PM-10560: Priority in natural order, Repository, sql simplifications

* PM-10560: Title column update

* PM-10560: Incorrect EF migration removal

* PM-10560: EF migrations

* PM-10560: Added views, SP naming simplification

* PM-10560: Notification entity Title update, EF migrations

* PM-10560: Removing Notification_ReadByUserId

* PM-10560: Notification ReadByUserIdAndStatus fix

* PM-10560: Notification ReadByUserIdAndStatus fix to be in line with requirements and EF

---------

Co-authored-by: Maciej Zieniuk <mzieniuk@bitwarden.com>
Co-authored-by: Matt Bishop <mbishop@bitwarden.com>
This commit is contained in:
Thomas Avery
2024-09-09 14:52:12 -05:00
committed by GitHub
parent 55bf815050
commit 4c0f8d54f3
39 changed files with 9983 additions and 0 deletions

View File

@ -0,0 +1,27 @@
#nullable enable
using System.ComponentModel.DataAnnotations;
using Bit.Core.Entities;
using Bit.Core.NotificationCenter.Enums;
using Bit.Core.Utilities;
namespace Bit.Core.NotificationCenter.Entities;
public class Notification : ITableObject<Guid>
{
public Guid Id { get; set; }
public Priority Priority { get; set; }
public bool Global { get; set; }
public ClientType ClientType { get; set; }
public Guid? UserId { get; set; }
public Guid? OrganizationId { get; set; }
[MaxLength(256)]
public string? Title { get; set; }
public string? Body { get; set; }
public DateTime CreationDate { get; set; }
public DateTime RevisionDate { get; set; }
public void SetNewId()
{
Id = CoreHelpers.GenerateComb();
}
}

View File

@ -0,0 +1,10 @@
#nullable enable
namespace Bit.Core.NotificationCenter.Entities;
public class NotificationStatus
{
public Guid NotificationId { get; set; }
public Guid UserId { get; set; }
public DateTime? ReadDate { get; set; }
public DateTime? DeletedDate { get; set; }
}

View File

@ -0,0 +1,18 @@
#nullable enable
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.NotificationCenter.Enums;
public enum ClientType : byte
{
[Display(Name = "All")]
All = 0,
[Display(Name = "Web Vault")]
Web = 1,
[Display(Name = "Browser Extension")]
Browser = 2,
[Display(Name = "Desktop App")]
Desktop = 3,
[Display(Name = "Mobile App")]
Mobile = 4
}

View File

@ -0,0 +1,18 @@
#nullable enable
using System.ComponentModel.DataAnnotations;
namespace Bit.Core.NotificationCenter.Enums;
public enum Priority : byte
{
[Display(Name = "Informational")]
Informational = 0,
[Display(Name = "Low")]
Low = 1,
[Display(Name = "Medium")]
Medium = 2,
[Display(Name = "High")]
High = 3,
[Display(Name = "Critical")]
Critical = 4
}

View File

@ -0,0 +1,8 @@
#nullable enable
namespace Bit.Core.NotificationCenter.Models.Filter;
public class NotificationStatusFilter
{
public bool? Read { get; set; }
public bool? Deleted { get; set; }
}

View File

@ -0,0 +1,29 @@
#nullable enable
using Bit.Core.NotificationCenter.Entities;
using Bit.Core.NotificationCenter.Enums;
using Bit.Core.NotificationCenter.Models.Filter;
using Bit.Core.Repositories;
namespace Bit.Core.NotificationCenter.Repositories;
public interface INotificationRepository : IRepository<Notification, Guid>
{
/// <summary>
/// Get notifications for a user with the given filters.
/// Includes global notifications.
/// </summary>
/// <param name="userId">User Id</param>
/// <param name="clientType">
/// Filter for notifications by client type. Always includes notifications with <see cref="ClientType.All"/>.
/// </param>
/// <param name="statusFilter">
/// Filters notifications by status.
/// If both <see cref="NotificationStatusFilter.Read"/> and <see cref="NotificationStatusFilter.Deleted"/>
/// are not set, includes notifications without a status.
/// </param>
/// <returns>
/// Ordered by priority (highest to lowest) and creation date (descending).
/// </returns>
Task<IEnumerable<Notification>> GetByUserIdAndStatusAsync(Guid userId, ClientType clientType,
NotificationStatusFilter? statusFilter);
}

View File

@ -0,0 +1,11 @@
#nullable enable
using Bit.Core.NotificationCenter.Entities;
namespace Bit.Core.NotificationCenter.Repositories;
public interface INotificationStatusRepository
{
Task<NotificationStatus?> GetByNotificationIdAndUserIdAsync(Guid notificationId, Guid userId);
Task<NotificationStatus> CreateAsync(NotificationStatus notificationStatus);
Task UpdateAsync(NotificationStatus notificationStatus);
}