diff --git a/invenio_users_resources/notifications/__init__.py b/invenio_users_resources/notifications/__init__.py new file mode 100644 index 0000000..c856e17 --- /dev/null +++ b/invenio_users_resources/notifications/__init__.py @@ -0,0 +1,9 @@ +# -*- 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. + +"""Notification related files for user purposes.""" diff --git a/invenio_users_resources/notifications.py b/invenio_users_resources/notifications/filters.py similarity index 55% rename from invenio_users_resources/notifications.py rename to invenio_users_resources/notifications/filters.py index ddbca42..2ca16f3 100644 --- a/invenio_users_resources/notifications.py +++ b/invenio_users_resources/notifications/filters.py @@ -6,13 +6,9 @@ # modify it under the terms of the MIT License; see LICENSE file for more # details. -"""User specific resources for notifications.""" +"""User specific filters for notifications.""" - -from invenio_notifications.models import Recipient -from invenio_notifications.services.builders import RecipientGenerator from invenio_notifications.services.filters import RecipientFilter -from invenio_records.dictutils import dict_lookup class UserPreferencesRecipientFilter(RecipientFilter): @@ -30,17 +26,3 @@ def __call__(self, notification, recipients): del recipients[key] return recipients - - -class UserRecipient(RecipientGenerator): - """User recipient generator for a notification.""" - - def __init__(self, key): - """Ctor.""" - self.key = key - - def __call__(self, notification, recipients): - """Update required recipient information and add backend id.""" - user = dict_lookup(notification.context, self.key) - recipients[user["id"]] = Recipient(data=user) - return recipients diff --git a/invenio_users_resources/notifications/generators.py b/invenio_users_resources/notifications/generators.py new file mode 100644 index 0000000..c995f44 --- /dev/null +++ b/invenio_users_resources/notifications/generators.py @@ -0,0 +1,28 @@ +# -*- 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 generators for notifications.""" + + +from invenio_notifications.models import Recipient +from invenio_notifications.services.generators import RecipientGenerator +from invenio_records.dictutils import dict_lookup + + +class UserRecipient(RecipientGenerator): + """User recipient generator for a notification.""" + + def __init__(self, key): + """Ctor.""" + self.key = key + + def __call__(self, notification, recipients): + """Update required recipient information and add backend id.""" + user = dict_lookup(notification.context, self.key) + recipients[user["id"]] = Recipient(data=user) + return recipients diff --git a/tests/test_notifications.py b/tests/test_notifications.py index 736585e..5691fc5 100644 --- a/tests/test_notifications.py +++ b/tests/test_notifications.py @@ -10,10 +10,8 @@ from invenio_notifications.models import Notification, Recipient -from invenio_users_resources.notifications import ( - UserPreferencesRecipientFilter, - UserRecipient, -) +from invenio_users_resources.notifications.filters import UserPreferencesRecipientFilter +from invenio_users_resources.notifications.generators import UserRecipient from invenio_users_resources.records.api import UserAggregate