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()
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()
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)
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))
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))
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))
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)
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))
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()
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()
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()
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)
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()
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()
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))
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))
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))
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()
async def create_list(project_id: int = Body(..., embed=True), list_id: int = Body(..., embed=True), title: str = Body(..., embed=True), priority: int = Body(..., embed=True), follower: List[int] = Body(..., embed=True), description: str = Body(None, embed=True), attachment: List[int] = Body(..., embed=True), relevance_case: List[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: max_sort_item = session.query(func.max(AtpOverviewTask.sort)).filter(*[ AtpOverviewTask.is_delete == 2, AtpOverviewTask.project_id == project_id, AtpOverviewTask.list_id == list_id ]).first() if max_sort_item[0]: max_sort = max_sort_item[0] + 1 else: max_sort = 1 session.add( AtpOverviewTask(title=title, project_id=project_id, sort=max_sort, description=description, priority=priority, follower=json.dumps(follower), img=json.dumps(attachment), relevance_case=json.dumps(relevance_case), list_id=list_id, status=2, creator=token_user.user_id, create_time=datetime.datetime.now(), is_delete=2)) 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()
async def update_user_info(data: UpdateUserInfo, token_user: TokenUser = Depends(auth_token)) -> BaseRes: session = Db.get_session() try: session.query(SysUser).filter(*[ SysUser.id == data.user_id, SysUser.is_delete == 2 ]).update({ SysUser.cname: data.user_cname, SysUser.email: data.email, SysUser.phone: data.phone, SysUser.updator: token_user.user_id, SysUser.update_time: datetime.now() }) if data.role_ids is not None: session.query(SysUserRole).filter(*[ SysUserRole.user_id == data.user_id, SysUserRole.role_id.notin_(data.role_ids) ]).update({ SysUserRole.is_delete: 1, SysUserRole.updator: token_user.user_id, SysUserRole.update_time: datetime.now() }, synchronize_session=False) session.query(SysUserRole).filter(*[ SysUserRole.user_id == data.user_id, SysUserRole.role_id.in_(data.role_ids) ]).update({ SysUserRole.is_delete: 2, SysUserRole.updator: token_user.user_id, SysUserRole.update_time: datetime.now() }, synchronize_session=False) temps: List[SysUserRole] = session.query(SysUserRole).filter(*[ SysUserRole.user_id == data.user_id, SysUserRole.role_id.in_(data.role_ids) ]).all() already_role_ids = set([x.role_id for x in temps]) gap_role_ids = set(data.role_ids) - already_role_ids for i in gap_role_ids: session.add(SysUserRole( user_id=data.user_id, role_id=i )) session.commit() return BaseRes() except Exception as e: session.rollback() logger.error(traceback.format_exc()) return BaseRes(status=0, error=str(e))
async def get_editor(id: int = Query(...), token_user: TokenUser = Depends(auth_token)) -> BaseRes: session = Db.get_session() try: editor: AtpProjectEditor = session.query(AtpProjectEditor).get(id) if not editor: return BaseRes(status=0, error="Can't find editor by the id: " + str(id)) _, error = verify_project_deleted(editor.project_id) if error: return error return BaseRes(data=editor) except Exception as e: logger.error(traceback.format_exc()) return BaseRes(status=0, error=str(e)) finally: session.close()
async def create_list(project_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 session = Db.get_session() try: exists_condition = [ AtpOverviewList.is_delete == 2, AtpOverviewList.project_id == project_id, AtpOverviewList.title == title ] count = session.query(func.count( AtpOverviewList.id)).filter(*exists_condition).all()[0][0] if count != 0: return BaseRes(status=0, error='任务栏标题已存在') max_sort_item = session.query(func.max(AtpOverviewList.sort)).filter(*[ AtpOverviewList.is_delete == 2, AtpOverviewList.project_id == project_id ]).first() if max_sort_item[0]: max_sort = max_sort_item[0] + 1 else: max_sort = 1 session.add( AtpOverviewList(title=title, project_id=project_id, sort=max_sort, creator=token_user.user_id, create_time=datetime.datetime.now(), is_delete=2)) 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()
async def upload_project_img( projectImg: UploadFile = File(...), project_id=Body(None, embed=True), token_user: TokenUser = Depends(auth_token) ) -> BaseRes: encrypt_filename: str = hashlib.md5((projectImg.filename + str(time.time())).encode()).hexdigest() suffix = projectImg.content_type.split('/')[1] filename = encrypt_filename + '.' + suffix try: with open(get_settings().static_path + filename, 'wb+') as f: f.write(await projectImg.read()) session = Db.get_session() file = AtpFileSystemFile( name=filename, creator=token_user.user_id, create_time=datetime.datetime.now() ) session.add(file) session.commit() if project_id: _, error = verify_project_filed(project_id) if error: return error _, error = verify_project_owner(token_user.user_id, project_id) if error: return error session.query(AtpProject) \ .filter(*[AtpProject.id == project_id, AtpProject.is_delete == 2]) \ .update({ # AtpProject.img: 'http://localhost:8900/static/' + filename, AtpProject.img: file.id, AtpProject.updator: token_user.user_id, AtpProject.update_time: datetime.datetime.now() }) session.commit() return BaseRes(data={'id': file.id, 'fileName': filename, 'url': get_settings().archive_host + filename}) except Exception as e: logger.error(traceback.format_exc()) return BaseRes(status=0, error=str(e))
async def get_all_editor(project_id: int = Query(...), token_user: TokenUser = Depends( auth_token)) -> BaseRes: _, error = verify_project_deleted(project_id) if error: return error session = Db.get_session() try: editors: List[AtpProjectEditor] = session.query( AtpProjectEditor).filter(*[ AtpProjectEditor.is_delete == 2, AtpProjectEditor.project_id == project_id ]).order_by(AtpProjectEditor.update_time.desc()).all() for editor in editors: user: SysUser = session.query(SysUser).get(editor.updator) editor.updator = user.cname return BaseRes(data=editors) except Exception as e: logger.error(traceback.format_exc()) return BaseRes(status=0, error=str(e)) finally: session.close()
async def upload_task_img(projectImg: UploadFile = File(...), project_id=Body(..., embed=True), task_id=Body(None, embed=True), token_user: TokenUser = Depends( auth_token)) -> BaseRes: _, error = verify_project_filed(project_id) if error: return error _, error = verify_project_owner(token_user.user_id, project_id) if error: return error encrypt_filename: str = hashlib.md5( (projectImg.filename + str(time.time())).encode()).hexdigest() suffix = projectImg.content_type.split('/')[1] filename = encrypt_filename + '.' + suffix try: with open(get_settings().static_path + filename, 'wb+') as f: f.write(await projectImg.read()) session = Db.get_session() file = AtpFileSystemFile(name=filename, creator=token_user.user_id, create_time=datetime.datetime.now()) session.add(file) session.commit() if task_id: task: AtpOverviewTask = session.query(AtpOverviewTask).get(task_id) file_ids = json.loads(task.img) if task.img else [] file_ids.append(file.id) task.img = json.dumps(file_ids) session.commit() return BaseRes( data={ 'fileName': filename, 'id': file.id, 'url': get_settings().archive_host + filename }) except Exception as e: logger.error(e) return BaseRes(status=0, error=str(e))
async def delete_module(id_list: List[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(AtpProjectModule).filter( AtpProjectModule.is_delete == 2, AtpProjectModule.id.in_(id_list)).update( {AtpProjectModule.is_delete: 1}, synchronize_session=False) session.commit() return BaseRes() except Exception as e: session.rollback() logger.error(e) return BaseRes(status=0, error=str(e))
async def get_current_user(token_user: TokenUser = Depends(auth_token)) -> BaseRes: session = Db.get_session() try: role_list: List[SysRole] = session.query(SysRole).filter(*[ SysRole.is_delete == 2 ]).all() return_data = [] for role in role_list: role_menu_map: List[SysRoleMenu] = session.query(SysRoleMenu).filter(*[ SysRoleMenu.is_delete == 2, SysRoleMenu.role_id == role.id ]).all() menu_ids = [x.menu_id for x in role_menu_map] return_data.append({ 'id': role.id, 'role_name': role.role_name, 'menu_list': menu_ids }) return BaseRes(data=return_data) except Exception as e: logger.warning(traceback.format_exc()) return BaseRes(status=0, error=str(e))
async def get_case_by_id( id: int = Query(...), project_id: int = Query(...), ) -> BaseRes: _, error = verify_project_deleted(project_id) if error: return error session = Db.get_session() try: case: AtpProjectCase = session.query(AtpProjectCase).filter( *[AtpProjectCase.is_delete == 2, AtpProjectCase.id == id]).first() create_user: SysUser = session.query(SysUser).filter( *[SysUser.is_delete == 2, SysUser.id == case.creator]).first() module_list: List[AtpProjectModule] = session.query( AtpProjectModule).filter(*[ AtpProjectModule.is_delete == 2, AtpProjectModule.project_id == project_id ]).all() module_breakcrumb = [] target_module: AtpProjectModule or None = None for i in module_list: if case.module_id == i.id: target_module = i
async def create_project_case(project_id: int = Body(..., embed=True), case_id_list: List[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() now_time = datetime.datetime.now() try: session.query(AtpProjectCase).filter( AtpProjectCase.is_delete == 2, AtpProjectCase.id.in_(case_id_list)).update( { AtpProjectCase.is_delete: 1, AtpProjectCase.updator: token_user.user_id, AtpProjectCase.update_time: now_time }, synchronize_session=False) session.query(AtpProjectCaseStep).filter( AtpProjectCaseStep.is_delete == 2, AtpProjectCaseStep.case_id.in_(case_id_list)).update( { AtpProjectCaseStep.is_delete: 1, AtpProjectCaseStep.updator: token_user.user_id, AtpProjectCaseStep.update_time: now_time }, synchronize_session=False) session.commit() return BaseRes() except Exception as e: session.rollback() logger.error(e) return BaseRes(status=0, error=str(e))
async def get_task_by_condition(project_id: int = Query(...), task_id: int = Query(...), token_user: TokenUser = Depends( auth_token)) -> BaseRes: _, error = verify_project_deleted(project_id) if error: return error session = Db.get_session() try: task: AtpOverviewTask = session.query(AtpOverviewTask).get(task_id) followers: List[SysUser] = session.query(SysUser).filter(*[ SysUser.is_delete == 2, SysUser.id.in_(json.loads(task.follower)) ]).all() imgs: List[AtpFileSystemFile] = session.query( AtpFileSystemFile).filter(*[ AtpFileSystemFile.is_delete == 2, AtpFileSystemFile.id.in_(json.loads(task.img)) ]).all() cases: List[AtpProjectCase] = session.query(AtpProjectCase).filter(*[ AtpProjectCase.is_delete == 2, AtpProjectCase.id.in_(json.loads(task.relevance_case)) ]).all() img_list = [] for i in imgs: img_list.append({ 'id': i.id, 'name': i.name, 'url': get_settings().archive_host + i.name }) task.follower = followers task.img = img_list task.relevance_case = cases return BaseRes(data=task) except Exception as e: logger.error(traceback.format_exc()) return BaseRes(status=0, error=str(e))