mirror of
https://github.com/open-webui/open-webui.git
synced 2026-11-17 09:51:35 +00:00
fix: persist OAuth blocked groups from admin settings
This commit is contained in:
parent
ad9da98168
commit
bcc7fa9805
2 changed files with 27 additions and 5 deletions
|
|
@ -75,6 +75,7 @@ from open_webui.utils.auth import (
|
|||
verify_password,
|
||||
)
|
||||
from open_webui.utils.groups import apply_default_group_assignment
|
||||
from open_webui.utils.json_codec import JSONCodec
|
||||
from open_webui.utils.misc import parse_duration, validate_email_format
|
||||
from open_webui.utils.rate_limit import RateLimiter
|
||||
from pydantic import BaseModel, StrictStr, field_validator
|
||||
|
|
@ -1421,6 +1422,7 @@ OAUTH_COMMA_LIST_FIELDS = {
|
|||
'OAUTH_ALLOWED_DOMAINS',
|
||||
'OAUTH_ADMIN_ROLES',
|
||||
'OAUTH_ALLOWED_ROLES',
|
||||
'OAUTH_BLOCKED_GROUPS',
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1463,6 +1465,11 @@ OAUTH_CONFIG_KEYS = {
|
|||
|
||||
|
||||
def _format_oauth_form_value(field: str, value):
|
||||
if field == 'OAUTH_BLOCKED_GROUPS' and isinstance(value, str):
|
||||
try:
|
||||
value = JSONCodec.loads(value)
|
||||
except (JSONCodec.JSONDecodeError, TypeError):
|
||||
pass
|
||||
if field in OAUTH_COMMA_LIST_FIELDS and isinstance(value, list):
|
||||
return ','.join(str(item) for item in value)
|
||||
return value
|
||||
|
|
|
|||
|
|
@ -341,6 +341,25 @@ def is_in_blocked_groups(group_name: str, groups: list) -> bool:
|
|||
return False
|
||||
|
||||
|
||||
def _parse_blocked_groups(value) -> list[str]:
|
||||
"""Load blocked groups from persistent config or the legacy env format."""
|
||||
if isinstance(value, list):
|
||||
return [str(group) for group in value if group]
|
||||
if not isinstance(value, str) or not value.strip():
|
||||
return []
|
||||
|
||||
try:
|
||||
parsed = JSONCodec.loads(value)
|
||||
except (JSONCodec.JSONDecodeError, TypeError):
|
||||
parsed = None
|
||||
|
||||
if isinstance(parsed, list):
|
||||
return [str(group) for group in parsed if group]
|
||||
if isinstance(parsed, str) and parsed.strip():
|
||||
return [parsed.strip()]
|
||||
return [group.strip() for group in value.split(',') if group.strip()]
|
||||
|
||||
|
||||
def get_parsed_and_base_url(server_url) -> tuple[urllib.parse.ParseResult, str]:
|
||||
parsed = urllib.parse.urlparse(server_url)
|
||||
base_url = f'{parsed.scheme}://{parsed.netloc}'
|
||||
|
|
@ -1624,11 +1643,7 @@ class OAuthManager:
|
|||
log.debug('Running OAUTH Group management')
|
||||
oauth_claim = auth_config.OAUTH_GROUPS_CLAIM
|
||||
|
||||
try:
|
||||
blocked_groups = JSONCodec.loads(auth_config.OAUTH_BLOCKED_GROUPS)
|
||||
except Exception as e:
|
||||
log.exception(f'Error loading OAUTH_BLOCKED_GROUPS: {e}')
|
||||
blocked_groups = []
|
||||
blocked_groups = _parse_blocked_groups(auth_config.OAUTH_BLOCKED_GROUPS)
|
||||
|
||||
user_oauth_groups = []
|
||||
# Nested claim search for groups claim
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue