Use registry.get_plugin() (#6408)

- Instead of registry.plugins.get()
- get_plugin checks registry hash
- performs registry reload if necessary
This commit is contained in:
Oliver 2024-02-05 15:51:45 +11:00 committed by GitHub
parent 3a48af6bd4
commit e9c6dd8273
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 6 deletions

View File

@ -142,7 +142,7 @@ class NotificationMethod:
return False
# Check if method globally enabled
plg_instance = registry.plugins.get(plg_cls.NAME.lower())
plg_instance = registry.get_plugin(plg_cls.NAME.lower())
if plg_instance and not plg_instance.get_setting(self.GLOBAL_SETTING):
return True

View File

@ -89,7 +89,7 @@ def process_event(plugin_slug, event, *args, **kwargs):
This function is run by the background worker process.
This function may queue multiple functions to be handled by the background worker.
"""
plugin = registry.plugins.get(plugin_slug, None)
plugin = registry.get_plugin(plugin_slug)
if plugin is None: # pragma: no cover
logger.error("Could not find matching plugin for '%s'", plugin_slug)

View File

@ -9,7 +9,7 @@ class EventMixin:
Implementing classes must provide a "process_event" function:
"""
def wants_process_event(self, event):
def wants_process_event(self, event: str) -> bool:
"""Function to subscribe to events.
Return true if you're interested in the given event, false if not.
@ -17,7 +17,7 @@ class EventMixin:
# Default implementation always returns true (backwards compatibility)
return True
def process_event(self, event, *args, **kwargs):
def process_event(self, event: str, *args, **kwargs) -> None:
"""Function to handle events.
Must be overridden by plugin

View File

@ -133,7 +133,7 @@ class InvenTreeCoreNotificationsPlugin(
def send_bulk(self):
"""Send the notifications out via slack."""
instance = registry.plugins.get(self.get_plugin().NAME.lower())
instance = registry.get_plugin(self.get_plugin().NAME.lower())
url = instance.get_setting('NOTIFICATION_SLACK_URL')
if not url:

View File

@ -19,7 +19,7 @@ class CoreNotificationTestTests(BaseNotificationIntegrationTest):
self.assertEqual(len(mail.outbox), 0)
# enable plugin and set mail setting to true
plugin = registry.plugins.get('inventreecorenotificationsplugin')
plugin = registry.get_plugin('inventreecorenotificationsplugin')
plugin.set_setting('ENABLE_NOTIFICATION_EMAILS', True)
NotificationUserSetting.set_setting(
key='NOTIFICATION_METHOD_MAIL',