mirror of
https://github.com/bitwarden/server.git
synced 2025-06-30 23:52:50 -05:00
[PM-10563] Notification Center API (#4852)
* PM-10563: Notification Center API * PM-10563: continuation token hack * PM-10563: Resolving merge conflicts * PM-10563: Unit Tests * PM-10563: Paging simplification by page number and size in database * PM-10563: Request validation * PM-10563: Read, Deleted status filters change * PM-10563: Plural name for tests * PM-10563: Request validation to always for int type * PM-10563: Continuation Token returns null on response when no more records available * PM-10563: Integration tests for GET * PM-10563: Mark notification read, deleted commands date typos fix * PM-10563: Integration tests for PATCH read, deleted * PM-10563: Request, Response models tests * PM-10563: EditorConfig compliance * PM-10563: Extracting to const * PM-10563: Update db migration script date * PM-10563: Update migration script date
This commit is contained in:
@ -0,0 +1,29 @@
|
||||
#nullable enable
|
||||
using Bit.Core.NotificationCenter.Authorization;
|
||||
using Bit.Core.NotificationCenter.Commands;
|
||||
using Bit.Core.NotificationCenter.Commands.Interfaces;
|
||||
using Bit.Core.NotificationCenter.Queries;
|
||||
using Bit.Core.NotificationCenter.Queries.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
|
||||
namespace Bit.Core.NotificationCenter;
|
||||
|
||||
public static class NotificationCenterServiceCollectionExtensions
|
||||
{
|
||||
public static void AddNotificationCenterServices(this IServiceCollection services)
|
||||
{
|
||||
// Authorization Handlers
|
||||
services.AddScoped<IAuthorizationHandler, NotificationAuthorizationHandler>();
|
||||
services.AddScoped<IAuthorizationHandler, NotificationStatusAuthorizationHandler>();
|
||||
// Commands
|
||||
services.AddScoped<ICreateNotificationCommand, CreateNotificationCommand>();
|
||||
services.AddScoped<ICreateNotificationStatusCommand, CreateNotificationStatusCommand>();
|
||||
services.AddScoped<IMarkNotificationDeletedCommand, MarkNotificationDeletedCommand>();
|
||||
services.AddScoped<IMarkNotificationReadCommand, MarkNotificationReadCommand>();
|
||||
services.AddScoped<IUpdateNotificationCommand, UpdateNotificationCommand>();
|
||||
// Queries
|
||||
services.AddScoped<IGetNotificationStatusDetailsForUserQuery, GetNotificationStatusDetailsForUserQuery>();
|
||||
services.AddScoped<IGetNotificationStatusForUserQuery, GetNotificationStatusForUserQuery>();
|
||||
}
|
||||
}
|
@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
using Bit.Core.Context;
|
||||
using Bit.Core.Exceptions;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
using Bit.Core.NotificationCenter.Queries.Interfaces;
|
||||
@ -21,8 +22,8 @@ public class GetNotificationStatusDetailsForUserQuery : IGetNotificationStatusDe
|
||||
_notificationRepository = notificationRepository;
|
||||
}
|
||||
|
||||
public async Task<IEnumerable<NotificationStatusDetails>> GetByUserIdStatusFilterAsync(
|
||||
NotificationStatusFilter statusFilter)
|
||||
public async Task<PagedResult<NotificationStatusDetails>> GetByUserIdStatusFilterAsync(
|
||||
NotificationStatusFilter statusFilter, PageOptions pageOptions)
|
||||
{
|
||||
if (!_currentContext.UserId.HasValue)
|
||||
{
|
||||
@ -33,6 +34,6 @@ public class GetNotificationStatusDetailsForUserQuery : IGetNotificationStatusDe
|
||||
|
||||
// Note: only returns the user's notifications - no authorization check needed
|
||||
return await _notificationRepository.GetByUserIdAndStatusAsync(_currentContext.UserId.Value, clientType,
|
||||
statusFilter);
|
||||
statusFilter, pageOptions);
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#nullable enable
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
|
||||
@ -6,5 +7,6 @@ namespace Bit.Core.NotificationCenter.Queries.Interfaces;
|
||||
|
||||
public interface IGetNotificationStatusDetailsForUserQuery
|
||||
{
|
||||
Task<IEnumerable<NotificationStatusDetails>> GetByUserIdStatusFilterAsync(NotificationStatusFilter statusFilter);
|
||||
Task<PagedResult<NotificationStatusDetails>> GetByUserIdStatusFilterAsync(NotificationStatusFilter statusFilter,
|
||||
PageOptions pageOptions);
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
#nullable enable
|
||||
using Bit.Core.Enums;
|
||||
using Bit.Core.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Entities;
|
||||
using Bit.Core.NotificationCenter.Models.Data;
|
||||
using Bit.Core.NotificationCenter.Models.Filter;
|
||||
@ -22,10 +23,13 @@ public interface INotificationRepository : IRepository<Notification, Guid>
|
||||
/// If both <see cref="NotificationStatusFilter.Read"/> and <see cref="NotificationStatusFilter.Deleted"/>
|
||||
/// are not set, includes notifications without a status.
|
||||
/// </param>
|
||||
/// <param name="pageOptions">
|
||||
/// Pagination options.
|
||||
/// </param>
|
||||
/// <returns>
|
||||
/// Ordered by priority (highest to lowest) and creation date (descending).
|
||||
/// Paged results ordered by priority (descending, highest to lowest) and creation date (descending).
|
||||
/// Includes all fields from <see cref="Notification"/> and <see cref="NotificationStatus"/>
|
||||
/// </returns>
|
||||
Task<IEnumerable<NotificationStatusDetails>> GetByUserIdAndStatusAsync(Guid userId, ClientType clientType,
|
||||
NotificationStatusFilter? statusFilter);
|
||||
Task<PagedResult<NotificationStatusDetails>> GetByUserIdAndStatusAsync(Guid userId, ClientType clientType,
|
||||
NotificationStatusFilter? statusFilter, PageOptions pageOptions);
|
||||
}
|
||||
|
Reference in New Issue
Block a user