Skip to content

_aux_functions_sharing

Raises 404 if User[user_id] is not linked to Project[project_id], regardless of whether the User or Project exists.

Source code in fractal_server/app/routes/api/v2/_aux_functions_sharing.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
async def get_link_or_404(
    *, user_id: int, project_id: int, db: AsyncSession
) -> LinkUserProjectV2:
    """
    Raises 404 if User[`user_id`] is not linked to Project[`project_id`],
    regardless of whether the User or Project exists.
    """
    link = await db.get(LinkUserProjectV2, (project_id, user_id))
    if link is None:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail="User is not linked to project.",
        )
    return link

get_pending_invitation_or_404(*, user_id, project_id, db) async

Raises 404 if User[user_id] has not a pending invitation to Project[project_id], regardless of whether the User or Project exists.

Source code in fractal_server/app/routes/api/v2/_aux_functions_sharing.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
async def get_pending_invitation_or_404(
    *, user_id: int, project_id: int, db: AsyncSession
) -> LinkUserProjectV2:
    """
    Raises 404 if User[`user_id`] has not a pending invitation to
    Project[`project_id`], regardless of whether the User or Project exists.
    """
    link = await get_link_or_404(user_id=user_id, project_id=project_id, db=db)
    if link.is_verified:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND,
            detail="No pending invitation for user on this project.",
        )
    return link

get_user_id_from_email_or_404(*, user_email, db) async

Raises 404 if there is no User with email user_email.

Source code in fractal_server/app/routes/api/v2/_aux_functions_sharing.py
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
async def get_user_id_from_email_or_404(
    *, user_email: str, db: AsyncSession
) -> int:
    """
    Raises 404 if there is no User with email `user_email`.
    """
    res = await db.execute(
        select(UserOAuth.id).where(UserOAuth.email == user_email)
    )
    user_id = res.scalar_one_or_none()
    if user_id is None:
        raise HTTPException(
            status_code=status.HTTP_404_NOT_FOUND, detail="User not found."
        )
    return user_id

raise_403_if_not_owner(*, user_id, project_id, db) async

Raises 403 if User[user_id] is not owner of Project[project_id], regardless of whether the User or Project exists.

Source code in fractal_server/app/routes/api/v2/_aux_functions_sharing.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
async def raise_403_if_not_owner(
    *,
    user_id: int,
    project_id: int,
    db: AsyncSession,
) -> None:
    """
    Raises 403 if User[`user_id`] is not owner of Project[`project_id`],
    regardless of whether the User or Project exists.
    """
    res = await db.execute(
        select(LinkUserProjectV2)
        .where(LinkUserProjectV2.project_id == project_id)
        .where(LinkUserProjectV2.user_id == user_id)
        .where(LinkUserProjectV2.is_owner.is_(True))
    )
    link = res.scalars().one_or_none()
    if link is None:
        raise HTTPException(
            status_code=status.HTTP_403_FORBIDDEN,
            detail="Current user is not the project owner.",
        )
    return link

Raises 422 if User[user_id] is linked Project[project_id], regardless of whether the User or Project exists.

Source code in fractal_server/app/routes/api/v2/_aux_functions_sharing.py
67
68
69
70
71
72
73
74
75
76
77
78
79
80
async def raise_422_if_link_exists(
    *, user_id: int, project_id: int, db: AsyncSession
) -> None:
    """
    Raises 422 if User[`user_id`] is linked Project[`project_id`], regardless
    of whether the User or Project exists.
    """
    link = await db.get(LinkUserProjectV2, (project_id, user_id))
    if link is not None:
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
            detail="User is already associated to project.",
        )
    return