mirror of
https://github.com/inventree/InvenTree.git
synced 2026-11-25 01:03:07 +00:00
* Deduplicate social backends
- Closes https://github.com/inventree/InvenTree/issues/13044
- Fixes bug which can cause duplication of social backends
- Added regression tests
* Update src/backend/InvenTree/InvenTree/config.py
Simplify implementation
* Ensure consistent ordering
* Bump API version
---------
(cherry picked from commit a91f079530)
Co-authored-by: Oliver <oliver.henry.walters@gmail.com>
Co-authored-by: Philipp Fruck <dev@p-fruck.de>
This commit is contained in:
4 files changed
+56
-10
No files matched your search
@@ -1,11 +1,14 @@
|
|||||||
"""InvenTree API version information."""
|
"""InvenTree API version information."""
|
||||||
|
|
||||||
# InvenTree API version
|
# InvenTree API version
|
||||||
INVENTREE_API_VERSION = 560
|
INVENTREE_API_VERSION = 561
|
||||||
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
"""Increment this API version number whenever there is a significant change to the API that any clients need to know about."""
|
||||||
|
|
||||||
INVENTREE_API_TEXT = """
|
INVENTREE_API_TEXT = """
|
||||||
|
|
||||||
|
v561 -> 2026-10-21 : https://github.com/inventree/InvenTree/pull/13046
|
||||||
|
- Fix ordering of social applications in API schema
|
||||||
|
|
||||||
v560 -> 2026-10-17 : https://github.com/inventree/InvenTree/pull/12737
|
v560 -> 2026-10-17 : https://github.com/inventree/InvenTree/pull/12737
|
||||||
- Adds search and ordering fields across remaining API endpoints (machine, stock, importer, report)
|
- Adds search and ordering fields across remaining API endpoints (machine, stock, importer, report)
|
||||||
|
|
||||||
|
|||||||
@@ -546,6 +546,22 @@ def get_custom_file(
|
|||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
||||||
|
def get_social_backends(defaults: list[str], backends: list[str]) -> list[str]:
|
||||||
|
"""Return a de-duplicated list of fully-qualified allauth social provider apps.
|
||||||
|
|
||||||
|
Backends may be specified either as the short provider name (e.g. 'openid_connect')
|
||||||
|
or the full module path (e.g. 'allauth.socialaccount.providers.openid_connect').
|
||||||
|
Names are normalized before de-duplication, so both forms map to the same app.
|
||||||
|
The returned list is sorted alphabetically.
|
||||||
|
"""
|
||||||
|
prefix = 'allauth.socialaccount.providers.'
|
||||||
|
|
||||||
|
return sorted({
|
||||||
|
app if app.startswith(prefix) else prefix + app
|
||||||
|
for app in [*defaults, *backends]
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
def get_frontend_settings(debug=True):
|
def get_frontend_settings(debug=True):
|
||||||
"""Return a dictionary of settings for the frontend interface."""
|
"""Return a dictionary of settings for the frontend interface."""
|
||||||
# New settings
|
# New settings
|
||||||
|
|||||||
@@ -994,17 +994,9 @@ SOCIAL_BACKENDS = get_setting(
|
|||||||
)
|
)
|
||||||
|
|
||||||
DEFAULT_SOCIAL = ['saml', 'openid_connect']
|
DEFAULT_SOCIAL = ['saml', 'openid_connect']
|
||||||
_SOCIAL_BACKENDS = list(dict.fromkeys([*DEFAULT_SOCIAL, *SOCIAL_BACKENDS]))
|
|
||||||
|
|
||||||
# region auth
|
# region auth
|
||||||
for app in _SOCIAL_BACKENDS: # pragma: no cover
|
INSTALLED_APPS.extend(config.get_social_backends(DEFAULT_SOCIAL, SOCIAL_BACKENDS))
|
||||||
# Ensure that the app starts with 'allauth.socialaccount.providers'
|
|
||||||
social_prefix = 'allauth.socialaccount.providers.'
|
|
||||||
|
|
||||||
if not app.startswith(social_prefix):
|
|
||||||
app = social_prefix + app
|
|
||||||
|
|
||||||
INSTALLED_APPS.append(app)
|
|
||||||
|
|
||||||
SOCIALACCOUNT_PROVIDERS = {a: {} for a in DEFAULT_SOCIAL}
|
SOCIALACCOUNT_PROVIDERS = {a: {} for a in DEFAULT_SOCIAL}
|
||||||
_PROVIDER_SETTINGS = get_setting(
|
_PROVIDER_SETTINGS = get_setting(
|
||||||
|
|||||||
@@ -1328,6 +1328,41 @@ class TestSettings(InvenTreeTestCase):
|
|||||||
|
|
||||||
set_global_setting('PLUGIN_ON_STARTUP', False)
|
set_global_setting('PLUGIN_ON_STARTUP', False)
|
||||||
|
|
||||||
|
def test_social_backends(self):
|
||||||
|
"""Test that social backends are normalized and de-duplicated."""
|
||||||
|
prefix = 'allauth.socialaccount.providers.'
|
||||||
|
defaults = ['saml', 'openid_connect']
|
||||||
|
|
||||||
|
# Full module path for a default backend must not produce a duplicate
|
||||||
|
self.assertEqual(
|
||||||
|
config.get_social_backends(defaults, [f'{prefix}openid_connect']),
|
||||||
|
[f'{prefix}openid_connect', f'{prefix}saml'],
|
||||||
|
)
|
||||||
|
|
||||||
|
# Mixed short and full names, with duplicates, are sorted alphabetically
|
||||||
|
self.assertEqual(
|
||||||
|
config.get_social_backends(
|
||||||
|
defaults, ['github', f'{prefix}github', 'saml', f'{prefix}google']
|
||||||
|
),
|
||||||
|
[
|
||||||
|
f'{prefix}github',
|
||||||
|
f'{prefix}google',
|
||||||
|
f'{prefix}openid_connect',
|
||||||
|
f'{prefix}saml',
|
||||||
|
],
|
||||||
|
)
|
||||||
|
|
||||||
|
# No extra backends
|
||||||
|
self.assertEqual(
|
||||||
|
config.get_social_backends(defaults, []),
|
||||||
|
[f'{prefix}openid_connect', f'{prefix}saml'],
|
||||||
|
)
|
||||||
|
|
||||||
|
# The running configuration must not contain duplicate apps
|
||||||
|
self.assertEqual(
|
||||||
|
len(settings.INSTALLED_APPS), len(set(settings.INSTALLED_APPS))
|
||||||
|
)
|
||||||
|
|
||||||
def test_helpers_cfg_file(self):
|
def test_helpers_cfg_file(self):
|
||||||
"""Test get_config_file."""
|
"""Test get_config_file."""
|
||||||
# normal run - not configured
|
# normal run - not configured
|
||||||
|
|||||||
Reference in new issue
Block a user