diff --git a/invenio_users_resources/notifications.py b/invenio_users_resources/notifications.py new file mode 100644 index 0000000..7e048a2 --- /dev/null +++ b/invenio_users_resources/notifications.py @@ -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) + ] diff --git a/invenio_users_resources/services/schemas.py b/invenio_users_resources/services/schemas.py index 9ad7a5a..315d775 100644 --- a/invenio_users_resources/services/schemas.py +++ b/invenio_users_resources/services/schemas.py @@ -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()