2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-04-29 20:16:44 +00:00

Use registry.get_plugin() (#6408) (#6409)

- Instead of registry.plugins.get()
- get_plugin checks registry hash
- performs registry reload if necessary

(cherry picked from commit e9c6dd82737832052cc647b4161658d75d6b66fd)

Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
This commit is contained in:
github-actions[bot] 2024-02-05 17:18:13 +11:00 committed by GitHub
parent 75f507d4c7
commit 39176d9a19
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 6 additions and 6 deletions

View File

@ -133,7 +133,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

@ -99,7 +99,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(SettingsContentMixin, SettingsMixin, Inve
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

@ -18,7 +18,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',