Coverage for src/backend/InvenTree/plugin/base/integration/NotificationMixin.py: 86%
19 statements
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
« prev ^ index » next coverage.py v7.15.2, created at 2026-10-07 17:47 +0000
1"""Plugin mixin class for supporting third-party notification methods."""
3from typing import TYPE_CHECKING
5from django.contrib.auth.models import User
6from django.db.models import Model
8import structlog
10from plugin import PluginMixinEnum
12logger = structlog.get_logger('inventree')
14if TYPE_CHECKING: 14 ↛ 15line 14 didn't jump to line 15 because the condition on line 14 was never true
15 from common.models import SettingsKeyType
16else:
18 class SettingsKeyType:
19 """Dummy class, so that python throws no error."""
22class NotificationMixin:
23 """Plugin mixin class for supporting third-party notification methods."""
25 class MixinMeta:
26 """Meta for mixin."""
28 MIXIN_NAME = PluginMixinEnum.NOTIFICATION
30 def __init__(self):
31 """Register mixin."""
32 super().__init__()
33 self.add_mixin(PluginMixinEnum.NOTIFICATION, True, __class__)
35 def filter_targets(self, targets: list[User]) -> list[User]:
36 """Filter notification targets based on the plugin's logic."""
37 # Default implementation returns all targets
38 return targets
40 def send_notification(
41 self, target: Model, category: str, users: list, context: dict
42 ) -> bool:
43 """Send notification to the specified target users.
45 Arguments:
46 target (Model): The target model instance to which the notification relates.
47 category (str): The category of the notification.
48 users (list): List of users to send the notification to.
49 context (dict): Context data for the notification.
51 Returns:
52 bool: True if the notification was sent successfully, False otherwise.
53 """
54 # The default implementation does nothing
55 return False