mirror of
https://github.com/OpenHands/OpenHands.git
synced 2026-03-22 05:37:20 +08:00
Fix union-attr mypy errors in enterprise code (#13176)
Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
@@ -106,6 +106,11 @@ async def summarize_issue_solvability(
|
||||
f'Solvability analysis disabled for user {github_view.user_info.user_id}'
|
||||
)
|
||||
|
||||
if user_settings.llm_api_key is None:
|
||||
raise ValueError(
|
||||
f'[Solvability] No LLM API key found for user {github_view.user_info.user_id}'
|
||||
)
|
||||
|
||||
try:
|
||||
llm_config = LLMConfig(
|
||||
model=user_settings.llm_model,
|
||||
|
||||
@@ -43,13 +43,15 @@ class SetAuthCookieMiddleware:
|
||||
if not user_auth or user_auth.auth_type != AuthType.COOKIE:
|
||||
return response
|
||||
if user_auth.refreshed:
|
||||
if user_auth.access_token is None:
|
||||
return response
|
||||
set_response_cookie(
|
||||
request=request,
|
||||
response=response,
|
||||
keycloak_access_token=user_auth.access_token.get_secret_value(),
|
||||
keycloak_refresh_token=user_auth.refresh_token.get_secret_value(),
|
||||
secure=False if request.url.hostname == 'localhost' else True,
|
||||
accepted_tos=user_auth.accepted_tos,
|
||||
accepted_tos=user_auth.accepted_tos or False,
|
||||
)
|
||||
|
||||
# On re-authentication (token refresh), kick off background sync for GitLab repos
|
||||
|
||||
@@ -91,6 +91,8 @@ async def get_credits(user_id: str = Depends(get_user_id)) -> GetCreditsResponse
|
||||
if not stripe_service.STRIPE_API_KEY:
|
||||
return GetCreditsResponse()
|
||||
user = await UserStore.get_user_by_id_async(user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail='User not found')
|
||||
user_team_info = await LiteLlmManager.get_user_team_info(
|
||||
user_id, str(user.current_org_id)
|
||||
)
|
||||
@@ -247,6 +249,8 @@ async def success_callback(session_id: str, request: Request):
|
||||
raise HTTPException(status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
user = await UserStore.get_user_by_id_async(billing_session.user_id)
|
||||
if user is None:
|
||||
raise HTTPException(status.HTTP_404_NOT_FOUND, detail='User not found')
|
||||
user_team_info = await LiteLlmManager.get_user_team_info(
|
||||
billing_session.user_id, str(user.current_org_id)
|
||||
)
|
||||
|
||||
@@ -77,13 +77,18 @@ async def update_email(
|
||||
)
|
||||
|
||||
# need to set auth cookie to the new tokens
|
||||
if user_auth.access_token is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED,
|
||||
detail='Access token not found',
|
||||
)
|
||||
set_response_cookie(
|
||||
request=request,
|
||||
response=response,
|
||||
keycloak_access_token=user_auth.access_token.get_secret_value(),
|
||||
keycloak_refresh_token=user_auth.refresh_token.get_secret_value(),
|
||||
secure=False if request.url.hostname == 'localhost' else True,
|
||||
accepted_tos=user_auth.accepted_tos,
|
||||
accepted_tos=user_auth.accepted_tos or False,
|
||||
)
|
||||
|
||||
await verify_email(request=request, user_id=user_id)
|
||||
@@ -156,13 +161,17 @@ async def verified_email(request: Request):
|
||||
response = RedirectResponse(redirect_uri, status_code=302)
|
||||
|
||||
# need to set auth cookie to the new tokens
|
||||
if user_auth.access_token is None:
|
||||
raise HTTPException(
|
||||
status_code=status.HTTP_401_UNAUTHORIZED, detail='Access token not found'
|
||||
)
|
||||
set_response_cookie(
|
||||
request=request,
|
||||
response=response,
|
||||
keycloak_access_token=user_auth.access_token.get_secret_value(),
|
||||
keycloak_refresh_token=user_auth.refresh_token.get_secret_value(),
|
||||
secure=False if request.url.hostname == 'localhost' else True,
|
||||
accepted_tos=user_auth.accepted_tos,
|
||||
accepted_tos=user_auth.accepted_tos or False,
|
||||
)
|
||||
|
||||
logger.info(f'Email {user_auth.email} verified.')
|
||||
|
||||
@@ -38,6 +38,8 @@ class ApiKeyStore:
|
||||
"""
|
||||
api_key = self.generate_api_key()
|
||||
user = await UserStore.get_user_by_id_async(user_id)
|
||||
if user is None:
|
||||
raise ValueError(f'User not found: {user_id}')
|
||||
org_id = user.current_org_id
|
||||
|
||||
async with a_session_maker() as session:
|
||||
@@ -116,6 +118,8 @@ class ApiKeyStore:
|
||||
async def list_api_keys(self, user_id: str) -> list[ApiKey]:
|
||||
"""List all API keys for a user."""
|
||||
user = await UserStore.get_user_by_id_async(user_id)
|
||||
if user is None:
|
||||
raise ValueError(f'User not found: {user_id}')
|
||||
org_id = user.current_org_id
|
||||
|
||||
async with a_session_maker() as session:
|
||||
@@ -129,6 +133,8 @@ class ApiKeyStore:
|
||||
|
||||
async def retrieve_mcp_api_key(self, user_id: str) -> str | None:
|
||||
user = await UserStore.get_user_by_id_async(user_id)
|
||||
if user is None:
|
||||
raise ValueError(f'User not found: {user_id}')
|
||||
org_id = user.current_org_id
|
||||
|
||||
async with a_session_maker() as session:
|
||||
|
||||
@@ -53,6 +53,8 @@ class SaasSecretsStore(SecretsStore):
|
||||
|
||||
async def store(self, item: Secrets):
|
||||
user = await UserStore.get_user_by_id_async(self.user_id)
|
||||
if user is None:
|
||||
raise ValueError(f'User not found: {self.user_id}')
|
||||
org_id = user.current_org_id
|
||||
|
||||
async with a_session_maker() as session:
|
||||
|
||||
@@ -88,6 +88,8 @@ class UserStore:
|
||||
session.add(user)
|
||||
|
||||
role = RoleStore.get_role_by_name('owner')
|
||||
if role is None:
|
||||
raise ValueError('Owner role not found in database')
|
||||
|
||||
from storage.org_member_store import OrgMemberStore
|
||||
|
||||
@@ -269,6 +271,8 @@ class UserStore:
|
||||
'user_store:migrate_user:done_get_role_by_name',
|
||||
extra={'user_id': user_id},
|
||||
)
|
||||
if role is None:
|
||||
raise ValueError('Owner role not found in database')
|
||||
|
||||
from storage.org_member_store import OrgMemberStore
|
||||
|
||||
|
||||
Reference in New Issue
Block a user