Validate profile and resource associated to a given user.
Note: this only returns non-db-bound objects.
Source code in fractal_server/app/routes/aux/validate_user_profile.py
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | async def validate_user_profile(
*,
user: UserOAuth,
db: AsyncSession,
) -> tuple[Resource, Profile]:
"""
Validate profile and resource associated to a given user.
Note: this only returns non-db-bound objects.
"""
await user_has_profile_or_422(user=user)
profile = await db.get(Profile, user.profile_id)
resource = await db.get(Resource, profile.resource_id)
try:
cast_serialize_resource(
resource.model_dump(exclude={"id", "timestamp_created"}),
)
cast_serialize_profile(
profile.model_dump(exclude={"resource_id", "id"}),
)
db.expunge(resource)
db.expunge(profile)
return resource, profile
except ValidationError as e:
error_msg = (
"User resource/profile are not valid for "
f"resource type '{resource.type}'. "
f"Original error: {str(e)}"
)
logger.warning(error_msg)
raise HTTPException(
status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
detail=error_msg,
)
|