def get_context( notification: BaseNotification, recipient: Union["Team", "User"], shared_context: Mapping[str, Any], extra_context: Mapping[str, Any], ) -> Mapping[str, Any]: """ Compose the various levels of context and add email-specific fields. The generic HTML/text templates only render the unsubscribe link if one is present in the context, so don't automatically add it to every message. """ context = { **shared_context, **notification.get_recipient_context(recipient, extra_context), } # TODO(mgaeta): The unsubscribe system relies on `user_id` so it doesn't # work with Teams. We should add the `actor_id` to the signed link. if isinstance(recipient, User) and notification.get_unsubscribe_key(): key, resource_id, referrer = notification.get_unsubscribe_key() context.update({ "unsubscribe_link": get_unsubscribe_link(recipient.id, resource_id, key, referrer) }) return context
def get_context( notification: BaseNotification, user: User, shared_context: Mapping[str, Any], extra_context: Mapping[str, Any], ) -> Mapping[str, Any]: """ Compose the various levels of context and add email-specific fields. The generic HTML/text templates only render the unsubscribe link if one is present in the context, so don't automatically add it to every message. """ context = { **shared_context, **notification.get_user_context(user, extra_context), } if notification.get_unsubscribe_key(): key, resource_id, referrer = notification.get_unsubscribe_key() context.update({ "unsubscribe_link": get_unsubscribe_link(user.id, resource_id, key, referrer) }) return context