diff --git a/authentik/api/v3/urls.py b/authentik/api/v3/urls.py index faa04b5b4..a9235da4f 100644 --- a/authentik/api/v3/urls.py +++ b/authentik/api/v3/urls.py @@ -22,11 +22,11 @@ from authentik.core.api.sources import SourceViewSet, UserSourceConnectionViewSe from authentik.core.api.tokens import TokenViewSet from authentik.core.api.users import UserViewSet from authentik.crypto.api import CertificateKeyPairViewSet -from authentik.events.api.event import EventViewSet -from authentik.events.api.notification import NotificationViewSet -from authentik.events.api.notification_mapping import NotificationWebhookMappingViewSet -from authentik.events.api.notification_rule import NotificationRuleViewSet -from authentik.events.api.notification_transport import NotificationTransportViewSet +from authentik.events.api.events import EventViewSet +from authentik.events.api.notification_mappings import NotificationWebhookMappingViewSet +from authentik.events.api.notification_rules import NotificationRuleViewSet +from authentik.events.api.notification_transports import NotificationTransportViewSet +from authentik.events.api.notifications import NotificationViewSet from authentik.flows.api.bindings import FlowStageBindingViewSet from authentik.flows.api.flows import FlowViewSet from authentik.flows.api.stages import StageViewSet diff --git a/authentik/events/api/event.py b/authentik/events/api/events.py similarity index 100% rename from authentik/events/api/event.py rename to authentik/events/api/events.py diff --git a/authentik/events/api/notification_mapping.py b/authentik/events/api/notification_mappings.py similarity index 100% rename from authentik/events/api/notification_mapping.py rename to authentik/events/api/notification_mappings.py diff --git a/authentik/events/api/notification_rule.py b/authentik/events/api/notification_rules.py similarity index 100% rename from authentik/events/api/notification_rule.py rename to authentik/events/api/notification_rules.py diff --git a/authentik/events/api/notification_transport.py b/authentik/events/api/notification_transports.py similarity index 100% rename from authentik/events/api/notification_transport.py rename to authentik/events/api/notification_transports.py diff --git a/authentik/events/api/notification.py b/authentik/events/api/notifications.py similarity index 96% rename from authentik/events/api/notification.py rename to authentik/events/api/notifications.py index 17792e8af..ca5bb1486 100644 --- a/authentik/events/api/notification.py +++ b/authentik/events/api/notifications.py @@ -13,7 +13,7 @@ from rest_framework.viewsets import GenericViewSet from authentik.api.authorization import OwnerFilter, OwnerPermissions from authentik.core.api.used_by import UsedByMixin -from authentik.events.api.event import EventSerializer +from authentik.events.api.events import EventSerializer from authentik.events.models import Notification @@ -55,6 +55,7 @@ class NotificationViewSet( "created", "event", "seen", + "user", ] permission_classes = [OwnerPermissions] filter_backends = [OwnerFilter, DjangoFilterBackend, OrderingFilter, SearchFilter] diff --git a/authentik/events/models.py b/authentik/events/models.py index 9880495aa..cd0e94f73 100644 --- a/authentik/events/models.py +++ b/authentik/events/models.py @@ -518,7 +518,7 @@ class NotificationWebhookMapping(PropertyMapping): @property def serializer(self) -> type["Serializer"]: - from authentik.events.api.notification_mapping import NotificationWebhookMappingSerializer + from authentik.events.api.notification_mappings import NotificationWebhookMappingSerializer return NotificationWebhookMappingSerializer diff --git a/schema.yml b/schema.yml index 1a4608ca2..34da56550 100644 --- a/schema.yml +++ b/schema.yml @@ -4070,6 +4070,10 @@ paths: - alert - notice - warning + - in: query + name: user + schema: + type: integer tags: - events security: diff --git a/web/src/elements/PageHeader.ts b/web/src/elements/PageHeader.ts index 1674b1d11..6583625c6 100644 --- a/web/src/elements/PageHeader.ts +++ b/web/src/elements/PageHeader.ts @@ -13,6 +13,7 @@ import { EventsApi } from "@goauthentik/api"; import { DEFAULT_CONFIG, tenant } from "../api/Config"; import { currentInterface } from "../api/Sentry"; +import { me } from "../api/Users"; import { EVENT_API_DRAWER_TOGGLE, EVENT_NOTIFICATION_DRAWER_TOGGLE, @@ -102,15 +103,18 @@ export class PageHeader extends LitElement { } firstUpdated(): void { - new EventsApi(DEFAULT_CONFIG) - .eventsNotificationsList({ - seen: false, - ordering: "-created", - pageSize: 1, - }) - .then((r) => { - this.hasNotifications = r.pagination.count > 0; - }); + me().then((user) => { + new EventsApi(DEFAULT_CONFIG) + .eventsNotificationsList({ + seen: false, + ordering: "-created", + pageSize: 1, + user: user.user.pk, + }) + .then((r) => { + this.hasNotifications = r.pagination.count > 0; + }); + }); } renderIcon(): TemplateResult { diff --git a/web/src/elements/notifications/NotificationDrawer.ts b/web/src/elements/notifications/NotificationDrawer.ts index 15f06a3d6..e5be9950e 100644 --- a/web/src/elements/notifications/NotificationDrawer.ts +++ b/web/src/elements/notifications/NotificationDrawer.ts @@ -14,6 +14,7 @@ import { EventsApi, Notification } from "@goauthentik/api"; import { AKResponse } from "../../api/Client"; import { DEFAULT_CONFIG } from "../../api/Config"; +import { me } from "../../api/Users"; import { EVENT_NOTIFICATION_DRAWER_TOGGLE, EVENT_REFRESH } from "../../constants"; import { ActionToLabel } from "../../pages/events/utils"; import { MessageLevel } from "../messages/Message"; @@ -53,15 +54,18 @@ export class NotificationDrawer extends LitElement { } firstUpdated(): void { - new EventsApi(DEFAULT_CONFIG) - .eventsNotificationsList({ - seen: false, - ordering: "-created", - }) - .then((r) => { - this.notifications = r; - this.unread = r.results.length; - }); + me().then((user) => { + new EventsApi(DEFAULT_CONFIG) + .eventsNotificationsList({ + seen: false, + ordering: "-created", + user: user.user.pk, + }) + .then((r) => { + this.notifications = r; + this.unread = r.results.length; + }); + }); } renderItem(item: Notification): TemplateResult { diff --git a/web/src/interfaces/UserInterface.ts b/web/src/interfaces/UserInterface.ts index 1f2187e77..3f52530da 100644 --- a/web/src/interfaces/UserInterface.ts +++ b/web/src/interfaces/UserInterface.ts @@ -123,15 +123,18 @@ export class UserInterface extends LitElement { } firstUpdated(): void { - new EventsApi(DEFAULT_CONFIG) - .eventsNotificationsList({ - seen: false, - ordering: "-created", - pageSize: 1, - }) - .then((r) => { - this.notificationsCount = r.pagination.count; - }); + me().then((user) => { + new EventsApi(DEFAULT_CONFIG) + .eventsNotificationsList({ + seen: false, + ordering: "-created", + pageSize: 1, + user: user.user.pk, + }) + .then((r) => { + this.notificationsCount = r.pagination.count; + }); + }); } render(): TemplateResult {