コード例 #1
0
ファイル: project_api.py プロジェクト: chenyanxiself/Event
async def update_project_env(
        env_info: UpdateProjectEnv,
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    _, error = verify_project_filed(env_info.project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, env_info.project_id)
    if error:
        return error
    try:
        Db.update_by_condition(
            AtpProjectEnv,
            [AtpProjectEnv.is_delete == 2, AtpProjectEnv.id == env_info.id],
            {
                AtpProjectEnv.host: env_info.env_host,
                AtpProjectEnv.name: env_info.env_name,
                AtpProjectEnv.updator: token_user.user_id,
                AtpProjectEnv.update_time: datetime.datetime.now()
            }
        )
        return BaseRes()
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
コード例 #2
0
async def update_task(project_id: int = Body(..., embed=True),
                      list_id: int = Body(..., embed=True),
                      title: str = Body(..., embed=True),
                      token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    _, error = verify_project_filed(project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, project_id)
    if error:
        return error
    try:
        exists_condition = [
            AtpOverviewList.is_delete == 2,
            AtpOverviewList.project_id == project_id,
            AtpOverviewList.title == title, AtpOverviewList.id != list_id
        ]
        count = Db.select_count_by_condition(AtpOverviewList.id,
                                             exists_condition)
        if count != 0:
            return BaseRes(status=0, error='任务栏标题已存在')
        condition = [
            AtpOverviewList.id == list_id,
            AtpOverviewList.is_delete == 2,
        ]
        Db.update_by_condition(
            AtpOverviewList, condition, {
                AtpOverviewList.title: title,
                AtpOverviewList.updator: token_user.user_id,
                AtpOverviewList.update_time: datetime.datetime.now()
            })
        return BaseRes()
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
コード例 #3
0
ファイル: project_api.py プロジェクト: chenyanxiself/Event
async def delete_suite(
        suite_id: int = Body(..., embed=True),
        project_id: int = Body(..., embed=True),
        suite_name: str = Body(None, embed=True),
        is_delete: int = Body(None, embed=True),
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    _, error = verify_project_filed(project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, project_id)
    if error:
        return error
    update_list = {
        AtpProjectApiSuite.updator: token_user.user_id,
        AtpProjectApiSuite.update_time: datetime.datetime.now()
    }
    if suite_name:
        update_list.setdefault(AtpProjectApiSuite.name, suite_name)
    if is_delete:
        update_list.setdefault(AtpProjectApiSuite.is_delete, int(is_delete))
    try:
        count = Db.update_by_condition(AtpProjectApiSuite, [AtpProjectApiSuite.id == suite_id], update_list)
        return BaseRes(data=count)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
コード例 #4
0
ファイル: project_api.py プロジェクト: chenyanxiself/Event
async def delete_api_case_by_id(
        id: int = Body(..., embed=True),
        project_id: int = Body(..., embed=True),
        token_user: TokenUser = Depends(auth_token)
):
    _, error = verify_project_filed(project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, project_id)
    if error:
        return error
    try:
        update_count: int = Db.update_by_condition(
            AtpProjectApiCase,
            [
                AtpProjectApiCase.id == id,
                AtpProjectApiCase.is_delete == 2,
            ],
            {
                AtpProjectApiCase.is_delete: 1,
                AtpProjectApiCase.updator: token_user.user_id,
                AtpProjectApiCase.update_time: datetime.datetime.now()
            }
        )
        return BaseRes(data=update_count)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
コード例 #5
0
ファイル: project_api.py プロジェクト: chenyanxiself/Event
async def update_project_type(
        id: int = Body(..., embed=True),
        project_type: int = Body(..., embed=True),
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    _, error = verify_project_deleted(id)
    if error:
        return error
    _, error = verify_project_owner(token_user.user_id, id)
    if error:
        return error
    try:
        count = Db.update_by_condition(
            AtpProject,
            [AtpProject.id == id, AtpProject.is_delete == 2],
            {
                AtpProject.type: project_type,
                AtpProject.updator: token_user.user_id,
                AtpProject.update_time: datetime.datetime.now()
            }
        )
        return BaseRes(data=count)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
コード例 #6
0
async def update_module(
    request: UpdateModule,
    token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    _, error = verify_project_filed(request.project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, request.project_id)
    if error:
        return error
    try:
        Db.update_by_condition(AtpProjectModule, [
            AtpProjectModule.is_delete == 2, AtpProjectModule.id == request.id
        ], {AtpProjectModule.name: request.name})
        return BaseRes()
    except Exception as e:
        logger.error(e)
        return BaseRes(status=0, error=str(e))
コード例 #7
0
ファイル: user_api.py プロジェクト: chenyanxiself/Event
async def update_password(data: UpdatePassword, token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    user: SysUser = Db.select_by_primary_key(SysUser, token_user.user_id)
    if verify_password(data.old_password, user.password):
        try:
            hash_paaword = get_password_hash(data.new_password)
            Db.update_by_condition(
                SysUser,
                [SysUser.id == token_user.user_id],
                {
                    SysUser.password: hash_paaword,
                    SysUser.updator: token_user.user_id,
                    SysUser.update_time: datetime.now()
                })
            return BaseRes()
        except Exception as e:
            logger.error(e)
            return BaseRes(status=0, error='更新密码失败')
    else:
        return BaseRes(status=0, error='密码错误')
コード例 #8
0
ファイル: project_api.py プロジェクト: chenyanxiself/Event
async def update_project_api_case(
        update_project_api_case: UpdateProjectApiCase,
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    _, error = verify_project_filed(update_project_api_case.project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, update_project_api_case.project_id)
    if error:
        return error
    try:
        request_headers: str = json.dumps(update_project_api_case.request_headers)
        request_query: str = json.dumps(update_project_api_case.request_query)
        request_body: str = str(update_project_api_case.request_body)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    try:
        db_res: int = Db.update_by_condition(
            AtpProjectApiCase,
            [
                AtpProjectApiCase.id == update_project_api_case.id,
                AtpProjectApiCase.is_delete == 2
            ],
            {
                AtpProjectApiCase.name: update_project_api_case.name,
                AtpProjectApiCase.method: update_project_api_case.request_method,
                AtpProjectApiCase.project_id: update_project_api_case.project_id,
                AtpProjectApiCase.suite_id: update_project_api_case.suite_id,
                AtpProjectApiCase.request_url: update_project_api_case.request_url,
                AtpProjectApiCase.is_use_env: update_project_api_case.request_host.is_user_env,
                AtpProjectApiCase.env_host: update_project_api_case.request_host.env_host,
                AtpProjectApiCase.request_headers: request_headers,
                AtpProjectApiCase.request_query: request_query,
                AtpProjectApiCase.request_body: request_body,
                AtpProjectApiCase.updator: token_user.user_id,
                AtpProjectApiCase.update_time: datetime.datetime.now()
            }
        )
        return BaseRes(data=db_res)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
コード例 #9
0
async def delete_report_by_id(id: int = Body(..., embed=True),
                              project_id: int = Body(..., embed=True),
                              token_user: TokenUser = Depends(auth_token)):
    _, error = verify_project_filed(project_id)
    if error:
        return error
    _, error = verify_project_member(token_user.user_id, project_id)
    if error:
        return error
    try:
        update_count: int = Db.update_by_condition(
            AtpProjectTestReport, [
                AtpProjectTestReport.id == id,
                AtpProjectTestReport.is_delete == '2',
            ], {
                AtpProjectTestReport.is_delete: '1',
                AtpProjectTestReport.updator: token_user.user_id,
                AtpProjectTestReport.update_time: datetime.datetime.now()
            })
        return BaseRes(data=update_count)
    except Exception as e:
        logger.error(e)
        return BaseRes(status=0, error=str(e))