Skip to content

Commit

Permalink
notifications: add user preferences filter
Browse files Browse the repository at this point in the history
schemas: add notifications schema
  • Loading branch information
rekt-hard committed Apr 27, 2023
1 parent 383bfbb commit 189315d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
27 changes: 27 additions & 0 deletions invenio_users_resources/notifications.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2023 Graz University of Technology.
#
# Invenio-Users-Resources is free software; you can redistribute it and/or
# modify it under the terms of the MIT License; see LICENSE file for more
# details.

"""User specific resources for notifications."""


from invenio_records_resources.notifications import RecipientFilter


class UserPreferencesRecipientFilter(RecipientFilter):
"""Recipient filter for notifications being enabled at all."""

def run(self, recipients, **kwargs):
"""Filter recipients."""
return [
r
for r in recipients
if r.get("user", {})
.get("preferences", {})
.get("notifications", {})
.get("enabled", False)
]
6 changes: 6 additions & 0 deletions invenio_users_resources/services/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,9 @@ class UserGhostSchema(Schema):
dump_only=True,
)
is_ghost = fields.Boolean(dump_only=True)


class NotificationPreferences(Schema):
"""Schema for notification preferences."""

enabled: fields.Bool()

0 comments on commit 189315d

Please sign in to comment.