Skip to content

current_user

Definition of /auth/current-user/ endpoints

get_current_user(group_ids_names=False, user=Depends(current_user_act), db=Depends(get_async_db)) async

Return current user

Source code in fractal_server/app/routes/auth/current_user.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@router_current_user.get("/current-user/", response_model=UserRead)
async def get_current_user(
    group_ids_names: bool = False,
    user: UserOAuth = Depends(current_user_act),
    db: AsyncSession = Depends(get_async_db),
):
    """
    Return current user
    """
    if group_ids_names is True:
        user_with_groups = await _get_single_user_with_groups(user, db)
        return user_with_groups
    else:
        return user

patch_current_user(user_update, current_user=Depends(current_user_act), user_manager=Depends(get_user_manager), db=Depends(get_async_db)) async

Note: a user cannot patch their own password (as enforced within the UserUpdateStrict schema).

Source code in fractal_server/app/routes/auth/current_user.py
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
@router_current_user.patch("/current-user/", response_model=UserRead)
async def patch_current_user(
    user_update: UserUpdateStrict,
    current_user: UserOAuth = Depends(current_user_act),
    user_manager: UserManager = Depends(get_user_manager),
    db: AsyncSession = Depends(get_async_db),
):
    """
    Note: a user cannot patch their own password (as enforced within the
    `UserUpdateStrict` schema).
    """
    update = UserUpdate(**user_update.model_dump(exclude_unset=True))

    # NOTE: here it would be relevant to catch an `InvalidPasswordException`
    # (from `fastapi_users.exceptions`), if we were to allow users change
    # their own password

    user = await user_manager.update(update, current_user, safe=True)
    validated_user = UserOAuth.model_validate(user.model_dump())

    patched_user = await db.get(
        UserOAuth, validated_user.id, populate_existing=True
    )
    patched_user_with_groups = await _get_single_user_with_groups(
        patched_user, db
    )
    return patched_user_with_groups