mirror of
https://github.com/open-webui/open-webui.git
synced 2026-09-26 17:30:27 -04:00
refac
This commit is contained in:
@@ -75,6 +75,7 @@ from open_webui.utils.auth import (
|
|||||||
verify_password,
|
verify_password,
|
||||||
)
|
)
|
||||||
from open_webui.utils.groups import apply_default_group_assignment
|
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.misc import parse_duration, validate_email_format
|
||||||
from open_webui.utils.rate_limit import RateLimiter
|
from open_webui.utils.rate_limit import RateLimiter
|
||||||
from pydantic import BaseModel, StrictStr, field_validator
|
from pydantic import BaseModel, StrictStr, field_validator
|
||||||
@@ -1463,6 +1464,9 @@ OAUTH_CONFIG_KEYS = {
|
|||||||
|
|
||||||
|
|
||||||
def _format_oauth_form_value(field: str, value):
|
def _format_oauth_form_value(field: str, value):
|
||||||
|
if field == 'OAUTH_BLOCKED_GROUPS' and isinstance(value, list):
|
||||||
|
# Preserve commas in group names and regex patterns when the form is saved.
|
||||||
|
return JSONCodec.dumps(value)
|
||||||
if field in OAUTH_COMMA_LIST_FIELDS and isinstance(value, list):
|
if field in OAUTH_COMMA_LIST_FIELDS and isinstance(value, list):
|
||||||
return ','.join(str(item) for item in value)
|
return ','.join(str(item) for item in value)
|
||||||
return value
|
return value
|
||||||
|
|||||||
@@ -351,6 +351,19 @@ def is_in_blocked_groups(group_name: str, groups: list) -> bool:
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _parse_blocked_groups(value) -> list[str]:
|
||||||
|
"""Accept JSON arrays, persisted lists, and comma-separated admin input."""
|
||||||
|
if isinstance(value, str):
|
||||||
|
try:
|
||||||
|
parsed = JSONCodec.loads(value)
|
||||||
|
except JSONCodec.JSONDecodeError:
|
||||||
|
parsed = None
|
||||||
|
value = parsed if isinstance(parsed, list) else [group.strip() for group in value.split(',')]
|
||||||
|
if not isinstance(value, list):
|
||||||
|
return []
|
||||||
|
return [group for group in value if isinstance(group, str) and group]
|
||||||
|
|
||||||
|
|
||||||
def get_parsed_and_base_url(server_url) -> tuple[urllib.parse.ParseResult, str]:
|
def get_parsed_and_base_url(server_url) -> tuple[urllib.parse.ParseResult, str]:
|
||||||
parsed = urllib.parse.urlparse(server_url)
|
parsed = urllib.parse.urlparse(server_url)
|
||||||
base_url = f'{parsed.scheme}://{parsed.netloc}'
|
base_url = f'{parsed.scheme}://{parsed.netloc}'
|
||||||
@@ -1636,11 +1649,7 @@ class OAuthManager:
|
|||||||
log.debug('Running OAUTH Group management')
|
log.debug('Running OAUTH Group management')
|
||||||
oauth_claim = auth_config.OAUTH_GROUPS_CLAIM
|
oauth_claim = auth_config.OAUTH_GROUPS_CLAIM
|
||||||
|
|
||||||
try:
|
blocked_groups = _parse_blocked_groups(auth_config.OAUTH_BLOCKED_GROUPS)
|
||||||
blocked_groups = JSONCodec.loads(auth_config.OAUTH_BLOCKED_GROUPS)
|
|
||||||
except Exception as e:
|
|
||||||
log.exception(f'Error loading OAUTH_BLOCKED_GROUPS: {e}')
|
|
||||||
blocked_groups = []
|
|
||||||
|
|
||||||
user_oauth_groups = []
|
user_oauth_groups = []
|
||||||
# Nested claim search for groups claim
|
# Nested claim search for groups claim
|
||||||
|
|||||||
Reference in New Issue
Block a user