Skip to content

Sharing

FUNCTION DESCRIPTION
verify_invitation_for_guest

Verify the invitation to join a project for a guest user

Classes

Functions:

verify_invitation_for_guest(guest_user_id, project_id, superuser=Depends(current_superuser_act), db=Depends(get_async_db)) async

Verify the invitation to join a project for a guest user

Note that a guest user would not be allowed to do this themselves.

Source code in fractal_server/app/routes/admin/v2/sharing.py
@router.post("/verify/", status_code=200)
async def verify_invitation_for_guest(
    guest_user_id: int,
    project_id: int,
    superuser: UserOAuth = Depends(current_superuser_act),
    db: AsyncSession = Depends(get_async_db),
) -> Response:
    """
    Verify the invitation to join a project for a guest user

    Note that a guest user would not be allowed to do this themselves.
    """
    # Get user and verify that they actually are a guest
    guest_user = await _user_or_404(guest_user_id, db)
    if not guest_user.is_guest:
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
            detail="Cannot accept invitations for non-guest users.",
        )

    # Find verification and check that permissions are set to R
    link = await get_pending_invitation_or_404(
        user_id=guest_user_id, project_id=project_id, db=db
    )
    if link.permissions != ProjectPermissions.READ:
        raise HTTPException(
            status_code=status.HTTP_422_UNPROCESSABLE_CONTENT,
            detail=(
                "Guest users can only have 'r' permission "
                f"(given: '{link.permissions}')"
            ),
        )
    # Mark the invitation as verified
    link.is_verified = True
    await db.commit()

    return Response(status_code=status.HTTP_200_OK)