mirror of
https://github.com/inventree/InvenTree.git
synced 2025-05-02 13:28:49 +00:00
Prevent plugin URL routing if ENABLE_PLUGINS_URL setting is disabled (#5648)
* Prevent plugin URL routing if ENABLE_PLUGINS_URL setting is disabled * Fix for unit test * Improve unit testing
This commit is contained in:
parent
30cf97d85b
commit
6521ce5216
@ -11,8 +11,33 @@ class SampleIntegrationPluginTests(InvenTreeTestCase):
|
|||||||
|
|
||||||
def test_view(self):
|
def test_view(self):
|
||||||
"""Check the function of the custom sample plugin."""
|
"""Check the function of the custom sample plugin."""
|
||||||
response = self.client.get('/plugin/sample/ho/he/')
|
|
||||||
|
from common.models import InvenTreeSetting
|
||||||
|
|
||||||
|
url = '/plugin/sample/ho/he/'
|
||||||
|
|
||||||
|
# First, check with custom URLs disabled
|
||||||
|
InvenTreeSetting.set_setting('ENABLE_PLUGINS_URL', False, None)
|
||||||
|
|
||||||
|
# Requires a full reload of the registry
|
||||||
|
registry.reload_plugins()
|
||||||
|
|
||||||
|
# URL should redirect to index page
|
||||||
|
response = self.client.get(url)
|
||||||
|
self.assertEqual(response.status_code, 302)
|
||||||
|
|
||||||
|
# Now, check with custom URLs enabled
|
||||||
|
InvenTreeSetting.set_setting('ENABLE_PLUGINS_URL', True, None)
|
||||||
|
|
||||||
|
# Requires a full reload of the registry
|
||||||
|
registry.reload_plugins()
|
||||||
|
|
||||||
|
# And ensure that the plugin is enabled
|
||||||
|
registry.set_plugin_state('sample', True)
|
||||||
|
|
||||||
|
response = self.client.get(url)
|
||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
|
|
||||||
self.assertEqual(response.content, b'Hi there testuser this works')
|
self.assertEqual(response.content, b'Hi there testuser this works')
|
||||||
|
|
||||||
def test_settings(self):
|
def test_settings(self):
|
||||||
|
@ -7,10 +7,13 @@ PLUGIN_BASE = 'plugin' # Constant for links
|
|||||||
|
|
||||||
def get_plugin_urls():
|
def get_plugin_urls():
|
||||||
"""Returns a urlpattern that can be integrated into the global urls."""
|
"""Returns a urlpattern that can be integrated into the global urls."""
|
||||||
|
from common.models import InvenTreeSetting
|
||||||
from plugin import registry
|
from plugin import registry
|
||||||
|
|
||||||
urls = []
|
urls = []
|
||||||
|
|
||||||
|
# Only allow custom routing if the setting is enabled
|
||||||
|
if InvenTreeSetting.get_setting('ENABLE_PLUGINS_URL', False, create=False, cache=False):
|
||||||
for plugin in registry.plugins.values():
|
for plugin in registry.plugins.values():
|
||||||
if plugin.mixin_enabled('urls'):
|
if plugin.mixin_enabled('urls'):
|
||||||
urls.append(plugin.urlpatterns)
|
urls.append(plugin.urlpatterns)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user