diff --git a/invenio_users_resources/entity_resolvers.py b/invenio_users_resources/entity_resolvers.py index d0449ca..7c77d10 100644 --- a/invenio_users_resources/entity_resolvers.py +++ b/invenio_users_resources/entity_resolvers.py @@ -16,7 +16,7 @@ from invenio_records_resources.references.entity_resolvers import ( EntityProxy, EntityResolver, - ResultItemResolver, + ServiceResultResolver, ) from .proxies import current_users_service @@ -86,7 +86,7 @@ def _get_entity_proxy(self, ref_dict): return UserProxy(self, ref_dict) -class UserResultItemResolver(ResultItemResolver): +class UserResultItemResolver(ServiceResultResolver): """Resolver for user result items.""" type_id = "user" @@ -94,7 +94,6 @@ class UserResultItemResolver(ResultItemResolver): def __init__(self): """Ctor.""" super().__init__( - UsersServiceConfig.result_item_cls, - UsersServiceConfig.service_id, + service_id=UsersServiceConfig.service_id, type_key=self.type_id, ) diff --git a/invenio_users_resources/notifications.py b/invenio_users_resources/notifications.py index d3b24b9..ab0dceb 100644 --- a/invenio_users_resources/notifications.py +++ b/invenio_users_resources/notifications.py @@ -9,8 +9,12 @@ """User specific resources for notifications.""" +from invenio_notifications.backends.email import EmailNotificationBackend from invenio_notifications.models import Recipient -from invenio_notifications.services.builders import RecipientBackendGenerator +from invenio_notifications.services.builders import ( + RecipientBackendGenerator, + RecipientGenerator, +) from invenio_notifications.services.filters import RecipientFilter from invenio_records.dictutils import dict_lookup @@ -32,7 +36,7 @@ def __call__(self, notification, recipients): return recipients -class UserRecipient: +class UserRecipient(RecipientGenerator): """User recipient generator for a notification.""" def __init__(self, key): @@ -42,8 +46,7 @@ def __init__(self, key): def __call__(self, notification, recipients): """Update required recipient information and add backend id.""" user = dict_lookup(notification.context, self.key) - if user.get("preferences", {}).get("notifications", {}).get("enabled", True): - recipients[user["id"]] = Recipient(data=user) + recipients[user["id"]] = Recipient(data=user) return recipients @@ -52,13 +55,6 @@ class UserEmailBackend(RecipientBackendGenerator): def __call__(self, notification, recipient, backends): """Update required recipient information and add backend id.""" - backends.append("email") - return "email" - # NOTE: Not sure about the backend payload yet. Is it needed? - # user = recipient.data - # rec.backends.append( - # { - # "backend": "email", - # "to": f"{user.profile.full_name} <{user.email}>", - # } - # ) + backend_id = EmailNotificationBackend.id + backends.append(backend_id) + return backend_id diff --git a/setup.cfg b/setup.cfg index aa6604f..280decb 100644 --- a/setup.cfg +++ b/setup.cfg @@ -29,6 +29,7 @@ zip_safe = False install_requires = invenio-accounts>=2.2.0,<3.0.0 invenio-i18n>=2.0.0 + invenio-notifications>=0.1.0,<1.0.0 invenio-oauthclient>=2.2.0,<3.0.0 invenio-records-resources>=4.0.0,<5.0.0