Exemple #1
0
async def delete_problem_in_problem_set(
    problem_set: models.ProblemSet = Depends(
        parse_problem_set_factory(load_links=True)),
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[schemas.ProblemSet]:
    await problem_set.operate_problem(problem, Operation.Delete)
    return StandardResponse(problem_set)
Exemple #2
0
def delete_file_from_uncommitted_problem_config(
    path: str = Path(...),
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[FileInfo]:
    problem_config = LakeFSProblemConfig(problem)
    file_info = problem_config.delete_file(pathlib.Path(path))
    return StandardResponse(file_info)
Exemple #3
0
async def create_problem(
    problem_create: schemas.ProblemCreate,
    background_tasks: BackgroundTasks,
    domain: models.Domain = Depends(parse_domain_from_auth),
    user: models.User = Depends(parse_user_from_auth),
    session: AsyncSession = Depends(db_session_dependency),
) -> StandardResponse[schemas.ProblemDetail]:
    try:
        problem_group = models.ProblemGroup()
        session.sync_session.add(problem_group)
        logger.info(f"problem group created: {problem_group}")
        problem = models.Problem(
            **problem_create.dict(),
            domain_id=domain.id,
            owner_id=user.id,
            problem_group_id=problem_group.id,
        )
        session.sync_session.add(problem)
        logger.info(f"problem created: {problem}")
        await session.commit()
        await session.refresh(problem)
    except Exception as e:
        logger.exception(f"problem creation failed: {problem_create}")
        raise e
    lakefs_problem_config = LakeFSProblemConfig(problem)
    background_tasks.add_task(lakefs_problem_config.ensure_branch)
    return StandardResponse(problem)
Exemple #4
0
def get_file_or_directory_info_in_uncommitted_problem_config(
    path: str = Path(...),
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[FileInfo]:
    problem_config = LakeFSProblemConfig(problem)
    file_info = problem_config.get_file_info(pathlib.Path(path))
    return StandardResponse(file_info)
Exemple #5
0
def reset_problem_config(
    lakefs_reset: schemas.LakeFSReset,
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[Empty]:
    problem_config = LakeFSProblemConfig(problem)
    problem_config.reset(lakefs_reset)
    return StandardResponse()
Exemple #6
0
async def update_problem(
    problem_edit: schemas.ProblemEdit = Depends(
        schemas.ProblemEdit.edit_dependency),
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[schemas.Problem]:
    problem.update_from_dict(problem_edit.dict())
    await problem.save_model()
    return StandardResponse(problem)
Exemple #7
0
def upload_file_to_problem_config(
        file: UploadFile = File(...),
        problem: models.Problem = Depends(parse_problem),
        path: str = Depends(parse_file_path),
) -> StandardResponse[FileInfo]:
    problem_config = LakeFSProblemConfig(problem)
    file_info = problem_config.upload_file(pathlib.Path(path), file.file)
    return StandardResponse(file_info)
Exemple #8
0
def update_problem_config_by_archive(
        file: UploadFile = File(...),
        problem: models.Problem = Depends(parse_problem)
) -> StandardResponse[Empty]:
    logger.info("problem config archive name: %s", file.filename)
    problem_config = LakeFSProblemConfig(problem)
    problem_config.upload_archive(file.filename, file.file)
    return StandardResponse()
Exemple #9
0
async def update_problem_set(
    problem_set_edit: schemas.ProblemSetEdit = Depends(
        schemas.ProblemSetEdit.edit_dependency),
    problem_set: models.ProblemSet = Depends(parse_problem_set),
) -> StandardResponse[schemas.ProblemSet]:
    problem_set.update_from_dict(problem_set_edit.dict())
    await problem_set.save_model()
    return StandardResponse(problem_set)
Exemple #10
0
async def update_problem_in_problem_set(
    update_problem: schemas.ProblemSetUpdateProblem,
    problem_set: models.ProblemSet = Depends(
        parse_problem_set_factory(load_links=True)),
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[schemas.ProblemSet]:
    await problem_set.operate_problem(problem, Operation.Update,
                                      update_problem.position)
    return StandardResponse(problem_set)
Exemple #11
0
async def get_problem(
    problem: models.Problem = Depends(parse_problem),
    user: models.User = Depends(parse_user_from_auth),
) -> StandardResponse[schemas.ProblemDetailWithLatestRecord]:
    record = await models.Record.get_user_latest_record(problem_set_id=None,
                                                        problem_id=problem.id,
                                                        user_id=user.id)
    result = schemas.ProblemDetailWithLatestRecord(**problem.dict(),
                                                   latest_record=record)
    return StandardResponse(result)
Exemple #12
0
async def commit_problem_config(
    commit: schemas.ProblemConfigCommit = Body(...),
    problem: models.Problem = Depends(parse_problem),
    user: models.User = Depends(parse_user_from_auth),
) -> StandardResponse[schemas.ProblemConfig]:
    result = await models.ProblemConfig.make_commit(problem=problem,
                                                    committer=user,
                                                    commit=commit)
    logger.info("problem config commit: %s", result)
    return StandardResponse(schemas.ProblemConfig.from_orm(result))
Exemple #13
0
def delete_directory_from_uncommitted_problem_config(
    path: str = Path(...),
    problem: models.Problem = Depends(parse_problem),
    recursive: bool = Query(
        False,
        description="Act as -r in the rm command. "
        "If false, only empty directory can be deleted.",
    ),
) -> StandardResponse[FileInfo]:
    problem_config = LakeFSProblemConfig(problem)
    file_info = problem_config.delete_directory(pathlib.Path(path), recursive)
    return StandardResponse(file_info)
Exemple #14
0
async def get_problem_in_problem_set(
    link: models.ProblemProblemSetLink = Depends(
        parse_problem_problem_set_link),
    user: models.User = Depends(parse_user_from_auth),
) -> StandardResponse[schemas.ProblemDetailWithLatestRecord]:
    # await link.problem_set.operate_problem(link.problem, Operation.Read)
    record = await models.Record.get_user_latest_record(
        problem_set_id=link.problem_set_id,
        problem_id=link.problem_id,
        user_id=user.id)
    result = schemas.ProblemDetailWithLatestRecord(**link.problem.dict(),
                                                   latest_record=record)
    return StandardResponse(result)
Exemple #15
0
async def add_problem_in_problem_set(
    add_problem: schemas.ProblemSetAddProblem,
    problem_set: models.ProblemSet = Depends(
        parse_problem_set_factory(load_links=True)),
    domain_auth: DomainAuthentication = Depends(DomainAuthentication),
) -> StandardResponse[schemas.ProblemSet]:
    problem = await parse_problem_without_validation(add_problem.problem,
                                                     domain_auth.auth.domain)
    # examine problem visibility
    parse_problem(problem, domain_auth.auth)
    await problem_set.operate_problem(problem, Operation.Create,
                                      add_problem.position)
    return StandardResponse(problem_set)
Exemple #16
0
async def create_problem_set(
    problem_set_create: schemas.ProblemSetCreate,
    domain: models.Domain = Depends(parse_domain_from_auth),
    user: models.User = Depends(parse_user_from_auth),
) -> StandardResponse[schemas.ProblemSet]:
    problem_set = models.ProblemSet(
        **problem_set_create.dict(),
        domain_id=domain.id,
        owner_id=user.id,
    )
    logger.info(f"create problem set: {problem_set}")
    await problem_set.save_model()
    return StandardResponse(problem_set)
Exemple #17
0
async def get_problem_set(
    problem_set: models.ProblemSet = Depends(
        parse_problem_set_factory(load_problems=True)),
    user: models.User = Depends(parse_user_from_auth),
) -> StandardResponse[schemas.ProblemSetDetail]:
    problems = await models.Problem.get_problems_with_record_states(
        result_cls=schemas.ProblemPreviewWithLatestRecord,
        problem_set_id=problem_set.id,
        problems=problem_set.problems,
        user_id=user.id,
    )
    result = schemas.ProblemSetDetail(**problem_set.dict(
        exclude={"problems":...}),
                                      problems=problems)
    return StandardResponse(result)
Exemple #18
0
async def submit_solution_to_problem(
    background_tasks: BackgroundTasks,
    celery_app: Celery = Depends(celery_app_dependency),
    problem_submit: schemas.ProblemSolutionSubmit = Depends(
        schemas.ProblemSolutionSubmit.form_dependency),
    problem: models.Problem = Depends(parse_problem),
    user: models.User = Depends(parse_user_from_auth),
) -> StandardResponse[schemas.Record]:
    record = await models.Record.submit(
        background_tasks=background_tasks,
        celery_app=celery_app,
        problem_submit=problem_submit,
        problem_set=None,
        problem=problem,
        user=user,
    )
    logger.info("create record: {}", record)
    return StandardResponse(record)
Exemple #19
0
async def get_user(
    user: models.User = Depends(parse_uid),
) -> StandardResponse[schemas.User]:
    return StandardResponse(user)
Exemple #20
0
async def delete_problem(
    problem: models.Problem = Depends(parse_problem),
) -> StandardResponse[Empty]:
    await problem.delete_model()
    return StandardResponse()
Exemple #21
0
async def get_problem_config_json(
    config: models.ProblemConfig = Depends(parse_problem_config),
) -> StandardResponse[schemas.ProblemConfig]:
    return StandardResponse(schemas.ProblemConfig.from_orm(config))
Exemple #22
0
async def delete_problem_set(
    problem_set: models.ProblemSet = Depends(parse_problem_set),
) -> StandardResponse[Empty]:
    await problem_set.delete_model()
    return StandardResponse()