Ejemplo n.º 1
0
def test_purge_plain(config, database, fastapi, caplog):
    caplog.set_level(logging.ERROR)
    from tests.test_import import test_import
    prj_id = test_import(config, database, caplog, "Test Purge")
    # Delete full
    ProjectsService().delete(current_user_id=ADMIN_USER_ID,
                             prj_id=prj_id,
                             only_objects=False)
    # Check it's gone
    with pytest.raises(AssertionError, match="Not found"):
        ProjectsService().delete(current_user_id=ADMIN_USER_ID,
                                 prj_id=prj_id,
                                 only_objects=False)
Ejemplo n.º 2
0
def update_project(project_id: int,
                   project: ProjectModel,
                   current_user: int = Depends(get_current_user)):
    """
        Update the project.
        Note that some fields will NOT be updated and simply ignored, e.g. *free_cols.
    """
    sce = ProjectsService()

    with RightsThrower(sce):
        present_project: ProjectBO = sce.query(current_user,
                                               project_id,
                                               for_managing=True)

    with ValidityThrower():
        # noinspection PyUnresolvedReferences
        present_project.update(session=sce.session,
                               title=project.title,
                               visible=project.visible,
                               status=project.status,
                               projtype=project.projtype,
                               init_classif_list=project.init_classif_list,
                               classiffieldlist=project.classiffieldlist,
                               popoverfieldlist=project.popoverfieldlist,
                               cnn_network_id=project.cnn_network_id,
                               comments=project.comments,
                               contact=project.contact,
                               managers=project.managers,
                               annotators=project.annotators,
                               viewers=project.viewers,
                               license_=project.license)
Ejemplo n.º 3
0
def test_prefs_set_get(config, database, fastapi, caplog):
    caplog.set_level(logging.ERROR)
    # Create a dest project
    prj_id = ProjectsService().create(
        ADMIN_USER_ID, CreateProjectReq(title="Preferences test"))
    prefs_for_test = "foo bar boo"
    # Set to something
    UserService().set_preferences_per_project(user_id=ADMIN_USER_ID,
                                              project_id=prj_id,
                                              key="tst",
                                              value=prefs_for_test)
    # Check it's still there
    prefs = UserService().get_preferences_per_project(user_id=ADMIN_USER_ID,
                                                      project_id=prj_id,
                                                      key="tst")
    assert prefs == prefs_for_test
    # No error in get if wrong project
    assert '' == UserService().get_preferences_per_project(
        user_id=ADMIN_USER_ID, project_id=-1, key="tst")
    # No error in get if wrong key
    assert '' == UserService().get_preferences_per_project(
        user_id=ADMIN_USER_ID, project_id=prj_id, key="test")
    # Error in set if wrong project
    with pytest.raises(Exception):
        UserService().set_preferences_per_project(user_id=ADMIN_USER_ID,
                                                  project_id=-1,
                                                  key="tst",
                                                  value="crash!")
Ejemplo n.º 4
0
def project_recompute_geography(
    project_id: int, current_user: int = Depends(get_current_user)) -> None:
    """
        Recompute geography information for all samples in project.
    """
    sce = ProjectsService()
    with RightsThrower(sce):
        sce.recompute_geo(current_user, project_id)
Ejemplo n.º 5
0
def project_set_get_user_stats(
    ids: str, current_user: int = Depends(get_current_user)
) -> List[ProjectUserStats]:
    """
        Read projects user statistics.
    """
    sce = ProjectsService()
    num_ids = _split_num_list(ids)
    with RightsThrower(sce):
        ret = sce.read_user_stats(current_user, num_ids)
    return ret
Ejemplo n.º 6
0
def project_set_get_stats(
    ids: str, current_user: int = Depends(get_current_user)
) -> List[ProjectTaxoStats]:
    """
        Read projects statistics, i.e. used taxa and classification states.
    """
    sce = ProjectsService()
    num_ids = _split_num_list(ids)
    with RightsThrower(sce):
        ret = sce.read_stats(current_user, num_ids)
    return ret
Ejemplo n.º 7
0
def project_query(
    project_id: int,
    for_managing: Optional[bool] = False,
    current_user: Optional[int] = Depends(get_optional_current_user)
) -> ProjectBO:
    """
        Read project if it exists for current user, eventually for managing it.
    """
    sce = ProjectsService()
    for_managing = bool(for_managing)
    with RightsThrower(sce):
        ret = sce.query(current_user, project_id, for_managing)
    return ret
Ejemplo n.º 8
0
def erase_project(
    project_id: int,
    only_objects: bool = False,
    current_user: int = Depends(get_current_user)
) -> Tuple[int, int, int, int]:
    """
        Delete the project.
            Optionally, if "only_objects" is set, the project structure is kept,
                but emptied from any object/sample/acquisition/process
            Otherwise, no trace of the project will remain in the database.
    """
    sce = ProjectsService()
    with RightsThrower(sce):
        return sce.delete(current_user, project_id, only_objects)
Ejemplo n.º 9
0
def create_project(
    params: CreateProjectReq, current_user: int = Depends(get_current_user)
) -> Union[int, str]:
    """
        Create an empty project with only a title, and return its number.
        The project will be managed by current user.
        The user has to be app administrator or project creator.
    """
    sce = ProjectsService()
    with RightsThrower(sce):
        ret = sce.create(current_user, params)
    if isinstance(ret, str):
        raise HTTPException(status_code=404, detail=ret)
    return ret
Ejemplo n.º 10
0
def search_projects(
        current_user: Optional[int] = Depends(get_optional_current_user),
        also_others: bool = False,
        for_managing: bool = False,
        title_filter: str = '',
        instrument_filter: str = '',
        filter_subset: bool = False) -> List[ProjectBO]:  # PABOPABOPABO
    """
        Return projects for current user, if any.
        - `param` also_others: Allows to return projects for which given user has no right
        - `param` for_managing: Allows to return project that can be written to (including erased) by the given user
        - `param` title_filter: Use this pattern for matching returned projects names
        - `param` instrument_filter: Only return projects where this instrument was used
        - `param` filter_subset: Only return projects having 'subset' in their names
    """
    sce = ProjectsService()
    ret = sce.search(current_user_id=current_user,
                     also_others=also_others,
                     for_managing=for_managing,
                     title_filter=title_filter,
                     instrument_filter=instrument_filter,
                     filter_subset=filter_subset)
    return ret
Ejemplo n.º 11
0
def search_unique_project(asker, title):
    with ProjectsService() as sce:
        srch = sce.search(current_user_id=asker, title_filter=title)
        assert len(srch) == 1
        return srch[0]
Ejemplo n.º 12
0
def create_project(owner, title):
    with ProjectsService() as sce:
        prj_id = sce.create(owner, CreateProjectReq(title=title))
        return prj_id