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.

NOTE: include_shared_projects is an obsolete query-parameter name, because it does not make a difference between owners/guests. A better naming would be e.g. include_zarr_dirs, but it would require a fix in fractal-web as well.

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
44
45
46
47
@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.

    NOTE: `include_shared_projects` is an obsolete query-parameter name,
    because it does not make a difference between owners/guests. A better
    naming would be e.g. `include_zarr_dirs`, but it would require a fix
    in `fractal-web` as well.
    """
    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_zarr_dirs = list(res.unique().scalars().all())
        # Note that `project_dirs` and the `authorized_zarr_dirs` may have some
        # common elements, and then the response may include non-unique items.
        return current_user.project_dirs + authorized_zarr_dirs
    else:
        return current_user.project_dirs