Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Remove the deprecated Sendgrid email plugin (#19725)
Lukasz Ostrowskie417c4efc0be
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex fb0310a57c..46feaa28b2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -10,6 +10,7 @@ All notable, unreleased changes to this project will be documented in this file.- Removed the deprecated Razorpay payment gateway plugin (`mirumee.payments.razorpay`).- Removed the deprecated Braintree payment gateway plugin (`mirumee.payments.braintree`).- Removed the deprecated Dummy (`mirumee.payments.dummy`) and Dummy Credit Card (`mirumee.payments.dummy_credit_card`) payment gateway plugins.+- Removed the deprecated Sendgrid email plugin (`mirumee.notifications.sendgrid_email`), along with the `sendgrid` dependency. It sent customer notification emails (account confirmation, password reset, order confirmation, fulfillment, invoice and gift card) through SendGrid dynamic templates, and served custom events passed to `externalNotificationTrigger` with its `pluginId`. Use the SMTP app or your own app subscribing to the corresponding webhook events instead. Staff notification emails are unaffected — they are sent by the separate Admin emails plugin (`mirumee.notifications.admin_email`).- Apps will be no longer to be granted with `MANAGE_APPS` permission. In certain cases, this permission was able to be assigned by the authorized user.App with such permission was not able to *act* like an admin app, but permission technically was granted.diff --git a/pyproject.toml b/pyproject.tomlindex 077c0e058e..db7638a2ff 100644--- a/pyproject.toml+++ b/pyproject.toml@@ -51,7 +51,6 @@ dependencies = ["pybars3>=0.9.7,<0.10","pyjwt>=2.13.0,<3","python-dateutil>=2.8.2,<3",- "python-http-client>=3.3.7,<4","python-json-logger>=0.1.11,<3.3.0","pytimeparse>=1.1.8,<2","redis>=5.0.1,<6",@@ -59,7 +58,6 @@ dependencies = ["requests-hardened>=1.3.0,<2.0.0","Rx>=1.6.3,<2","semantic-version>=2.10.0,<3",- "sendgrid>=6.12.5,<7","sentry-sdk~=2.58","stripe>=3.0.0,<4","text-unidecode~=1.2",diff --git a/saleor/graphql/notifications/tests/test_external_notification_dispatch.py b/saleor/graphql/notifications/tests/test_external_notification_dispatch.pyindex d27a7905a8..b995705162 100644--- a/saleor/graphql/notifications/tests/test_external_notification_dispatch.py+++ b/saleor/graphql/notifications/tests/test_external_notification_dispatch.py@@ -3,6 +3,7 @@ from unittest.mock import patchfrom graphql_relay.node.node import to_global_idfrom ....account.models import User+from ....plugins.tests.sample_plugins import PluginSample@patch("saleor.plugins.manager.PluginsManager.notify")@@ -26,7 +27,7 @@ def test_notify_via_external_notification_trigger("extraPayload": '{"recipient_email":"[email protected]"}',"externalEventType": test_template_id,},- "pluginId": "mirumee.notifications.sendgrid_email",+ "pluginId": PluginSample.PLUGIN_ID,"channel": channel_PLN.slug,}diff --git a/saleor/plugins/sendgrid/__init__.py b/saleor/plugins/sendgrid/__init__.pydeleted file mode 100644index a4840ffded..0000000000--- a/saleor/plugins/sendgrid/__init__.py+++ /dev/null@@ -1,23 +0,0 @@-from dataclasses import dataclass---@dataclass-class SendgridConfiguration:- api_key: str | None- sender_name: str | None- sender_address: str | None- account_confirmation_template_id: str | None- account_set_customer_password_template_id: str | None- account_delete_template_id: str | None- account_change_email_confirm_template_id: str | None- account_change_email_request_template_id: str | None- account_password_reset_template_id: str | None- invoice_ready_template_id: str | None- order_confirmation_template_id: str | None- order_confirmed_template_id: str | None- order_fulfillment_confirmation_template_id: str | None- order_fulfillment_update_template_id: str | None- order_payment_confirmation_template_id: str | None- order_canceled_template_id: str | None- order_refund_confirmation_template_id: str | None- send_gift_card_template_id: str | Nonediff --git a/saleor/plugins/sendgrid/plugin.py b/saleor/plugins/sendgrid/plugin.pydeleted file mode 100644index 6eba5cbc39..0000000000--- a/saleor/plugins/sendgrid/plugin.py+++ /dev/null@@ -1,284 +0,0 @@-import logging-from collections.abc import Callable-from dataclasses import asdict--from django.core.exceptions import ValidationError--from ...core.notify import NotifyEventType, UserNotifyEvent-from ...plugins.sendgrid.tasks import send_email_with_dynamic_template_id-from ..base_plugin import BasePlugin, ConfigurationTypeField-from ..error_codes import PluginErrorCode-from ..models import PluginConfiguration-from . import SendgridConfiguration-from .tasks import (- send_account_confirmation_email_task,- send_account_delete_confirmation_email_task,- send_fulfillment_confirmation_email_task,- send_fulfillment_update_email_task,- send_gift_card_email_task,- send_invoice_email_task,- send_order_canceled_email_task,- send_order_confirmation_email_task,- send_order_confirmed_email_task,- send_order_refund_email_task,- send_password_reset_email_task,- send_payment_confirmation_email_task,- send_request_email_change_email_task,- send_set_user_password_email_task,- send_user_change_email_notification_task,-)--logger = logging.getLogger(__name__)---EVENT_MAP = {- UserNotifyEvent.ACCOUNT_CONFIRMATION: (- send_account_confirmation_email_task,- "account_confirmation_template_id",- ),- UserNotifyEvent.ACCOUNT_SET_CUSTOMER_PASSWORD: (- send_set_user_password_email_task,- "account_set_customer_password_template_id",- ),- UserNotifyEvent.ACCOUNT_DELETE: (- send_account_delete_confirmation_email_task,- "account_delete_template_id",- ),- UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_CONFIRM: (- send_user_change_email_notification_task,- "account_change_email_confirm_template_id",- ),- UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_REQUEST: (- send_request_email_change_email_task,- "account_change_email_request_template_id",- ),- UserNotifyEvent.ACCOUNT_PASSWORD_RESET: (- send_password_reset_email_task,- "account_password_reset_template_id",- ),- UserNotifyEvent.INVOICE_READY: (- send_invoice_email_task,- "invoice_ready_template_id",- ),- UserNotifyEvent.ORDER_CONFIRMATION: (- send_order_confirmation_email_task,- "order_confirmation_template_id",- ),- UserNotifyEvent.ORDER_CONFIRMED: (- send_order_confirmed_email_task,- "order_confirmed_template_id",- ),- UserNotifyEvent.ORDER_FULFILLMENT_CONFIRMATION: (- send_fulfillment_confirmation_email_task,- "order_fulfillment_confirmation_template_id",- ),- UserNotifyEvent.ORDER_FULFILLMENT_UPDATE: (- send_fulfillment_update_email_task,- "order_fulfillment_update_template_id",- ),- UserNotifyEvent.ORDER_PAYMENT_CONFIRMATION: (- send_payment_confirmation_email_task,- "order_payment_confirmation_template_id",- ),- UserNotifyEvent.ORDER_CANCELED: (- send_order_canceled_email_task,- "order_canceled_template_id",- ),- UserNotifyEvent.ORDER_REFUND_CONFIRMATION: (- send_order_refund_email_task,- "order_refund_confirmation_template_id",- ),- UserNotifyEvent.SEND_GIFT_CARD: (- send_gift_card_email_task,- "send_gift_card_template_id",- ),-}--HELP_TEXT_TEMPLATE = "ID of the dynamic template in Sendgrid"---class DeprecatedSendgridEmailPlugin(BasePlugin):- """Deprecated.-- This plugin is deprecated and will be removed in future version.- """-- PLUGIN_ID = "mirumee.notifications.sendgrid_email"- PLUGIN_NAME = "Sendgrid"- DEFAULT_ACTIVE = False- CONFIGURATION_PER_CHANNEL = True-- DEFAULT_CONFIGURATION = [- {"name": "sender_name", "value": ""},- {"name": "sender_address", "value": ""},- {"name": "account_confirmation_template_id", "value": None},- {"name": "account_set_customer_password_template_id", "value": None},- {"name": "account_delete_template_id", "value": None},- {"name": "account_change_email_confirm_template_id", "value": None},- {"name": "account_change_email_request_template_id", "value": None},- {"name": "account_password_reset_template_id", "value": None},- {"name": "invoice_ready_template_id", "value": None},- {"name": "order_confirmation_template_id", "value": None},- {"name": "order_confirmed_template_id", "value": None},- {"name": "order_fulfillment_confirmation_template_id", "value": None},- {"name": "order_fulfillment_update_template_id", "value": None},- {"name": "order_payment_confirmation_template_id", "value": None},- {"name": "order_canceled_template_id", "value": None},- {"name": "order_refund_confirmation_template_id", "value": None},- {"name": "send_gift_card_template_id", "value": None},- {"name": "api_key", "value": None},- ]- CONFIG_STRUCTURE = {- "sender_name": {- "type": ConfigurationTypeField.STRING,- "help_text": "Name which will be visible as 'from' name.",- "label": "Sender name",- },- "sender_address": {- "type": ConfigurationTypeField.STRING,- "help_text": "Sender email which will be visible as 'from' email.",- "label": "Sender email",- },- "account_confirmation_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Account confirmation email template",- },- "account_set_customer_password_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Account set customer password email template",- },- "account_delete_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Account delete email template",- },- "account_change_email_confirm_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Account change email confirm email template",- },- "account_change_email_request_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Account change email request email template",- },- "account_password_reset_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Account password reset email template",- },- "invoice_ready_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Invoice ready email template",- },- "order_confirmation_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Order confirmation email template",- },- "order_confirmed_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": "The dynamic template ID for order confirmed.",- "label": "Order confirmed email template",- },- "order_fulfillment_confirmation_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Order fulfillment confirmation email template",- },- "order_fulfillment_update_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Order fulfillment update email template",- },- "order_payment_confirmation_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Order payment confirmation email template",- },- "order_canceled_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Order canceled email template",- },- "order_refund_confirmation_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Order refund confirmation email template",- },- "send_gift_card_template_id": {- "type": ConfigurationTypeField.STRING,- "help_text": HELP_TEXT_TEMPLATE,- "label": "Send gift card email template",- },- "api_key": {- "type": ConfigurationTypeField.SECRET,- "help_text": "Your Sendgrid API key.",- "label": "API key",- },- }-- def __init__(self, *args, **kwargs):- super().__init__(*args, **kwargs)- # Convert to dict to easier take config elements- configuration = {item["name"]: item["value"] for item in self.configuration}- self.config = SendgridConfiguration(**configuration)-- def notify(- self,- event: NotifyEventType | str,- payload_func: Callable[[], dict],- previous_value: None,- ) -> None:- if not self.active:- return previous_value-- event_in_notify_event = event in UserNotifyEvent.CHOICES-- if not event_in_notify_event:- logger.info("Send email with event %s as dynamic template ID.", event)- payload = payload_func()- send_email_with_dynamic_template_id.delay(- payload, event, asdict(self.config)- )- return previous_value-- if event not in EVENT_MAP:- logger.warning("Missing handler for event %s", event)- return previous_value-- configuration = {item["name"]: item["value"] for item in self.configuration}-- event_task, event_template = EVENT_MAP.get(event) # type: ignore[arg-type,misc]- template_id = configuration.get(event_template)- if not template_id:- # the empty fields means that we should not send an email for this event.- return previous_value- payload = payload_func()- event_task.delay(payload, asdict(self.config))- return previous_value-- @classmethod- def validate_plugin_configuration(- cls, plugin_configuration: "PluginConfiguration", **kwargs- ):- """Validate if provided configuration is correct."""- if not plugin_configuration.active:- return-- configuration = plugin_configuration.configuration- configuration = {item["name"]: item["value"] for item in configuration}- api_key = configuration.get("api_key")- if not api_key:- error_msg = "Missing SendGrid API Key"- raise ValidationError(- {- "api_key": ValidationError(- error_msg,- code=PluginErrorCode.NOT_FOUND.value,- ),- }- )diff --git a/saleor/plugins/sendgrid/tasks.py b/saleor/plugins/sendgrid/tasks.pydeleted file mode 100644index 60cccaaa1a..0000000000--- a/saleor/plugins/sendgrid/tasks.py+++ /dev/null@@ -1,363 +0,0 @@-import logging--from python_http_client import exceptions-from sendgrid import SendGridAPIClient, SendGridException-from sendgrid.helpers.mail import Mail--from ...account import events as account_events-from ...celeryconf import app-from ...core.db.connection import allow_writer-from ...giftcard import events as gift_card_events-from ...graphql.core.utils import from_global_id_or_none-from ...invoice import events as invoice_events-from ...order import events as order_events-from . import SendgridConfiguration--logger = logging.getLogger(__name__)--CELERY_RETRY_BACKOFF = 30-CELERY_RETRY_MAX = 5---def send_email(configuration: SendgridConfiguration, template_id, payload):- recipient_email = payload["recipient_email"]- sendgrid_client = SendGridAPIClient(configuration.api_key)- from_email = (configuration.sender_address, configuration.sender_name)- message = Mail(from_email=from_email, to_emails=recipient_email)- message.dynamic_template_data = payload- message.template_id = template_id- try:- sendgrid_client.send(message)- except exceptions.BadRequestsError as e:- logger.warning("Bad request to Sendgrid, response: %s", e.body)--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_account_confirmation_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.account_confirmation_template_id,- payload=payload,- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_password_reset_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- user_id = payload.get("user", {}).get("id")-- user_id = from_global_id_or_none(user_id)- send_email(- configuration=configuration,- template_id=configuration.account_password_reset_template_id,- payload=payload,- )- with allow_writer():- account_events.customer_password_reset_link_sent_event(user_id=user_id)--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_request_email_change_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- user_id = payload.get("user", {}).get("id")- send_email(- configuration=configuration,- template_id=configuration.account_change_email_request_template_id,- payload=payload,- )- with allow_writer():- account_events.customer_email_change_request_event(- user_id=from_global_id_or_none(user_id),- parameters={- "old_email": payload.get("old_email"),- "new_email": payload["recipient_email"],- },- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_user_change_email_notification_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- user_id = payload.get("user", {}).get("id")- send_email(- configuration=configuration,- template_id=configuration.account_change_email_confirm_template_id,- payload=payload,- )- event_parameters = {- "old_email": payload["old_email"],- "new_email": payload["new_email"],- }- with allow_writer():- account_events.customer_email_changed_event(- user_id=from_global_id_or_none(user_id), parameters=event_parameters- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_account_delete_confirmation_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.account_delete_template_id,- payload=payload,- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_set_user_password_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.account_set_customer_password_template_id,- payload=payload,- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_invoice_email_task(payload: dict, configuration: dict):- """Send an invoice to user of related order with URL to download it."""- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.invoice_ready_template_id,- payload=payload,- )- with allow_writer():- invoice_events.notification_invoice_sent_event(- user_id=from_global_id_or_none(payload["requester_user_id"]),- app_id=from_global_id_or_none(payload["requester_app_id"]),- invoice_id=from_global_id_or_none(payload["invoice"]["id"]),- customer_email=payload["recipient_email"],- )- order_events.event_invoice_sent_notification(- order_id=from_global_id_or_none(payload["invoice"]["order_id"]),- user_id=from_global_id_or_none(payload["requester_user_id"]),- app_id=from_global_id_or_none(payload["requester_app_id"]),- email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_order_confirmation_email_task(payload: dict, configuration: dict):- """Send order confirmation email."""- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_confirmation_template_id,- payload=payload,- )- with allow_writer():- order_events.event_order_confirmation_notification(- order_id=from_global_id_or_none(payload["order"]["id"]),- user_id=from_global_id_or_none(payload["order"].get("user_id")),- customer_email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_fulfillment_confirmation_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_fulfillment_confirmation_template_id,- payload=payload,- )- with allow_writer():- order_events.event_fulfillment_confirmed_notification(- order_id=from_global_id_or_none(payload["order"]["id"]),- user_id=from_global_id_or_none(payload["requester_user_id"]),- app_id=from_global_id_or_none(payload["requester_app_id"]),- customer_email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_fulfillment_update_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_fulfillment_update_template_id,- payload=payload,- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_payment_confirmation_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_payment_confirmation_template_id,- payload=payload,- )- with allow_writer():- order_events.event_payment_confirmed_notification(- order_id=from_global_id_or_none(payload["order"]["id"]),- user_id=from_global_id_or_none(payload["order"].get("user_id")),- customer_email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_order_canceled_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_canceled_template_id,- payload=payload,- )- with allow_writer():- order_events.event_order_cancelled_notification(- order_id=from_global_id_or_none(payload["order"]["id"]),- user_id=from_global_id_or_none(payload["requester_user_id"]),- app_id=from_global_id_or_none(payload["requester_app_id"]),- customer_email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_order_refund_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_refund_confirmation_template_id,- payload=payload,- )- with allow_writer():- order_events.event_order_refunded_notification(- order_id=from_global_id_or_none(payload["order"]["id"]),- user_id=from_global_id_or_none(payload["requester_user_id"]),- app_id=from_global_id_or_none(payload["requester_app_id"]),- customer_email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_gift_card_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.send_gift_card_template_id,- payload=payload,- )- email_data = {- "gift_card_id": from_global_id_or_none(payload["gift_card"]["id"]),- "user_id": from_global_id_or_none(payload["requester_user_id"]),- "app_id": from_global_id_or_none(payload["requester_app_id"]),- "email": payload["recipient_email"],- }- with allow_writer():- if payload["resending"] is True:- gift_card_events.gift_card_resent_event(**email_data)- else:- gift_card_events.gift_card_sent_event(**email_data)--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_order_confirmed_email_task(payload: dict, configuration: dict):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=configuration.order_confirmed_template_id,- payload=payload,- )- with allow_writer():- order_events.event_order_confirmed_notification(- order_id=from_global_id_or_none(payload.get("order", {}).get("id")),- user_id=from_global_id_or_none(payload.get("requester_user_id")),- app_id=from_global_id_or_none(payload["requester_app_id"]),- customer_email=payload["recipient_email"],- )--- autoretry_for=(SendGridException,),- retry_backoff=CELERY_RETRY_BACKOFF,- retry_kwargs={"max_retries": CELERY_RETRY_MAX},- compression="zlib",-)-def send_email_with_dynamic_template_id(- payload: dict, template_id: str, configuration: dict-):- configuration = SendgridConfiguration(**configuration)- send_email(- configuration=configuration,- template_id=template_id,- payload=payload,- )diff --git a/saleor/plugins/sendgrid/tests/__init__.py b/saleor/plugins/sendgrid/tests/__init__.pydeleted file mode 100644index e69de29bb2..0000000000diff --git a/saleor/plugins/sendgrid/tests/conftest.py b/saleor/plugins/sendgrid/tests/conftest.pydeleted file mode 100644index 69f69c532d..0000000000--- a/saleor/plugins/sendgrid/tests/conftest.py+++ /dev/null@@ -1,110 +0,0 @@-import pytest--from ....plugins.sendgrid.plugin import DeprecatedSendgridEmailPlugin-from ...manager import get_plugins_manager---def sendgrid_email_plugin(settings, channel_USD):- def fun(- active=True,- sender_name=None,- sender_address=None,- account_confirmation_template_id=None,- account_set_customer_password_template_id=None,- account_delete_template_id=None,- account_change_email_confirm_template_id=None,- account_change_email_request_template_id=None,- account_password_reset_template_id=None,- invoice_ready_template_id=None,- order_confirmation_template_id=None,- order_confirmed_template_id=None,- order_fulfillment_confirmation_template_id=None,- order_fulfillment_update_template_id=None,- order_payment_confirmation_template_id=None,- order_canceled_template_id=None,- order_refund_confirmation_template_id=None,- send_gift_card_template_id=None,- api_key=None,- ):- settings.PLUGINS = [- "saleor.plugins.sendgrid.plugin.DeprecatedSendgridEmailPlugin"- ]- manager = get_plugins_manager(allow_replica=False)- manager.save_plugin_configuration(- DeprecatedSendgridEmailPlugin.PLUGIN_ID,- channel_USD.slug,- {- "active": active,- "configuration": [- {"name": "sender_name", "value": sender_name},- {"name": "sender_address", "value": sender_address},- {- "name": "account_confirmation_template_id",- "value": account_confirmation_template_id,- },- {- "name": "account_set_customer_password_template_id",- "value": account_set_customer_password_template_id,- },- {- "name": "account_delete_template_id",- "value": account_delete_template_id,- },- {- "name": "account_change_email_confirm_template_id",- "value": account_change_email_confirm_template_id,- },- {- "name": "account_change_email_request_template_id",- "value": account_change_email_request_template_id,- },- {- "name": "account_password_reset_template_id",- "value": account_password_reset_template_id,- },- {- "name": "invoice_ready_template_id",- "value": invoice_ready_template_id,- },- {- "name": "order_confirmation_template_id",- "value": order_confirmation_template_id,- },- {- "name": "order_confirmed_template_id",- "value": order_confirmed_template_id,- },- {- "name": "order_fulfillment_confirmation_template_id",- "value": order_fulfillment_confirmation_template_id,- },- {- "name": "order_fulfillment_update_template_id",- "value": order_fulfillment_update_template_id,- },- {- "name": "order_payment_confirmation_template_id",- "value": order_payment_confirmation_template_id,- },- {- "name": "order_canceled_template_id",- "value": order_canceled_template_id,- },- {- "name": "order_refund_confirmation_template_id",- "value": order_refund_confirmation_template_id,- },- {- "name": "send_gift_card_template_id",- "value": send_gift_card_template_id,- },- {"name": "api_key", "value": api_key},- ],- },- )- manager = get_plugins_manager(allow_replica=False)- manager.get_all_plugins()- return manager.plugins_per_channel[channel_USD.slug][0]-- return fundiff --git a/saleor/plugins/sendgrid/tests/test_plugin.py b/saleor/plugins/sendgrid/tests/test_plugin.pydeleted file mode 100644index 0b5676f9a8..0000000000--- a/saleor/plugins/sendgrid/tests/test_plugin.py+++ /dev/null@@ -1,185 +0,0 @@-import json-from dataclasses import asdict-from unittest.mock import MagicMock, patch--import pytest-from django.core.exceptions import ValidationError--from ....account.notifications import get_user_custom_payload-from ....core.notify import AdminNotifyEvent, UserNotifyEvent-from ....webhook.payloads import generate_product_variant_payload-from ...models import PluginConfiguration-from ..plugin import EVENT_MAP---def test_get_event_map():- for event in UserNotifyEvent.CHOICES:- assert event in EVENT_MAP---@patch("saleor.plugins.sendgrid.tasks.send_email_with_dynamic_template_id.delay")-def test_notify_via_external_notification_trigger_with_extra_payload(- mocked_event_map,- staff_users,- sendgrid_email_plugin,-):- extra_payload = {"TEST": "VALUE", "TEST_LIST": ["GUEST1", "GUEST2"]}- plugin = sendgrid_email_plugin(- active=True, api_key="AB12", account_password_reset_template_id="123"- )-- expected_payload = [get_user_custom_payload(user) for user in staff_users]- for payload in expected_payload:- payload["extra_payload"] = extra_payload- test_template_id = "2efac70d-64ed-4e57-9951-f87e14d7e60e"- plugin.notify(test_template_id, lambda: expected_payload, None)-- mocked_event_map.assert_called_once_with(- expected_payload, test_template_id, asdict(plugin.config)- )---@patch("sendgrid.base_interface.BaseInterface.send")-def test_send_notification_to_customers_with_product_variant_payload(- base_interface_mock,- staff_users,- sendgrid_email_plugin,- product_with_single_variant,-):- plugin = sendgrid_email_plugin(active=True, api_key="AB12")- extra_payload = json.dumps(- json.loads(- generate_product_variant_payload(product_with_single_variant.variants.all())- )[0]- )-- expected_payload = [get_user_custom_payload(user) for user in staff_users]- for payload in expected_payload:- payload["extra_payload"] = extra_payload-- test_template_id = "2efac70d-64ed-4e57-9951-f87e14d7e60e"-- plugin.notify(test_template_id, lambda: expected_payload[0], None)-- base_interface_mock.assert_called_once()---@patch("saleor.plugins.sendgrid.plugin.EVENT_MAP")-def test_notify_when_plugin_disabled(mocked_event_map, sendgrid_email_plugin):- mocked_event_task = MagicMock()- event_map = {- UserNotifyEvent.ACCOUNT_PASSWORD_RESET: (- mocked_event_task,- "account_password_reset_template_id",- )- }- mocked_event_map.__getitem__.side_effect = event_map.__getitem__- mocked_event_map.get.side_effect = event_map.get-- plugin = sendgrid_email_plugin(active=False)-- plugin.notify(UserNotifyEvent.ACCOUNT_PASSWORD_RESET, {}, None)-- assert not mocked_event_task.delay.called---@patch("saleor.plugins.sendgrid.plugin.EVENT_MAP")-def test_notify_not_valid_event_type(mocked_event_map, sendgrid_email_plugin):- mocked_event_task = MagicMock()- event_map = {- UserNotifyEvent.ACCOUNT_PASSWORD_RESET: (- mocked_event_task,- "account_password_reset_template_id",- )- }- mocked_event_map.__getitem__.side_effect = event_map.__getitem__- mocked_event_map.get.side_effect = event_map.get-- plugin = sendgrid_email_plugin(api_key="AB12", active=True)-- plugin.notify(AdminNotifyEvent.CSV_EXPORT_FAILED, lambda: {"payload": 1}, None)-- assert not mocked_event_task.delay.called---@patch("saleor.plugins.sendgrid.plugin.EVENT_MAP")-def test_notify_missing_handler(mocked_event_map, sendgrid_email_plugin):- sample_payload = {"key_1": "value"}-- mocked_event_task = MagicMock()- event_map = {- UserNotifyEvent.ACCOUNT_CHANGE_EMAIL_REQUEST: (- mocked_event_task,- "account_password_reset_template_id",- )- }- mocked_event_map.__contains__.side_effect = event_map.__contains__-- plugin = sendgrid_email_plugin(api_key="AB12", active=True)-- plugin.notify(UserNotifyEvent.ACCOUNT_PASSWORD_RESET, sample_payload, None)-- assert mocked_event_map.__contains__.called- assert not mocked_event_task.delay.called---@patch("saleor.plugins.sendgrid.plugin.EVENT_MAP")-def test_notify_missing_template_id(mocked_event_map, sendgrid_email_plugin):- sample_payload = {"key_1": "value"}-- mocked_event_task = MagicMock()- event_map = {- UserNotifyEvent.ACCOUNT_PASSWORD_RESET: (- mocked_event_task,- "account_password_reset_template_id",- )- }- mocked_event_map.__getitem__.side_effect = event_map.__getitem__- mocked_event_map.__contains__.return_value = True- mocked_event_map.get.side_effect = event_map.get-- plugin = sendgrid_email_plugin(- active=True, api_key="AB12", account_password_reset_template_id=None- )-- plugin.notify(UserNotifyEvent.ACCOUNT_PASSWORD_RESET, sample_payload, None)-- assert mocked_event_map.get.called- assert not mocked_event_task.delay.called---@patch("saleor.plugins.sendgrid.plugin.EVENT_MAP")-def test_notify(mocked_event_map, sendgrid_email_plugin):- sample_payload = {"key_1": "value"}-- mocked_event_task = MagicMock()- event_map = {- UserNotifyEvent.ACCOUNT_PASSWORD_RESET: (- mocked_event_task,- "account_password_reset_template_id",- )- }- mocked_event_map.__getitem__.side_effect = event_map.__getitem__- mocked_event_map.__contains__.return_value = True- mocked_event_map.get.side_effect = event_map.get-- plugin = sendgrid_email_plugin(- active=True, api_key="AB12", account_password_reset_template_id="123"- )-- plugin.notify(UserNotifyEvent.ACCOUNT_PASSWORD_RESET, lambda: sample_payload, None)-- mocked_event_task.delay.assert_called_once_with(- sample_payload, asdict(plugin.config)- )---def test_save_plugin_configuration_missing_api_key(- sendgrid_email_plugin,-):- plugin = sendgrid_email_plugin(active=False)- configuration = PluginConfiguration.objects.get()-- data_to_save = {"active": True, "configuration": []}- with pytest.raises(ValidationError):- plugin.save_plugin_configuration(configuration, data_to_save)diff --git a/saleor/plugins/sendgrid/tests/test_tasks.py b/saleor/plugins/sendgrid/tests/test_tasks.pydeleted file mode 100644index 40d030d330..0000000000--- a/saleor/plugins/sendgrid/tests/test_tasks.py+++ /dev/null@@ -1,950 +0,0 @@-from dataclasses import asdict-from unittest.mock import Mock, patch--import pytest--from ....account import CustomerEvents-from ....account.models import CustomerEvent-from ....account.notifications import get_default_user_payload-from ....giftcard import GiftCardEvents-from ....giftcard.models import GiftCardEvent-from ....graphql.core.utils import to_global_id_or_none-from ....invoice import InvoiceEvents-from ....invoice.models import Invoice, InvoiceEvent-from ....order import OrderEvents, OrderEventsEmails-from ....order.models import OrderEvent-from ....order.notifications import (- get_default_fulfillment_payload,- get_default_order_payload,-)-from ..tasks import (- send_account_confirmation_email_task,- send_account_delete_confirmation_email_task,- send_email,- send_fulfillment_confirmation_email_task,- send_fulfillment_update_email_task,- send_gift_card_email_task,- send_invoice_email_task,- send_order_canceled_email_task,- send_order_confirmation_email_task,- send_order_confirmed_email_task,- send_order_refund_email_task,- send_password_reset_email_task,- send_payment_confirmation_email_task,- send_request_email_change_email_task,- send_set_user_password_email_task,- send_user_change_email_notification_task,-)---def sample_payload(customer_user):- token = "token123"- return {- "user": get_default_user_payload(customer_user),- "recipient_email": "[email protected]",- "token": token,- "reset_url": f"http://localhost:8000/redirect{token}",- "domain": "localhost:8000",- "site_name": "Saleor",- }---@patch("saleor.plugins.sendgrid.tasks.Mail")-@patch("saleor.plugins.sendgrid.tasks.SendGridAPIClient.send")-def test_send_email(- mocked_api_client, mocked_mail, sendgrid_email_plugin, sample_payload-):- plugin = sendgrid_email_plugin(- sender_name="Sender Name",- sender_address="[email protected]",- api_key="123",- )- template_id = "ABC"- recipient_email = sample_payload["recipient_email"]-- config = plugin.config-- mock_message = Mock()- mocked_mail.return_value = mock_message-- send_email(config, template_id=template_id, payload=sample_payload)-- mocked_mail.assert_called_with(- from_email=(config.sender_address, config.sender_name),- to_emails=recipient_email,- )-- mock_message.dynamic_template_data = sample_payload- mock_message.template_id = template_id-- mocked_api_client.assert_called_with(mock_message)---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_account_confirmation_email_task(- mocked_send_email, customer_user, sendgrid_email_plugin-):- template_id = "ABC1"- recipient_email = "[email protected]"- token = "token123"- payload = {- "user": get_default_user_payload(customer_user),- "recipient_email": recipient_email,- "token": token,- "reset_url": f"http://localhost:8000/redirect{token}",- "domain": "localhost:8000",- "site_name": "Saleor",- }-- plugin = sendgrid_email_plugin(- api_key="AB12", account_confirmation_template_id=template_id- )-- send_account_confirmation_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_password_reset_email_task(- mocked_send_email, customer_user, sendgrid_email_plugin-):- template_id = "ABC1"- recipient_email = "[email protected]"- token = "token123"- payload = {- "user": get_default_user_payload(customer_user),- "recipient_email": recipient_email,- "token": token,- "reset_url": f"http://localhost:8000/redirect{token}",- "domain": "localhost:8000",- "site_name": "Saleor",- }-- plugin = sendgrid_email_plugin(- api_key="A12",- account_password_reset_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_password_reset_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )- event = CustomerEvent.objects.get()- assert event.type == CustomerEvents.PASSWORD_RESET_LINK_SENT- assert event.user == customer_user---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_request_email_change_email_task(- mocked_send_email, customer_user, sendgrid_email_plugin-):- template_id = "ABC1"- token = "token123"- recipient_email = "[email protected]"- payload = {- "user": get_default_user_payload(customer_user),- "recipient_email": recipient_email,- "token": token,- "redirect_url": f"http://localhost:8000/redirect{token}",- "old_email": "[email protected]",- "new_email": "[email protected]",- "site_name": "Saleor",- "domain": "localhost:8000",- }-- plugin = sendgrid_email_plugin(- api_key="A12",- account_change_email_request_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_request_email_change_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )- event = CustomerEvent.objects.get()- assert event.type == CustomerEvents.EMAIL_CHANGE_REQUEST- assert event.user == customer_user- assert event.parameters == {- "old_email": payload["old_email"],- "new_email": payload["recipient_email"],- }---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_user_change_email_notification_task(- mocked_send_email, customer_user, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "user": get_default_user_payload(customer_user),- "recipient_email": recipient_email,- "site_name": "Saleor",- "domain": "localhost:8000",- "old_email": "[email protected]",- "new_email": recipient_email,- }-- plugin = sendgrid_email_plugin(- api_key="A12",- account_change_email_confirm_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_user_change_email_notification_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )- event = CustomerEvent.objects.get()- assert event.type == CustomerEvents.EMAIL_CHANGED- assert event.user == customer_user- assert event.parameters == {- "old_email": payload["old_email"],- "new_email": payload["recipient_email"],- }---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_account_delete_confirmation_email_task(- mocked_send_email, customer_user, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- token = "token123"- payload = {- "user": get_default_user_payload(customer_user),- "recipient_email": recipient_email,- "token": token,- "delete_url": f"http://localhost:8000/redirect{token}",- "site_name": "Saleor",- "domain": "localhost:8000",- }-- plugin = sendgrid_email_plugin(- api_key="A12",- account_delete_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_account_delete_confirmation_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_set_user_password_email_task(- mocked_send_email, customer_user, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- token = "token123"- payload = {- "user": get_default_user_payload(customer_user),- "recipient_email": recipient_email,- "token": token,- "password_set_url": f"http://localhost:8000/redirect{token}",- "site_name": "Saleor",- "domain": "localhost:8000",- }-- plugin = sendgrid_email_plugin(- api_key="A12",- account_set_customer_password_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_set_user_password_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_invoice_email_task_by_user(- mocked_send_email, staff_user, order, sendgrid_email_plugin-):- template_id = "ABC1"-- invoice = Invoice.objects.create(order=order)- recipient_email = "[email protected]"- payload = {- "invoice": {- "id": to_global_id_or_none(invoice),- "order_id": to_global_id_or_none(order),- "number": 999,- "download_url": "http://localhost:8000/download",- },- "recipient_email": recipient_email,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": to_global_id_or_none(staff_user),- "requester_app_id": None,- }-- plugin = sendgrid_email_plugin(- api_key="A12",- invoice_ready_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_invoice_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )- invoice_event = InvoiceEvent.objects.get()- assert invoice_event.type == InvoiceEvents.SENT- assert not invoice_event.app- assert invoice_event.user == staff_user-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.INVOICE_SENT- assert order_event.user == staff_user- assert not order_event.app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_invoice_email_task_by_app(- mocked_send_email, app, order, sendgrid_email_plugin-):- template_id = "ABC1"-- invoice = Invoice.objects.create(order=order)- recipient_email = "[email protected]"- payload = {- "invoice": {- "id": to_global_id_or_none(invoice),- "order_id": to_global_id_or_none(order),- "number": 999,- "download_url": "http://localhost:8000/download",- },- "recipient_email": recipient_email,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": None,- "requester_app_id": to_global_id_or_none(app),- }-- plugin = sendgrid_email_plugin(- api_key="A12",- invoice_ready_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_invoice_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )- invoice_event = InvoiceEvent.objects.get()- assert invoice_event.type == InvoiceEvents.SENT- assert invoice_event.app == app- assert not invoice_event.user-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.INVOICE_SENT- assert order_event.app == app- assert not order_event.user---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_confirmation_email_task(- mocked_send_email, staff_user, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "site_name": "Saleor",- "domain": "localhost:8000",- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_confirmation_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_confirmation_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.ORDER_CONFIRMATION,- }---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_fulfillment_confirmation_email_task_by_user(- mocked_send_email, staff_user, fulfillment, order, sendgrid_email_plugin-):- template_id = "ABC1"-- payload = get_default_fulfillment_payload(order, fulfillment)- payload["requester_user_id"] = to_global_id_or_none(staff_user)- payload["requester_app_id"] = None-- plugin = sendgrid_email_plugin(- api_key="A12",- order_fulfillment_confirmation_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_fulfillment_confirmation_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.user == staff_user- assert not order_event.app- assert order_event.parameters == {- "email": order.user_email,- "email_type": OrderEventsEmails.FULFILLMENT,- }---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_fulfillment_confirmation_email_task_by_app(- mocked_send_email, app, fulfillment, order, sendgrid_email_plugin-):- template_id = "ABC1"-- payload = get_default_fulfillment_payload(order, fulfillment)- payload["requester_user_id"] = None- payload["requester_app_id"] = to_global_id_or_none(app)-- plugin = sendgrid_email_plugin(- api_key="A12",- order_fulfillment_confirmation_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_fulfillment_confirmation_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert not order_event.user- assert order_event.app == app- assert order_event.parameters == {- "email": order.user_email,- "email_type": OrderEventsEmails.FULFILLMENT,- }---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_fulfillment_update_email_task(- mocked_send_email, staff_user, fulfillment, order, sendgrid_email_plugin-):- template_id = "ABC1"-- payload = get_default_fulfillment_payload(order, fulfillment)-- plugin = sendgrid_email_plugin(- api_key="A12",- order_fulfillment_update_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_fulfillment_update_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_payment_confirmation_email_task(- mocked_send_email, payment_dummy, staff_user, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "payment": {- "created": payment_dummy.created_at,- "modified": payment_dummy.modified_at,- "charge_status": payment_dummy.charge_status,- "total": payment_dummy.total,- "captured_amount": payment_dummy.captured_amount,- "currency": payment_dummy.currency,- },- "site_name": "Saleor",- "domain": "localhost:8000",- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_payment_confirmation_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_payment_confirmation_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.PAYMENT,- }---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_canceled_email_task_by_user(- mocked_send_email, staff_user, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": to_global_id_or_none(staff_user),- "requester_app_id": None,- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_canceled_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_canceled_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.ORDER_CANCEL,- }- assert not order_event.app- assert order_event.user == staff_user---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_canceled_email_task_by_app(- mocked_send_email, app, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": None,- "requester_app_id": to_global_id_or_none(app),- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_canceled_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_canceled_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.ORDER_CANCEL,- }- assert not order_event.user- assert order_event.app == app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_refund_email_task_by_user(- mocked_send_email, staff_user, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "amount": order.total_gross_amount,- "currency": order.currency,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": to_global_id_or_none(staff_user),- "requester_app_id": None,- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_refund_confirmation_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_refund_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.ORDER_REFUND,- }- assert not order_event.app- assert order_event.user == staff_user---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_refund_email_task_by_app(- mocked_send_email, app, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "amount": order.total_gross_amount,- "currency": order.currency,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": None,- "requester_app_id": to_global_id_or_none(app),- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_refund_confirmation_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_refund_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.ORDER_REFUND,- }- assert not order_event.user- assert order_event.app == app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_gift_card_email_task_by_user(- mocked_send_email, staff_user, gift_card, sendgrid_email_plugin-):- template_id = "ABC1"- recipient_email = "[email protected]"-- payload = {- "user": get_default_user_payload(staff_user),- "requester_user_id": to_global_id_or_none(staff_user),- "requester_app_id": None,- "recipient_email": recipient_email,- "resending": False,- "gift_card": {- "id": to_global_id_or_none(gift_card),- "code": gift_card.code,- "balance": gift_card.current_balance_amount,- "currency": gift_card.currency,- },- }-- plugin = sendgrid_email_plugin(- api_key="A12",- send_gift_card_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_gift_card_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- gift_card_event = GiftCardEvent.objects.get()- assert gift_card_event.type == GiftCardEvents.SENT_TO_CUSTOMER- assert gift_card_event.parameters == {- "email": recipient_email,- }- assert gift_card_event.user == staff_user- assert not gift_card_event.app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_gift_card_email_task_by_user_resending(- mocked_send_email, staff_user, gift_card, sendgrid_email_plugin-):- template_id = "ABC1"- recipient_email = "[email protected]"-- payload = {- "user": get_default_user_payload(staff_user),- "requester_user_id": to_global_id_or_none(staff_user),- "requester_app_id": None,- "recipient_email": recipient_email,- "resending": True,- "gift_card": {- "id": to_global_id_or_none(gift_card),- "code": gift_card.code,- "balance": gift_card.current_balance_amount,- "currency": gift_card.currency,- },- }-- plugin = sendgrid_email_plugin(- api_key="A12",- send_gift_card_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_gift_card_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- gift_card_event = GiftCardEvent.objects.get()- assert gift_card_event.type == GiftCardEvents.RESENT- assert gift_card_event.parameters == {- "email": recipient_email,- }- assert gift_card_event.user == staff_user- assert not gift_card_event.app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_gift_card_email_task_by_app(- mocked_send_email, app, gift_card, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "user": None,- "requester_user_id": None,- "requester_app_id": to_global_id_or_none(app),- "recipient_email": recipient_email,- "resending": False,- "gift_card": {- "id": to_global_id_or_none(gift_card),- "code": gift_card.code,- "balance": gift_card.current_balance_amount,- "currency": gift_card.currency,- },- }-- plugin = sendgrid_email_plugin(- api_key="A12",- send_gift_card_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_gift_card_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- gift_card_event = GiftCardEvent.objects.get()- assert gift_card_event.type == GiftCardEvents.SENT_TO_CUSTOMER- assert gift_card_event.parameters == {- "email": recipient_email,- }- assert not gift_card_event.user- assert gift_card_event.app == app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_confirmed_email_task_by_user(- mocked_send_email, staff_user, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "amount": order.total_gross_amount,- "currency": order.currency,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": to_global_id_or_none(staff_user),- "requester_app_id": None,- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_confirmed_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_confirmed_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.CONFIRMED,- }- assert order_event.user == staff_user- assert not order_event.app---@patch("saleor.plugins.sendgrid.tasks.send_email")-def test_send_order_confirmed_email_task_by_app(- mocked_send_email, app, order, sendgrid_email_plugin-):- template_id = "ABC1"-- recipient_email = "[email protected]"- payload = {- "order": get_default_order_payload(order, "http://localhost:8000/redirect"),- "recipient_email": recipient_email,- "amount": order.total_gross_amount,- "currency": order.currency,- "site_name": "Saleor",- "domain": "localhost:8000",- "requester_user_id": None,- "requester_app_id": to_global_id_or_none(app),- }-- plugin = sendgrid_email_plugin(- api_key="A12",- order_confirmed_template_id=template_id,- sender_name="Sender Name",- sender_address="[email protected]",- )-- send_order_confirmed_email_task(payload, asdict(plugin.config))-- mocked_send_email.assert_called_with(- configuration=plugin.config,- template_id=template_id,- payload=payload,- )-- order_event = OrderEvent.objects.get()- assert order_event.type == OrderEvents.EMAIL_SENT- assert order_event.parameters == {- "email": recipient_email,- "email_type": OrderEventsEmails.CONFIRMED,- }- assert not order_event.user- assert order_event.app == appdiff --git a/saleor/settings.py b/saleor/settings.pyindex 2d3081ee01..42ba1a03d5 100644--- a/saleor/settings.py+++ b/saleor/settings.py@@ -947,7 +947,6 @@ BUILTIN_PLUGINS = ["saleor.payment.gateways.stripe.plugin.StripeGatewayPlugin","saleor.plugins.user_email.plugin.UserEmailPlugin","saleor.plugins.admin_email.plugin.AdminEmailPlugin",- "saleor.plugins.sendgrid.plugin.DeprecatedSendgridEmailPlugin","saleor.plugins.openid_connect.plugin.OpenIDConnectPlugin",]diff --git a/uv.lock b/uv.lockindex 1471e8a318..48021652b4 100644--- a/uv.lock+++ b/uv.lock@@ -2269,15 +2269,6 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/0b/d7/1959b9648791274998a9c3526f6d0ec8fd2233e4d4acce81bbae76b44b2a/python_dotenv-1.2.2-py3-none-any.whl", hash = "sha256:1d8214789a24de455a8b8bd8ae6fe3c6b69a5e3d64aa8a8e5d68e694bbcb285a", size = 22101, upload-time = "2026-03-01T16:00:25.09Z" },]-[[package]]-name = "python-http-client"-version = "3.3.7"-source = { registry = "https://pypi.org/simple" }-sdist = { url = "https://files.pythonhosted.org/packages/56/fa/284e52a8c6dcbe25671f02d217bf2f85660db940088faf18ae7a05e97313/python_http_client-3.3.7.tar.gz", hash = "sha256:bf841ee45262747e00dec7ee9971dfb8c7d83083f5713596488d67739170cea0", size = 9377, upload-time = "2022-03-09T20:23:56.386Z" }-wheels = [- { url = "https://files.pythonhosted.org/packages/29/31/9b360138f4e4035ee9dac4fe1132b6437bd05751aaf1db2a2d83dc45db5f/python_http_client-3.3.7-py3-none-any.whl", hash = "sha256:ad371d2bbedc6ea15c26179c6222a78bc9308d272435ddf1d5c84f068f249a36", size = 8352, upload-time = "2022-03-09T20:23:54.862Z" },-]-[[package]]name = "python-json-logger"version = "3.2.1"@@ -2527,7 +2518,6 @@ dependencies = [{ name = "pydantic-core" },{ name = "pyjwt" },{ name = "python-dateutil" },- { name = "python-http-client" },{ name = "python-json-logger" },{ name = "python-magic", marker = "sys_platform != 'win32'" },{ name = "python-magic-bin", marker = "sys_platform == 'win32'" },@@ -2537,7 +2527,6 @@ dependencies = [{ name = "requests-hardened" },{ name = "rx" },{ name = "semantic-version" },- { name = "sendgrid" },{ name = "sentry-sdk" },{ name = "stripe" },{ name = "text-unidecode" },@@ -2636,7 +2625,6 @@ requires-dist = [{ name = "pydantic-core", specifier = ">=2.33.0,<3" },{ name = "pyjwt", specifier = ">=2.13.0,<3" },{ name = "python-dateutil", specifier = ">=2.8.2,<3" },- { name = "python-http-client", specifier = ">=3.3.7,<4" },{ name = "python-json-logger", specifier = ">=0.1.11,<3.3.0" },{ name = "python-magic", marker = "sys_platform != 'win32'", specifier = ">=0.4.27,<0.5" },{ name = "python-magic-bin", marker = "sys_platform == 'win32'", specifier = ">=0.4.14,<0.5" },@@ -2646,7 +2634,6 @@ requires-dist = [{ name = "requests-hardened", specifier = ">=1.3.0,<2.0.0" },{ name = "rx", specifier = ">=1.6.3,<2" },{ name = "semantic-version", specifier = ">=2.10.0,<3" },- { name = "sendgrid", specifier = ">=6.12.5,<7" },{ name = "sentry-sdk", specifier = "~=2.58" },{ name = "stripe", specifier = ">=3.0.0,<4" },{ name = "text-unidecode", specifier = "~=1.2" },@@ -2699,20 +2686,6 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/6a/23/8146aad7d88f4fcb3a6218f41a60f6c2d4e3a72de72da1825dc7c8f7877c/semantic_version-2.10.0-py2.py3-none-any.whl", hash = "sha256:de78a3b8e0feda74cabc54aab2da702113e33ac9d9eb9d2389bcf1f58b7d9177", size = 15552, upload-time = "2022-05-26T13:35:21.206Z" },]-[[package]]-name = "sendgrid"-version = "6.12.5"-source = { registry = "https://pypi.org/simple" }-dependencies = [- { name = "cryptography" },- { name = "python-http-client" },- { name = "werkzeug" },-]-sdist = { url = "https://files.pythonhosted.org/packages/da/fa/f718b2b953f99c1f0085811598ac7e31ccbd4229a81ec2a5290be868187a/sendgrid-6.12.5.tar.gz", hash = "sha256:ea9aae30cd55c332e266bccd11185159482edfc07c149b6cd15cf08869fabdb7", size = 50310, upload-time = "2025-09-19T06:23:09.229Z" }-wheels = [- { url = "https://files.pythonhosted.org/packages/bd/55/b3c3880a77082e8f7374954e0074aafafaa9bc78bdf9c8f5a92c2e7afc6a/sendgrid-6.12.5-py3-none-any.whl", hash = "sha256:96f92cc91634bf552fdb766b904bbb53968018da7ae41fdac4d1090dc0311ca8", size = 102173, upload-time = "2025-09-19T06:23:07.93Z" },-]-[[package]]name = "sentry-sdk"version = "2.58.0"@@ -3160,18 +3133,6 @@ wheels = [{ url = "https://files.pythonhosted.org/packages/fa/a8/5b41e0da817d64113292ab1f8247140aac61cbf6cfd085d6a0fa77f4984f/websockets-15.0.1-py3-none-any.whl", hash = "sha256:f7a866fbc1e97b5c617ee4116daaa09b722101d4a3c170c787450ba409f9736f", size = 169743, upload-time = "2025-03-05T20:03:39.41Z" },]-[[package]]-name = "werkzeug"-version = "3.1.6"-source = { registry = "https://pypi.org/simple" }-dependencies = [- { name = "markupsafe" },-]-sdist = { url = "https://files.pythonhosted.org/packages/61/f1/ee81806690a87dab5f5653c1f146c92bc066d7f4cebc603ef88eb9e13957/werkzeug-3.1.6.tar.gz", hash = "sha256:210c6bede5a420a913956b4791a7f4d6843a43b6fcee4dfa08a65e93007d0d25", size = 864736, upload-time = "2026-02-19T15:17:18.884Z" }-wheels = [- { url = "https://files.pythonhosted.org/packages/4d/ec/d58832f89ede95652fd01f4f24236af7d32b70cab2196dfcc2d2fd13c5c2/werkzeug-3.1.6-py3-none-any.whl", hash = "sha256:7ddf3357bb9564e407607f988f683d72038551200c704012bb9a4c523d42f131", size = 225166, upload-time = "2026-02-19T15:17:17.475Z" },-]-[[package]]name = "wrapt"version = "1.17.3"