Ejemplo n.º 1
0
async def del_project_img(
        file_id: int = Body(..., embed=True),
        task_id: int = Body(None, embed=True),
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    session = Db.get_session()
    file: AtpFileSystemFile = session.query(AtpFileSystemFile).get(file_id)
    if not file:
        return BaseRes(status=0, error='file not found')
    file_path = get_settings().static_path + file.name
    if not os.path.exists(file_path):
        return BaseRes(status=0, error='file not found')
    os.remove(file_path)
    if task_id:
        task: AtpOverviewTask = session.query(AtpOverviewTask).get(task_id)
        _, error = verify_project_filed(task.project_id)
        if error:
            return error
        _, error = verify_project_member(token_user.user_id, task.project_id)
        if error:
            return error
        img_list = json.loads(task.img)
        img_list.remove(file_id)
        task.img = json.dumps(img_list)
        session.commit()
    return BaseRes()
Ejemplo n.º 2
0
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))
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
async def create_role(
        name: str = Body(..., embed=True),
        menu_list: List[int] = Body(..., embed=True),
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    session = Db.get_session()
    try:
        new_role = SysRole(
            role_name=name,
            creator=token_user.user_id,
            create_time=datetime.now()
        )
        session.add(new_role)
        session.commit()
        for menu_id in menu_list:
            session.add(SysRoleMenu(
                menu_id=menu_id,
                role_id=new_role.id,
                creator=token_user.user_id,
                create_time=datetime.now()
            ))
        session.commit()
        return BaseRes(data=new_role.id)
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=e)
Ejemplo n.º 5
0
async def delete_project_env(
        id: int = Body(..., embed=True),
        project_id: int = 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
    session = Db.get_session()
    try:
        session.query(AtpProjectEnv).filter(AtpProjectEnv.is_delete == 2, AtpProjectEnv.id == id).update(
            {
                AtpProjectEnv.is_delete: 1,
                AtpProjectEnv.updator: token_user.user_id,
                AtpProjectEnv.update_time: datetime.datetime.now()
            }
        )
        session.query(AtpProjectApiCase).filter(
            AtpProjectApiCase.is_delete == 2,
            AtpProjectApiCase.project_id == project_id,
            AtpProjectApiCase.env_host == id
        ).update({
            AtpProjectApiCase.env_host: None
        })
        session.commit()
        return BaseRes()
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 6
0
async def create_project(
        create_project: Project,
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    user_id = token_user.user_id
    session = Db.get_session()
    try:
        project: AtpProject = AtpProject(
            name=create_project.project_name,
            remark=create_project.project_desc,
            type=1,
            img=create_project.project_img,
            creator=user_id,
            create_time=datetime.datetime.now()
        )
        session.add(project)
        session.commit()
        project_id = project.id
        for member_id in create_project.project_member:
            member: AtpProjectMember = AtpProjectMember(
                project_id=project_id,
                member_id=member_id,
                creator=user_id,
                create_time=datetime.datetime.now()
            )
            session.add(member)
        session.commit()
        return BaseRes()
    except Exception as e:
        logger.error(traceback.format_exc())
        session.rollback()
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 7
0
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))
Ejemplo n.º 8
0
async def update_editor(id: int = Body(..., embed=True),
                        project_id: int = Body(..., embed=True),
                        title: str = Body(None, embed=True),
                        data: 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
    session = Db.get_session()
    try:
        editor: AtpProjectEditor = session.query(AtpProjectEditor).get(id)
        editor.updator = token_user.user_id
        editor.update_time = datetime.datetime.now()
        if is_delete:
            editor.is_delete = is_delete
        if title:
            editor.title = title
        if data:
            editor.data = data
        session.commit()
        return BaseRes(data={'id': id})
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    finally:
        session.close()
Ejemplo n.º 9
0
async def get_project_id(id: int = Query(...)) -> BaseRes:
    _, error = verify_project_deleted(id)
    if error:
        return error
    try:
        project: AtpProject = Db.select_by_primary_key(AtpProject, id)
        member_relation_list: List[AtpProjectMember] = Db.select_by_condition(
            AtpProjectMember,
            [
                AtpProjectMember.project_id == id,
                AtpProjectMember.is_delete == 2
            ]
        )
        if project.img:
            file: AtpFileSystemFile = Db.select_by_primary_key(AtpFileSystemFile, project.img)
            project.img = {
                'id': file.id,
                'url': get_settings().archive_host + file.name
            }
        else:
            project.img = {
                'id': 0,
                'url': 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
            }
        project.member = []
        for member_relation in member_relation_list:
            user: SysUser = Db.select_by_primary_key(SysUser, member_relation.member_id)
            project.member.append({
                'id': user.id,
                'cname': user.cname,
            })
        return BaseRes(data=project)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 10
0
async def get_all_user_roll(token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    session = Db.get_session()
    try:
        user_list: List[SysUser] = session.query(SysUser).filter(*[
            SysUser.is_delete == 2
        ]).all()
        return_data = []
        for user in user_list:
            user_roll_map: List[SysUserRole] = session.query(SysUserRole).filter(*[
                SysUserRole.is_delete == 2,
                SysUserRole.user_id == user.id
            ]).all()
            roll_ids = [x.role_id for x in user_roll_map]
            return_data.append({
                'user_id': user.id,
                'user_name': user.name,
                'user_cname': user.cname,
                'user_phone': user.phone,
                'user_email': user.email,
                'role_ids': roll_ids
            })
        return BaseRes(data=return_data)
    except Exception as e:
        logger.warning(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 11
0
async def delete_task(project_id: int = Body(..., embed=True),
                      id: int = 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
    session = Db.get_session()
    try:
        delete_item: AtpOverviewTask = session.query(AtpOverviewTask).get(id)
        if delete_item:
            delete_item.is_delete = 1
            delete_item.updator = token_user.user_id,
            delete_item.update_time = datetime.datetime.now()
            session.query(AtpOverviewTask).filter(*[
                AtpOverviewTask.project_id == delete_item.project_id,
                AtpOverviewTask.list_id == delete_item.list_id, AtpOverviewTask
                .sort > delete_item.sort, AtpOverviewTask.is_delete == 2
            ]).update({
                AtpOverviewTask.sort: AtpOverviewTask.sort - 1,
                AtpOverviewTask.updator: token_user.user_id,
                AtpOverviewTask.update_time: datetime.datetime.now()
            })
            session.commit()
        return BaseRes()
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    finally:
        session.close()
Ejemplo n.º 12
0
async def get_current_user(token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    session = Db.get_session()
    try:
        user_role_list: List[SysUserRole] = session.query(SysUserRole).filter(*[
            SysUserRole.is_delete == 2,
            SysUserRole.user_id == token_user.user_id
        ]).all()
        if len(user_role_list) == 0:
            return BaseRes(data=[])
        user_role_id_list = [x.role_id for x in user_role_list]
        menu_map_list: List[tuple] = session.query(distinct(SysRoleMenu.menu_id)).filter(*[
            SysRoleMenu.is_delete == 2,
            SysRoleMenu.role_id.in_(user_role_id_list)
        ]).all()
        menus_ids = set()
        for menu_map in menu_map_list:
            menus_ids.add(menu_map[0])
        menus: List[SysMenu] = session.query(SysMenu).filter(*[
            SysMenu.is_delete == 2,
            SysMenu.id.in_(menus_ids)
        ]).all()
        return_value = []
        for m in menus:
            return_value.append({
                'id': m.id,
                'name': m.name,
                'regExp': m.menu_reg,
                'path': m.menu_path,
                'parentId': m.parent_id,
                'icon': m.icon
            })
        return BaseRes(data=return_value)
    except Exception as e:
        logger.warning(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 13
0
async def update_editor(project_id: int = Body(..., embed=True),
                        title: str = Body(..., embed=True),
                        type: int = 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
    session = Db.get_session()
    try:
        editor = AtpProjectEditor(project_id=project_id,
                                  title=title,
                                  type=type,
                                  creator=token_user.user_id,
                                  create_time=datetime.datetime.now(),
                                  updator=token_user.user_id,
                                  update_time=datetime.datetime.now())
        session.add(editor)
        session.commit()
        return BaseRes(data={'id': editor.id})
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    finally:
        session.close()
Ejemplo n.º 14
0
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))
Ejemplo n.º 15
0
async def delete_user(user_id: int = Body(..., embed=True), token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    session = Db.get_session()
    try:
        session.query(SysUser).filter(*[
            SysUser.id == user_id,
            SysUser.is_delete == 2
        ]).update({
            SysUser.is_delete: 1,
            SysUser.updator: token_user.user_id,
            SysUser.update_time: datetime.now()
        })
        session.query(AtpProjectMember).filter(*[
            AtpProjectMember.is_delete == 2,
            AtpProjectMember.member_id == user_id
        ]).update({
            AtpProjectMember.is_delete: 1,
            AtpProjectMember.updator: token_user.user_id,
            AtpProjectMember.update_time: datetime.now()
        })
        session.commit()
        return BaseRes(data='success')
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=e)
Ejemplo n.º 16
0
async def update_list_sort(project_id: int = Body(..., embed=True),
                           start_index: int = Body(..., embed=True),
                           end_index: int = 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
    session = Db.get_session()
    try:
        target_list_columns: List[AtpOverviewList] = session.query(
            AtpOverviewList).filter(*[
                AtpOverviewList.is_delete == 2,
                AtpOverviewList.project_id == project_id,
            ]).order_by(AtpOverviewList.sort).all()
        new_sort = target_list_columns[end_index].sort
        if start_index < end_index:
            for i in target_list_columns[start_index + 1:end_index + 1]:
                i.sort -= 1
        else:
            for i in target_list_columns[end_index:start_index]:
                i.sort += 1
        target_list_columns[start_index].sort = new_sort
        session.commit()
        return BaseRes()
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    finally:
        session.close()
Ejemplo n.º 17
0
async def update_task(project_id: int = Body(..., embed=True),
                      task_id: int = Body(..., embed=True),
                      value: Any = Body(..., embed=True),
                      key: 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
    session = Db.get_session()
    try:
        session.query(AtpOverviewTask).filter(
            *[AtpOverviewTask.id == task_id, AtpOverviewTask.is_delete == 2
              ]).update({
                  getattr(AtpOverviewTask, key): value,
                  AtpOverviewTask.updator: token_user.user_id,
                  AtpOverviewTask.update_time: datetime.datetime.now()
              })
        session.commit()
        return BaseRes()
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    finally:
        session.close()
Ejemplo n.º 18
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))
Ejemplo n.º 19
0
async def add_user(user: AddUser, token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    hash_paaword = get_password_hash(user.password)
    session = Db.get_session()
    try:
        new_user = SysUser(
            name=user.user_name,
            password=hash_paaword,
            cname=user.user_cname,
            email=user.email,
            phone=user.phone,
            creator=token_user.user_id,
            create_time=datetime.now()
        )
        session.add(new_user)
        session.commit()
        for role_id in user.role_ids:
            session.add(SysUserRole(
                user_id=new_user.id,
                role_id=role_id,
                creator=token_user.user_id,
                create_time=datetime.now()
            ))
        session.commit()
        return BaseRes(data=new_user.id)
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=e)
Ejemplo n.º 20
0
async def get_all_menu(token_user: TokenUser = Depends(auth_token)) -> BaseRes:
    session = Db.get_session()
    try:
        menu_list: List[SysMenu] = session.query(SysMenu).filter(*[
            SysRole.is_delete == 2
        ]).all()
        return BaseRes(data=menu_list)
    except Exception as e:
        logger.warning(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 21
0
def verify_project_deleted(id: int):
    project_id = id
    project: AtpProject = Db.select_by_primary_key(AtpProject, project_id)
    if not project:
        return None, BaseRes(status=0, error='项目不存在')
    else:
        if project.is_delete == 1:
            return None, BaseRes(status=0, error='项目不存在')
        else:
            return project, None
Ejemplo n.º 22
0
async def get_workstation_projects(token_user: TokenUser = Depends(
    auth_token)) -> BaseRes:
    try:
        project_list: List[AtpProject] = Db.select_by_condition(
            AtpProject, [AtpProject.type == 1, AtpProject.is_delete == 2],
            AtpProject.create_time.desc())
        parted_project_list = []
        for project in project_list:
            is_part_in = Db.select_by_condition(
                AtpProjectMember,
                [
                    AtpProjectMember.is_delete == 2,
                    AtpProjectMember.project_id == project.id,
                    AtpProjectMember.member_id.in_([token_user.user_id])
                ],
            )
            if is_part_in:
                parted_project_list.append(project)
            if project.img:
                file: AtpFileSystemFile = Db.select_by_primary_key(
                    AtpFileSystemFile, project.img)
                project.img = {
                    'id': file.id,
                    'url': get_settings().archive_host + file.name
                }
            else:
                project.img = {
                    'id':
                    0,
                    'url':
                    'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
                }
        session = Db.get_session()
        report_list: List[AtpProjectTestReport] = session.query(
            AtpProjectTestReport).join(
                AtpProject,
                AtpProject.id == AtpProjectTestReport.project_id).filter(
                    AtpProjectTestReport.is_delete == 2,
                    AtpProjectTestReport.creator == token_user.user_id,
                    AtpProject.is_delete == 2).limit(10).all()
        total_projects_num = Db.select_count_by_condition(
            AtpProject.id, [AtpProject.is_delete == 2])
        return BaseRes(
            data={
                'underway_projects': project_list[:6],
                'parted_projects': parted_project_list[:6],
                'my_reports': report_list,
                'total_projects_num': total_projects_num,
                'total_underway_projects_num': len(project_list)
            })
    except Exception as e:
        logger.error(e)
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 23
0
async def get_env_by_project_id(project_id: int = Query(...)) -> BaseRes:
    _, error = verify_project_deleted(project_id)
    if error:
        return error
    try:
        env_list: List[AtpProjectEnv] = Db.select_by_condition(AtpProjectEnv,
                                                               [AtpProjectEnv.is_delete == 2,
                                                                AtpProjectEnv.project_id == project_id])
        return BaseRes(data=env_list)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 24
0
async def get_task_by_condition(project_id: int = Query(...),
                                keyword: str = Query(None),
                                relation_type: int = Query(...),
                                filter_type: int = Query(...),
                                token_user: TokenUser = Depends(
                                    auth_token)) -> BaseRes:
    _, error = verify_project_deleted(project_id)
    if error:
        return error
    try:
        task_list_condition: list = [
            AtpOverviewList.is_delete == 2,
            AtpOverviewList.project_id == project_id
        ]
        task_list: List[AtpOverviewList] = Db.select_by_condition(
            AtpOverviewList, task_list_condition, AtpOverviewList.sort)
        for l in task_list:
            task_condition: list = [
                AtpOverviewTask.is_delete == 2,
                AtpOverviewTask.project_id == project_id,
                AtpOverviewTask.list_id == l.id
            ]
            if keyword:
                task_condition.append(
                    AtpOverviewTask.title.like(f'%{keyword}%'))
            if filter_type in [1, 2]:
                task_condition.append(AtpOverviewTask.status == filter_type)
            if relation_type == 2:
                task_condition.append(
                    AtpOverviewTask.creator == token_user.user_id)
            tasks: List[AtpOverviewTask] = Db.select_by_condition(
                AtpOverviewTask, task_condition, AtpOverviewTask.sort)
            # 根据条件找出所有符合条件的, 再筛选我关注的
            if relation_type == 3:
                target_tasks = []
                for t in tasks:
                    if token_user.user_id in json.loads(t.follower):
                        target_tasks.append(t)
                tasks = target_tasks
            l.taskList = tasks
            for t in tasks:
                user: SysUser = Db.select_by_primary_key(
                    SysUser, int(str(t.creator)))
                t.creator = {
                    'id': user.id if user else 0,
                    'cname': user.cname if user else ''
                }
            l.taskList = tasks
        return BaseRes(data=task_list)
    except Exception as e:
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 25
0
async def login(login_user: LoginUser) -> BaseRes:
    user_list = Db.select_by_condition(SysUser, [SysUser.name == login_user.user_name, SysUser.is_delete == '2'])
    if (len(user_list)) == 0:
        return BaseRes(status=0, error='用户名或密码错误')
    else:
        user: SysUser = user_list[0]
        if verify_password(login_user.password, user.password):
            token_data = {'id': user.id, 'cname': user.cname}
            token = create_access_token(data=token_data)
            data = {'token': token, 'type': 'Bearer'}
            return BaseRes(data=data)
        else:
            return BaseRes(status=0, error='用户名或密码错误')
Ejemplo n.º 26
0
async def get_all_module(project_id: int = Query(...)) -> BaseRes:
    _, error = verify_project_deleted(project_id)
    if error:
        return error
    try:
        return_data: List[AtpProjectModule] = Db.select_by_condition(
            AtpProjectModule, [
                AtpProjectModule.is_delete == 2, AtpProjectModule.project_id
                == project_id
            ])
        return BaseRes(data=return_data)
    except Exception as e:
        logger.error(e)
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 27
0
async def update_role(
        id: int = Body(..., embed=True),
        name: str = Body(..., embed=True),
        menu_list: List[int] = Body(..., embed=True),
        token_user: TokenUser = Depends(auth_token)
) -> BaseRes:
    session = Db.get_session()
    try:
        session.query(SysRole).filter(*[
            SysRole.id == id,
            SysRole.is_delete == 2
        ]).update({
            SysRole.role_name: name,
            SysRole.updator: token_user.user_id,
            SysRole.update_time: datetime.now()
        })
        session.query(SysRoleMenu).filter(*[
            SysRoleMenu.role_id == id,
            SysRoleMenu.menu_id.notin_(menu_list)
        ]).update({
            SysRoleMenu.is_delete: 1,
            SysRoleMenu.updator: token_user.user_id,
            SysRoleMenu.update_time: datetime.now()
        }, synchronize_session=False)
        session.query(SysRoleMenu).filter(*[
            SysRoleMenu.role_id == id,
            SysRoleMenu.menu_id.in_(menu_list)
        ]).update({
            SysRoleMenu.is_delete: 2,
            SysRoleMenu.updator: token_user.user_id,
            SysRoleMenu.update_time: datetime.now()
        }, synchronize_session=False)
        temps: List[SysRoleMenu] = session.query(SysRoleMenu).filter(*[
            SysRoleMenu.role_id == id,
            SysRoleMenu.menu_id.in_(menu_list)
        ]).all()
        already_menu_ids = set([x.menu_id for x in temps])
        gap_menu_ids = set(menu_list) - already_menu_ids
        for i in gap_menu_ids:
            session.add(SysRoleMenu(
                menu_id=i,
                role_id=id
            ))
        session.commit()
        return BaseRes()
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
Ejemplo n.º 28
0
async def update_suite_case_sort(
        before_id: int = Body(..., embed=True),
        after_id: int = Body(..., embed=True),
        project_id: int = Body(..., embed=True),
        suite_id: int = Body(..., embed=True),
        type: int = 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
    session = Db.get_session()
    try:
        all_relation: List[AtpProjectApiSuiteCaseRelation] = session.query(AtpProjectApiSuiteCaseRelation).filter(
            AtpProjectApiSuiteCaseRelation.is_delete == 2,
            AtpProjectApiSuiteCaseRelation.suite_id == suite_id
        ).order_by(AtpProjectApiSuiteCaseRelation.sort).all()
        before_index = None
        after_index = None
        for index, relation in enumerate(all_relation):
            if relation.case_id == before_id:
                before_index = index
            if relation.case_id == after_id:
                after_index = index
        if type == 1:
            temp = all_relation[before_index]
            del all_relation[before_index]
            temp.sort = all_relation[after_index].sort
            all_relation.insert(after_index, temp)
            for i, v in enumerate(all_relation[after_index + 1:]):
                v.sort = i + after_index + 2
        elif type == 2:
            temp = all_relation[before_index]
            del all_relation[before_index]
            all_relation.insert(after_index, temp)
            for i, v in enumerate(all_relation[before_index:]):
                v.sort = i + before_index + 1
        session.commit()
        return BaseRes()
    except Exception as e:
        session.rollback()
        logger.error(traceback.format_exc())
        return BaseRes(status=0, error=str(e))
    finally:
        session.close()
Ejemplo n.º 29
0
async def create_project_case(
    request: ProjectCase,
    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
    session = Db.get_session()
    try:
        case = AtpProjectCase(name=request.name,
                              module_id=request.module_id,
                              project_id=request.project_id,
                              priority=request.priority,
                              precondition=request.precondition,
                              remark=request.remark,
                              creator=token_user.user_id,
                              create_time=datetime.datetime.now())
        session.add(case)
        session.commit()
        for step in request.steps:
            session.add(
                AtpProjectCaseStep(case_id=case.id,
                                   step=step.step,
                                   exception=step.exception,
                                   creator=token_user.user_id,
                                   create_time=datetime.datetime.now()))
        session.commit()
        return BaseRes()
Ejemplo n.º 30
0
async def get_case_by_module_id(project_id: int = Body(..., embed=True),
                                module_id: int = Body(None, embed=True),
                                keyword: str = Body(None,
                                                    embed=True)) -> BaseRes:
    _, error = verify_project_deleted(project_id)
    if error:
        return error
    condition = [
        AtpProjectCase.is_delete == 2, AtpProjectCase.project_id == project_id
    ]
    if module_id:
        condition.append(AtpProjectCase.module_id == module_id)
    if keyword:
        condition.append(AtpProjectCase.name.like(f'%{keyword}%'))
    try:
        case_list: List[AtpProjectCase] = Db.select_by_condition(
            AtpProjectCase, condition, AtpProjectCase.id.desc())
        index = 1
        for case in case_list:
            case.index = index
            index += 1
            case.steps = Db.select_by_condition(AtpProjectCaseStep, [
                AtpProjectCaseStep.is_delete == 2, AtpProjectCaseStep.case_id
                == case.id
            ])
            case.cname = Db.select_by_primary_key(SysUser, case.creator).cname
            case.module_name = Db.select_by_primary_key(
                AtpProjectModule, case.module_id).name
        return BaseRes(data=case_list)