mirror of
https://github.com/open-webui/open-webui.git
synced 2026-10-02 02:12:25 +00:00
refac
This commit is contained in:
parent
dc4f5da5a0
commit
7f703dcc98
1 changed files with 7 additions and 13 deletions
|
|
@ -27,7 +27,7 @@ from open_webui.models.tools import (
|
|||
)
|
||||
from open_webui.utils.access_control import (
|
||||
filter_allowed_access_grants,
|
||||
has_access,
|
||||
has_connection_access,
|
||||
has_permission,
|
||||
)
|
||||
from open_webui.utils.auth import get_admin_user, get_verified_user
|
||||
|
|
@ -102,7 +102,7 @@ async def get_tools(
|
|||
)
|
||||
|
||||
# OpenAPI Tool Servers
|
||||
server_access_grants = {}
|
||||
server_connections = {}
|
||||
for server in await get_tool_servers(request):
|
||||
server_idx = server.get('idx', 0)
|
||||
connections = await Config.get('tool_server.connections', [])
|
||||
|
|
@ -113,10 +113,8 @@ async def get_tools(
|
|||
)
|
||||
continue
|
||||
connection = connections[server_idx]
|
||||
server_config = connection.get('config', {})
|
||||
|
||||
server_id = f'server:{server.get("id")}'
|
||||
server_access_grants[server_id] = server_config.get('access_grants', [])
|
||||
server_connections[server_id] = connection
|
||||
|
||||
tools.append(
|
||||
ToolUserResponse(
|
||||
|
|
@ -149,10 +147,8 @@ async def get_tools(
|
|||
user.id, f'mcp:{server_id}'
|
||||
)
|
||||
|
||||
server_config = server.get('config') or {}
|
||||
|
||||
tool_id = f'server:mcp:{info.get("id")}'
|
||||
server_access_grants[tool_id] = server_config.get('access_grants', [])
|
||||
server_connections[tool_id] = server
|
||||
|
||||
tools.append(
|
||||
ToolUserResponse(
|
||||
|
|
@ -181,12 +177,10 @@ async def get_tools(
|
|||
tool
|
||||
for tool in tools
|
||||
if not str(tool.id).startswith('server:')
|
||||
or await has_access(
|
||||
user.id,
|
||||
'read',
|
||||
server_access_grants.get(str(tool.id), []),
|
||||
or await has_connection_access(
|
||||
user,
|
||||
server_connections[str(tool.id)],
|
||||
user_group_ids,
|
||||
db=db,
|
||||
)
|
||||
]
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue