Skip to content

Commit 79b344c

Browse files
committed
Validate SystemNotification creation with policies
1 parent de19274 commit 79b344c

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/components/notification-system/system-notification.resolver.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@ import {
66
ObjectType,
77
Resolver,
88
} from '@nestjs/graphql';
9-
import { LoggedInSession, type Session, UnauthorizedException } from '~/common';
109
import { MarkdownScalar } from '~/common/markdown.scalar';
11-
import { isAdmin } from '~/common/session';
10+
import { Privileges } from '../authorization';
1211
import { NotificationService } from '../notifications';
1312
import { SystemNotification } from './system-notification.dto';
1413

@@ -23,17 +22,16 @@ export class SystemNotificationCreationOutput {
2322

2423
@Resolver(SystemNotification)
2524
export class SystemNotificationResolver {
26-
constructor(private readonly notifications: NotificationService) {}
25+
constructor(
26+
private readonly notifications: NotificationService,
27+
private readonly privileges: Privileges,
28+
) {}
2729

2830
@Mutation(() => SystemNotificationCreationOutput)
2931
async createSystemNotification(
3032
@Args({ name: 'message', type: () => MarkdownScalar }) message: string,
31-
@LoggedInSession() session: Session,
3233
): Promise<SystemNotificationCreationOutput> {
33-
if (!isAdmin(session)) {
34-
throw new UnauthorizedException();
35-
}
36-
34+
this.privileges.for(SystemNotification).verifyCan('create');
3735
return await this.notifications.create(SystemNotification, null, {
3836
message,
3937
});

0 commit comments

Comments
 (0)