Skip to content

profile

delete_profile(profile_id, superuser=Depends(current_active_superuser), db=Depends(get_async_db)) async

Delete single Profile.

Source code in fractal_server/app/routes/admin/v2/profile.py
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
@router.delete("/{profile_id}/", status_code=204)
async def delete_profile(
    profile_id: int,
    superuser: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
):
    """
    Delete single `Profile`.
    """
    profile = await _get_profile_or_404(profile_id=profile_id, db=db)

    # Fail if at least one UserOAuth is associated with the Profile.
    res = await db.execute(
        select(func.count(UserOAuth.id)).where(
            UserOAuth.profile_id == profile.id
        )
    )
    associated_users_count = res.scalar()
    if associated_users_count > 0:
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
            detail=(
                f"Cannot delete Profile {profile_id} because it's associated"
                f" with {associated_users_count} UserOAuths."
            ),
        )

    # Delete
    await db.delete(profile)
    await db.commit()
    return Response(status_code=status.HTTP_204_NO_CONTENT)

get_single_profile(profile_id, superuser=Depends(current_active_superuser), db=Depends(get_async_db)) async

Query single Profile.

Source code in fractal_server/app/routes/admin/v2/profile.py
21
22
23
24
25
26
27
28
29
30
31
@router.get("/{profile_id}/", response_model=ProfileRead, status_code=200)
async def get_single_profile(
    profile_id: int,
    superuser: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> ProfileRead:
    """
    Query single `Profile`.
    """
    profile = await _get_profile_or_404(profile_id=profile_id, db=db)
    return profile

put_profile(profile_id, profile_update, superuser=Depends(current_active_superuser), db=Depends(get_async_db)) async

Override single Profile.

Source code in fractal_server/app/routes/admin/v2/profile.py
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
@router.put("/{profile_id}/", response_model=ProfileRead, status_code=200)
async def put_profile(
    profile_id: int,
    profile_update: ProfileCreate,
    superuser: UserOAuth = Depends(current_active_superuser),
    db: AsyncSession = Depends(get_async_db),
) -> ProfileRead:
    """
    Override single `Profile`.
    """
    profile = await _get_profile_or_404(profile_id=profile_id, db=db)

    if profile_update.name and profile_update.name != profile.name:
        await _check_profile_name(name=profile_update.name, db=db)

    for key, value in profile_update.model_dump().items():
        setattr(profile, key, value)
    await db.commit()
    await db.refresh(profile)
    return profile