mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-07-25 12:01:04 +02:00
Fix auth and config validation regressions
This commit is contained in:
parent
e4b53f78e9
commit
8ac6f1aa06
9 changed files with 346 additions and 49 deletions
|
|
@ -18,6 +18,7 @@ from api.services.auth.depends import get_user
|
|||
from api.services.configuration.ai_model_configuration import (
|
||||
convert_legacy_ai_model_configuration_to_v2,
|
||||
get_resolved_ai_model_configuration,
|
||||
update_organization_ai_model_configuration_last_validated_at,
|
||||
upsert_organization_ai_model_configuration_v2,
|
||||
)
|
||||
from api.services.configuration.check_validity import (
|
||||
|
|
@ -107,6 +108,24 @@ class UserConfigurationRequestResponseSchema(BaseModel):
|
|||
organization_pricing: dict[str, Union[float, str, bool]] | None = None
|
||||
|
||||
|
||||
def _is_validation_cache_stale(
|
||||
last_validated_at: datetime | None,
|
||||
validity_ttl_seconds: int,
|
||||
) -> bool:
|
||||
if last_validated_at is None:
|
||||
return True
|
||||
|
||||
has_timezone = (
|
||||
last_validated_at.tzinfo is not None
|
||||
and last_validated_at.utcoffset() is not None
|
||||
)
|
||||
if has_timezone:
|
||||
now = datetime.now(last_validated_at.tzinfo)
|
||||
else:
|
||||
now = datetime.now()
|
||||
return last_validated_at < now - timedelta(seconds=validity_ttl_seconds)
|
||||
|
||||
|
||||
@router.get("/configurations/user")
|
||||
async def get_user_configurations(
|
||||
user: UserModel = Depends(get_user),
|
||||
|
|
@ -255,10 +274,9 @@ async def validate_user_configurations(
|
|||
)
|
||||
configurations = resolved_config.effective
|
||||
|
||||
if (
|
||||
not configurations.last_validated_at
|
||||
or configurations.last_validated_at
|
||||
< datetime.now() - timedelta(seconds=validity_ttl_seconds)
|
||||
if _is_validation_cache_stale(
|
||||
configurations.last_validated_at,
|
||||
validity_ttl_seconds,
|
||||
):
|
||||
validator = UserConfigurationValidator()
|
||||
try:
|
||||
|
|
@ -267,6 +285,13 @@ async def validate_user_configurations(
|
|||
organization_id=user.selected_organization_id,
|
||||
created_by=user.provider_id,
|
||||
)
|
||||
if (
|
||||
resolved_config.source == "organization_v2"
|
||||
and user.selected_organization_id is not None
|
||||
):
|
||||
await update_organization_ai_model_configuration_last_validated_at(
|
||||
user.selected_organization_id
|
||||
)
|
||||
return status
|
||||
except ValueError as e:
|
||||
raise HTTPException(status_code=422, detail=e.args[0])
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue