Skip to content

Commit

Permalink
setup: add invenio-notifications as dependency
Browse files Browse the repository at this point in the history
resolvers: refactor import
  • Loading branch information
rekt-hard committed Apr 27, 2023
1 parent 374964d commit 2dcc0c4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
7 changes: 3 additions & 4 deletions invenio_users_resources/entity_resolvers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from invenio_records_resources.references.entity_resolvers import (
EntityProxy,
EntityResolver,
ResultItemResolver,
ServiceResultResolver,
)

from .proxies import current_users_service
Expand Down Expand Up @@ -86,15 +86,14 @@ 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"

def __init__(self):
"""Ctor."""
super().__init__(
UsersServiceConfig.result_item_cls,
UsersServiceConfig.service_id,
service_id=UsersServiceConfig.service_id,
type_key=self.type_id,
)
24 changes: 10 additions & 14 deletions invenio_users_resources/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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):
Expand All @@ -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


Expand All @@ -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
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 2dcc0c4

Please sign in to comment.