async def get(self): user = self.get_current_session_user() # 获取当前用户 db = self.get_async_mongo() user_rel_col = db.user_grp_rel grp_rel = await user_rel_col.find_one({'user': user}) if grp_rel is None: res = dict(result=False) return get_std_json_response(data=jsontool.dumps(res)) if grp_rel['g_name'] == 'admin': res = dict(result=True) return get_std_json_response(data=jsontool.dumps(res)) else: res = dict(result=False) return get_std_json_response(data=jsontool.dumps(res))
async def wrapper(self, *args, **kwargs): page_idx = self.get_argument('page_idx', '1') # 页面索引号-var page_cap = self.get_argument('page_cap', '15') # 一页的记录容量-var page_idx = int(page_idx) page_cap = int(page_cap) my_paginator_data = await method(self, *args, **kwargs) page_count = await my_paginator_data.count() msg_details = my_paginator_data.skip(page_cap * (page_idx - 1)).limit( page_cap) # 进行分页 total_page = math.ceil(page_count / page_cap) # 总的页面数 msg_content_list = await msg_details.to_list(page_cap) res_dict = dict( page_total_cnts=total_page, page_idx=page_idx, page_cap=page_cap, page_data=msg_content_list, ) res_str = jsontool.dumps(res_dict, ensure_ascii=False) return res_str
async def get_content_list(self, *args, **kwargs): """ 直接传入项目名称和表的名称,返回分页的信息 :param self: :param args: :param kwargs:col_name :return: """ page_cap = self.get_argument('page_cap', '10') # 一页的记录容量-var pro_id = self.get_argument('pro_id', None) col_name = kwargs.get('col_name', None) hide_fields = kwargs.get('hide_fields', None) # 需要隐藏的字段,一个dict """:type:dict""" if list_have_none_mem(*[col_name, pro_id, page_cap]): return ConstData.msg_args_wrong page_cap = int(page_cap) mongo_conn = self.get_async_mongo() mycol = mongo_conn[col_name] if pro_id is None: msg_details = mycol.find({ "is_del": False }, hide_fields).sort([('date_time', DESCENDING)]) # 升序排列 else: msg_details = mycol.find({ 'pro_id': ObjectId(pro_id), "is_del": False }, hide_fields).sort([('date_time', DESCENDING)]) # 升序排列 msg_details_cnt = await msg_details.count() page_size = page_cap if page_cap < msg_details_cnt else msg_details_cnt msg_content_list = await msg_details.to_list(page_size) return get_std_json_response(data=jsontool.dumps(msg_content_list))
async def get(self): stoken = self.get_argument('stoken', None) if list_have_none_mem(*[stoken]): return ConstData.msg_args_wrong db = self.get_async_mongo() share_col = db.share_test_report utest_col = db['unit_test_data'] share_obj = await share_col.find_one({'stoken': stoken}) if share_obj is None: return ConstData.msg_forbidden # todo 把完整的Unittest的报告内容获取出来并返回 msg_details = utest_col.find( {"_id": ObjectId(str(share_obj['rep_id']))}) msg_content_list = await msg_details.to_list(1) msg_content = msg_content_list[0] # 做一个阅读访问次数的计数 cnt = share_obj['cnt'] if cnt is None: cnt = 0 cnt += 1 await share_col.update({'stoken': stoken}, {'$set': {'cnt': cnt}}) return get_std_json_response( data=jsontool.dumps(msg_content, ensure_ascii=False))
async def get(self): tbl_out = { 'http_port': HTTP_PORT, 'process_num ': SERVER_PROCESS, 'db_server': mongodb_cfg.host, 'mongo_port': mongodb_cfg.port } try: con = motor.MotorClient(host=mongodb_cfg.host, port=mongodb_cfg.port) db = con[mongodb_cfg.db_name] res = await db.authenticate(mongodb_cfg.user_name, mongodb_cfg.user_pwd) if res is True: tbl_out['connect'] = True user_id = "admin" db = self.get_async_mongo() user_col = db.g_users res = await user_col.find_one({'user_id': user_id}) if res: return ConstData.msg_exist else: tbl_out['connect'] = False except: traceback.print_exc() tbl_out['connect'] = "mongodb connect error" return get_std_json_response( data=jsontool.dumps(tbl_out, ensure_ascii=False))
async def get(self): org_id = self.get_argument('org_id', None) if list_have_none_mem(*[ org_id, ]): return ConstData.msg_args_wrong # org = await Organization.objects.get(id=ObjectId(str(org_id))) # """:type Organization""" # if org is None: # return ConstData.msg_none db = self.get_async_mongo() app_col = db.test_data_app test_app = await app_col.find_one( {'organization': ObjectId(str(org_id))}) # test_app = await TestDataApp.objects.get(organization=ObjectId(str(org_id))) # 如果后面是1对多了,则查询多条 if test_app is None: return ConstData.msg_none else: # result = [] # result.append(test_app.to_dict()) return get_std_json_response(code=200, data=jsontool.dumps( test_app, ensure_ascii=False))
async def post(self): req_dict = self.get_post_body_dict() # passwd = req_dict.get('passwd', None) nickname = req_dict.get('nick_name', None) if list_have_none_mem(*[nickname]): return ConstData.msg_args_wrong db = self.get_async_mongo() user_col = db.g_users current_auth_user = await user_col.find_one( {'_id': self.cache_session['user']}) current_auth_user['nickname'] = nickname await user_col.update({'_id': self.cache_session['user']}, {'$set': { 'nickname': nickname }}, upsert=False) # current_auth_user = await current_auth_user.save() res_dict = dict(user_id=current_auth_user['user_id'], nickname=current_auth_user['nickname'], rc_time=current_auth_user['rc_time']) return get_std_json_response( data=jsontool.dumps(res_dict, ensure_ascii=False))
async def get(self): current_user_id = self.cache_session['user'] # """:type:User""" mongo_conn = self.get_async_mongo() user_col = mongo_conn['g_users'] current_auth_user = await user_col.find_one( {'_id': ObjectId(current_user_id)}) # print("user_col.find_one({'user_id': %s})" % current_user_id) if not current_auth_user: return ConstData.msg_fail res_dict = dict( user_id=current_auth_user["user_id"], nickname=current_auth_user["nickname"], rc_time=current_auth_user["rc_time"], # status=current_auth_user["status"], ) res_data = jsontool.dumps(res_dict, ensure_ascii=False) dlog.debug(res_data) return get_std_json_response(data=res_data)
async def post(self): post_json = self.get_post_body_dict() id = post_json.get('id', None) project_name = post_json.get('name', None) mark = post_json.get('mark', None) if list_have_none_mem(*[id, project_name, mark]): return ConstData.msg_args_wrong # todo 做资源归属和权限的判断 db = self.get_async_mongo() proj_col = db.test_project project_obj = await proj_col.find_one({'_id': ObjectId(str(id))}) user_org = await self.get_organization() organization = project_obj['organization'] if (project_obj is None) or (organization is None): return ConstData.msg_forbidden pro_org_id = organization if pro_org_id != user_org: return ConstData.msg_forbidden data = dict( project_name=project_name, mark=mark ) result = await proj_col.update({'_id': ObjectId(str(id))}, {'$set': data}, upsert=False) res_str = get_std_json_response(code=200, data=jsontool.dumps(result)) return res_str
async def post(self): appid = self.get_argument('appid_form', None) appkey = self.get_argument('appkey_form', None) if list_have_none_mem(*[appid, appkey]): return ConstData.msg_args_wrong db = self.get_async_mongo() app_col = db.test_data_app test_data_app = await app_col.find_one({'app_id': str(appid)} ) # 后面要为app_id建立index if test_data_app is None: return ConstData.msg_none # 可以和数据库连接形成动态的验证 if str(appkey) == str(test_data_app['app_key']): # todo:后面对于自动化的工具应用,要隔离部署,单独做一套体系,先默认使用某个人的信息了 app_session = await self.create_app_session( app_id=appid, client_type=ClientTypeDict.api) if app_session is None: return ConstData.msg_forbidden # todo 后面要做高频的api接口的统计系统 res_data = jsontool.dumps(app_session) dlog.debug(res_data) return get_std_json_response(data=res_data) else: return ConstData.msg_fail
async def post(self): post_json = self.get_post_body_dict() mark = post_json.get('mark', None) project_name = post_json.get('name', None) organization = await self.get_organization() user = self.get_current_session_user() db = self.get_async_mongo() proj_col = db.test_project org_col = db.organization org_res = await org_col.find_one({'_id': ObjectId(organization)}) org_name = org_res['name'] user_col = db.g_users user_res = await user_col.find_one({'_id': ObjectId(user)}) user_nickname = user_res['nickname'] new_data = dict( project_name=project_name, mark=mark, organization=organization, org_name=org_name, owner=user, owner_name=user_nickname, ) new_data = set_default_rc_tag(new_data) result = await proj_col.insert(new_data) res_str = get_std_json_response(code=200, data=jsontool.dumps(result)) return res_str
async def get(self): """ 1. 自己当前的组织下的资源 2. 生成share的内容 支持手机端的 :return: """ rep_id = self.get_argument('rep_id', None) # 测试报告的ID if list_have_none_mem(*[rep_id]): return ConstData.msg_args_wrong db = self.get_async_mongo() share_col = db.share_test_report utest_col = db.unit_test_data proj_col = db.test_project # todo 做资源归属和权限的判断 test_data = await utest_col.find_one({'_id': ObjectId(rep_id)}) project = await proj_col.find_one({'_id': test_data['pro_id']}) # if (project is None) or (project.organization is None): if project is None: return ConstData.msg_forbidden user_org = await self.get_organization() pro_org_id = project['organization'] if pro_org_id != user_org: return ConstData.msg_forbidden share_obj = await share_col.find_one({'rep_id': rep_id}) if share_obj is None: # 如果不存在分享Link则创建一组 stoken = generate_uuid_token() # 生成一组随机串,分享的时候会看到 share_data = dict(rep_id=rep_id, stoken=stoken, cnt=0, is_del=False, project=project['_id'], p_name=project['project_name'], owner=project['owner'], owner_name=project['owner_name'], organization=project['organization'], org_name=project['org_name']) # await share_obj.set_project_tag(project) # await share_obj.set_org_user_tag(http_req=self) share_data = set_default_rc_tag(share_data) await share_col.insert(share_data) share_url = share_page + stoken else: # 如果有,则直接使用 share_url = share_page + share_obj['stoken'] res_dict = dict(share_url=share_url) return get_std_json_response(data=jsontool.dumps(res_dict))
async def get(self): stoken = self.get_argument('stoken', None) if list_have_none_mem(*[stoken]): return ConstData.msg_args_wrong page_size = self.get_argument('page_size', 30) page_idx = self.get_argument('page_idx', 1) page_size = int(page_size) page_idx = int(page_idx) db = self.get_async_mongo() share_col = db.share_project_report utest_col = db['unit_test_data'] share_obj = await share_col.find_one({'stoken': stoken}) if share_obj is None: return ConstData.msg_forbidden # 做一个阅读访问次数的计数 await share_col.update({'stoken': stoken}, {'$inc':{'cnt': 1}}) condition = { "pro_id": share_obj['project'], "is_del": False } #todo: delete default next release if 'tag' in share_obj.keys(): tag = share_obj['tag'] if tag != 'default': condition['tag'] = tag else: condition['$or'] = [ {'tag': tag}, {'tag': {'$exists': False}} ] else: condition['$or'] = [ {'tag': 'default'}, {'tag': {'$exists': False}} ] res = utest_col.find( condition, {"details": 0}, sort=[('rc_time', DESCENDING)]) page_count = await res.count() msg_details = res.skip(page_size * (page_idx - 1)).limit(page_size) # 进行分页 total_page = math.ceil(page_count / page_size) # 总的页面数 msg_content_list = await msg_details.to_list(page_size) page_res = dict( page_idx=page_idx, page_total_cnts=total_page, page_cap=page_size, page_data=msg_content_list ) return get_std_json_response(data=jsontool.dumps(page_res, ensure_ascii=False))
async def get(self): """ 用户当前视图下的组织信息 :return: """ res = await self.get_organization() db = self.get_async_mongo() org_col = db.organization org_res = await org_col.find_one({'_id': ObjectId(res)}) return get_std_json_response( data=jsontool.dumps(org_res, ensure_ascii=False))
def get(self): print('run app-info:', app_version) res = dict( server='tornado', # web服务器 app_version=app_version, # 应用版本 dtlib_version=dtlib.VERSION, # 第三方库dt-lib的版本 req_time=timetool.get_current_time_string(), # 当前查询时间点 timezone=timetool.get_time_zone(), # 当前服务器的时区 ) return get_std_json_response( data=jsontool.dumps(res, ensure_ascii=False))
def get(self): """ 返回客户端的公网IP地址及端口 :return: """ client_req = self.request res_dict = dict(remote_ip=client_req.remote_ip, method=client_req.method, path=client_req.path, headers=client_req.headers._dict) return get_std_json_response(data=jsontool.dumps(res_dict))
async def get(self): """ 获取用户的联系信息 :return: """ db = self.get_async_mongo() user_col = db.user_detail_info user_detail = await user_col.find_one( {'user': self.get_current_session_user()}) if user_detail is None: # 如果为空则创建一个 user_detail = {} return get_std_json_response(data=jsontool.dumps(user_detail))
async def get(self): stoken = self.get_argument('stoken', None) if list_have_none_mem(*[stoken]): return ConstData.msg_args_wrong page_size = self.get_argument('page_size', 30) page_idx = self.get_argument('page_idx', 1) page_size = int(page_size) page_idx = int(page_idx) db = self.get_async_mongo() share_col = db.share_project_report utest_col = db['unit_test_data'] share_obj = await share_col.find_one({'stoken': stoken}) if share_obj is None: return ConstData.msg_forbidden # todo 把完整的Unittest的报告内容获取出来并返回 # 做一个阅读访问次数的计数 cnt = share_obj['cnt'] if cnt is None: cnt = 0 cnt += 1 await share_col.update({'stoken': stoken}, {'$set': {'cnt': cnt}}) res = utest_col.find({ "pro_id": share_obj['project'], "is_del": False }, {"details": 0}, sort=[('rc_time', DESCENDING)]) page_count = await res.count() msg_details = res.skip(page_size * (page_idx - 1)).limit( page_size) # 进行分页 total_page = math.ceil(page_count / page_size) # 总的页面数 msg_content_list = await msg_details.to_list(page_size) page_res = dict(page_idx=page_idx, page_total_cnts=total_page, page_cap=page_size, page_data=msg_content_list) return get_std_json_response( data=jsontool.dumps(page_res, ensure_ascii=False))
async def get(self): pro_id = self.get_argument('pro_id', None) if pro_id is None: return ConstData.msg_args_wrong db = self.get_async_mongo() pro_col = db.test_project tags = await pro_col.find_one({'_id': ObjectId(pro_id)}, {'tags': 1}) # test_data_col = db.unit_test_data # tags = await test_data_col.distinct("tag", # {"pro_id": ObjectId(pro_id), 'is_del': False, 'tag': {'$exists': True}}) tag_list = list() if 'tags' in tags.keys(): tag_list = tags['tags'] msg_succeed = '{"code":%s,"msg":"success","data":%s}' % (ResCode.ok, jsontool.dumps(tag_list)) # 操作成功 return msg_succeed
async def get(self): """ 初始化账号 :return: """ user_id = "admin" passwd = "admin@2018" u_name = 'your nickname' db = self.get_async_mongo() user_col = db.g_users user_reg_col = db.user_reg_info res = await user_col.find_one({'user_id': user_id}) if res: return ConstData.msg_exist rand_salt = get_rand_salt() new_user = { 'user_id': user_id, 'salt': rand_salt, 'nickname': u_name, 'passwd': hashlibmd5with_salt(passwd, rand_salt) } new_user = set_default_rc_tag(new_user) new_user.update(self.set_template()) user_res = await user_col.insert(new_user) # new_user = await new_user.save() # """:type:User""" new_user_reg_info = {'user': user_res, 'u_name': u_name} new_user_reg_info.update(self.set_http_tag()) new_user_reg_info = set_default_rc_tag(new_user_reg_info) await user_reg_col.insert(new_user_reg_info) # await user_reg_info.save() org = await self.create_dft_organization(new_user_reg_info, is_default=True) await self.create_dft_org_rel(new_user_reg_info, org, is_default=False, is_current=True) res_dict = await self.create_org_app(org) res_dict['user'] = new_user['user_id'] res_dict['password'] = passwd invite_json = jsontool.dumps(res_dict, ensure_ascii=False) return get_std_json_response(data=invite_json)
async def get(self): appid = self.get_argument('appid', None) if list_have_none_mem(*[appid]): return ConstData.msg_args_wrong # todo 后续要加一次数据库IO来查询是否存在此qrcode unauth_token = await self.create_anonymous_token( MobileAuthPcToken, appid=appid, client_type=ClientTypeDict.browser) """:type:MobileAuthPcToken""" # 这个链接是给手机打开的,用来给PC签名授权 url = '%s/auth2/app-confirm/' % QR_AUTH_DOMAIN res_dict = dict(appid=appid, url=url, qrtoken=unauth_token.token) res_data = get_std_json_response(data=jsontool.dumps(res_dict)) return res_data
async def get(self, *args, **kwargs): """ admin用户请求该接口可以获取所有用户列表 :param self: :param args: :param kwargs:col_name :return: """ # todo: admin show_field = dict(_id=1, user_id=1, nickname=1, is_lock=1) mongo_conn = self.get_async_mongo() mycol = mongo_conn['g_users'] user_list = mycol.find({"is_del": False}, show_field) # 升序排列 user_cnt = await user_list.count() user_list = await user_list.to_list(user_cnt) return get_std_json_response(data=jsontool.dumps(user_list))
async def post(self): post_dict = self.get_post_body_dict() user_id = post_dict.get(ConstData.user_form, None) passwd = post_dict.get(ConstData.passwd_form, None) if list_have_none_mem(*[user_id, passwd]): return ConstData.msg_args_wrong db = self.get_async_mongo() user_res = await db['g_users'].find_one( { 'user_id': user_id, 'is_del': False }, { '_id': 1, 'passwd': 1, 'salt': 1, 'is_lock': 1 }) if not user_res: return ConstData.msg_fail try: if user_res['is_lock'] is True: return ConstData.msg_forbidden except: pass user_pass = user_res['passwd'] user_salt = user_res['salt'] _id = user_res['_id'] md5_password = hashlibmd5with_salt(passwd, user_salt) # auth_res = await User.auth(user_id, passwd) if md5_password == user_pass: # if auth_res: token_res = await self.create_token_session( _id, client_type=ClientTypeDict.browser) data = {"token": token_res['token']} return get_std_json_response(msg="success", data=jsontool.dumps(data)) else: return ConstData.msg_fail
def get(self): print('run app-info:', app_version) mongo_version = get_mongodb_version() pip_list = get_pip_list() python = get_python_version() res = dict( server='tornado', # web服务器 app_version=app_version, # 应用版本 dtlib_version=dtlib.VERSION, # 第三方库dt-lib的版本 req_time=timetool.get_current_time_string(), # 当前查询时间点 timezone=timetool.get_time_zone(), # 当前服务器的时区 mongo_server=mongo_version, # mongo的服务器版本号 python=python, # python版本号 pip_list=pip_list, # 安装的pip_list ) return get_std_json_response( data=jsontool.dumps(res, ensure_ascii=False))
async def get(self): appid = self.get_argument('appid', None) # 应用公钥 shadow_secret = self.get_argument('shadow_secret', None) # 影子私钥 auth_token = self.get_argument('auth_token', None) # 用户授权token if list_have_none_mem(*[appid, shadow_secret, auth_token]): return ConstData.msg_args_wrong auth_token = await ThirdAuthToken.objects.get(token=auth_token) """:type:ThirdAuthToken""" if auth_token is None: return ConstData.msg_none access_token = await AuthAccessToken.objects.get(user=auth_token.user) """:type:AuthAccessToken""" res_data = get_std_json_response( data=jsontool.dumps(access_token.to_dict())) return res_data
async def get(self): project_id = self.get_argument('project_id', None) if project_id is None: return ConstData.msg_args_wrong db = self.get_async_mongo() proj_col = db.test_project project_obj = await proj_col.find_one({'_id': ObjectId(str(project_id))}) organization = project_obj['organization'] app_col = db.test_data_app test_data_app = await app_col.find_one({'organization': organization}) data = dict( project_name=project_obj['project_name'], project_id=project_obj['_id'], app_id=test_data_app['app_id'], app_key=test_data_app['app_key'] ) res_str = get_std_json_response(code=200, data=jsontool.dumps(data)) return res_str
def get_std_json_res(**kwargs): """ 获取标准的json返回值,以此处为标准,传入的参数: - code:整数 - msg:字符串提示 - data:传进来的是dict,不是str类型 :return: """ code = kwargs.get('code', 200) msg = kwargs.get('msg', '') data = kwargs.get('data', '') if list_have_none_mem(*[code, msg, data]) is True: raise ValueError res_dict = dict(code=code, msg=msg, data=data) return jsontool.dumps(res_dict, ensure_ascii=False)
async def wrapper(self, *args, **kwargs): # callback = self.get_argument('callback', None) page_idx = self.get_argument('page_idx', '1') # 页面索引号-var page_cap = self.get_argument('page_cap', '15') # 一页的记录容量-var page_idx = int(page_idx) page_cap = int(page_cap) my_paginator_data = await method(self, *args, **kwargs) if my_paginator_data is None: rcs_len = 0 my_paginator_data = [] else: rcs_len = len(my_paginator_data) # 记录总长度 # 前端分页显示的内容 page_total_cnts = int(math.ceil(rcs_len / page_cap)) # 页面的总数 # 计算分页数据 start_idx = (page_idx - 1) * page_cap # 起始记录 end_idx = start_idx + page_cap if end_idx > rcs_len: end_idx = rcs_len # 防止溢出 page_data = my_paginator_data[start_idx:end_idx] # 取出分页的数据 page_data_json_list = [] for item in page_data: page_data_json_list.append(item) res_dict = dict(page_total_cnts=page_total_cnts, page_idx=page_idx, page_cap=page_cap, page_data=page_data_json_list, count=rcs_len) res_str = jsontool.dumps(res_dict, ensure_ascii=False) return res_str
async def get(self): uuid = self.get_argument('uuid', None) confirm = self.get_argument('confirm', None) if list_have_none_mem(*[ uuid, ]): return ConstData.msg_args_wrong current_auth_token = await MobileAuthPcToken.objects.get(token=uuid) """:type:MobileAuthPcToken""" if current_auth_token is None: return ConstData.msg_forbidden user = self.get_current_session_user() # 当前手机登录的用户 if confirm is None: current_auth_token.status = QrAuthStatusCode.wait elif confirm == '1': # 将状态修改为 确认授权态,授权,用户签名 current_auth_token.user = user current_auth_token.user_id = user.user_id current_auth_token.u_name = user.nickname current_auth_token.status = QrAuthStatusCode.confirm # 然后创建auth_token,这个会告诉PC端此用户已经登录,然后把此session传给PC端 # 直接创建webtoken,暂先不客auth_token await self.create_token_session(user, WebToken, client_type=ClientTypeDict.browser ) # 创建一个PC端的access_token else: # 将状态修改为 取消授权态 current_auth_token.status = QrAuthStatusCode.cancel current_auth_token = await current_auth_token.save() return get_std_json_response( data=jsontool.dumps(current_auth_token.to_dict()))
async def get(self): """ 要做鉴权和区分 :return: """ data_id = self.get_argument('id', None) if list_have_none_mem(*[data_id]): return ConstData.msg_args_wrong mongo_coon = self.get_async_mongo() mycol = mongo_coon['unit_test_data'] user_org = await self.get_organization() """:type:Organization""" msg_details = await mycol.find_one({ "organization": ObjectId(user_org), "_id": ObjectId(data_id) }) return get_std_json_response( data=jsontool.dumps(msg_details, ensure_ascii=False))