From 91e1b6c4a2074c5f9ff78c964a92cb192f3d1eba Mon Sep 17 00:00:00 2001 From: Philipinho <16838612+Philipinho@users.noreply.github.com> Date: Tue, 31 Mar 2026 15:49:05 +0100 Subject: [PATCH] filter --- .../core/notification/notification.service.ts | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/apps/server/src/core/notification/notification.service.ts b/apps/server/src/core/notification/notification.service.ts index cbbc3e5a..1f88bf59 100644 --- a/apps/server/src/core/notification/notification.service.ts +++ b/apps/server/src/core/notification/notification.service.ts @@ -7,6 +7,7 @@ import { PaginationOptions } from '@docmost/db/pagination/pagination-options'; import { WsGateway } from '../../ws/ws.gateway'; import { MailService } from '../../integrations/mail/mail.service'; import { NotificationTab, NotificationType, NotificationTypeToSettingKey } from './notification.constants'; +import { PagePermissionRepo } from '@docmost/db/repos/page/page-permission.repo'; @Injectable() export class NotificationService { @@ -14,6 +15,7 @@ export class NotificationService { constructor( private readonly notificationRepo: NotificationRepo, + private readonly pagePermissionRepo: PagePermissionRepo, private readonly wsGateway: WsGateway, private readonly mailService: MailService, @InjectKysely() private readonly db: KyselyDB, @@ -44,7 +46,30 @@ export class NotificationService { pagination: PaginationOptions, type: NotificationTab = 'all', ) { - return this.notificationRepo.findByUserId(userId, pagination, type); + const result = await this.notificationRepo.findByUserId( + userId, + pagination, + type, + ); + + const pageIds = result.items + .map((n: any) => n.pageId) + .filter(Boolean); + + if (pageIds.length > 0) { + const accessiblePageIds = + await this.pagePermissionRepo.filterAccessiblePageIds({ + pageIds, + userId, + }); + const accessibleSet = new Set(accessiblePageIds); + + result.items = result.items.filter( + (n: any) => !n.pageId || accessibleSet.has(n.pageId), + ); + } + + return result; } async getUnreadCount(userId: string) {