Skip to content

viewer_paths

get_current_user_allowed_viewer_paths(include_shared_projects=True, current_user=Depends(current_user_act_ver), db=Depends(get_async_db)) async

Returns the allowed viewer paths for current user.

Source code in fractal_server/app/routes/auth/viewer_paths.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
@router_viewer_paths.get(
    "/current-user/allowed-viewer-paths/", response_model=list[str]
)
async def get_current_user_allowed_viewer_paths(
    include_shared_projects: bool = True,
    current_user: UserOAuth = Depends(current_user_act_ver),
    db: AsyncSession = Depends(get_async_db),
) -> list[str]:
    """
    Returns the allowed viewer paths for current user.
    """
    authorized_paths = current_user.project_dirs.copy()

    if include_shared_projects:
        res = await db.execute(
            select(DatasetV2.zarr_dir)
            .join(ProjectV2, ProjectV2.id == DatasetV2.project_id)
            .join(
                LinkUserProjectV2, LinkUserProjectV2.project_id == ProjectV2.id
            )
            .where(LinkUserProjectV2.user_id == current_user.id)
            .where(LinkUserProjectV2.is_verified.is_(True))
        )
        authorized_paths.extend(res.unique().scalars().all())
        # Note that `project_dirs` and the `db.execute` result may have some
        # common elements, and then this list may have non-unique items.

    return authorized_paths