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 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 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 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, *args, **kwargs): # todo: judge is admin post_json = self.get_post_body_dict() _id = post_json.get('_id', None) _id = ObjectId(_id) if list_have_none_mem(*[_id]): return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['g_users'] res = await mycol.find_one({'_id': _id}) if res: if res['is_del'] is True or res['user_id'] == 'admin': return ConstData.msg_args_wrong data = dict(is_del=True) # todo: set del_time await mycol.update({'_id': ObjectId(_id)}, {'$set': data}, upsert=False) # update user_org_rel user_org_col = mongo_conn['user_org_rel'] res = await user_org_col.find_one({'user': _id}) if res: data = dict(is_del=True) await user_org_col.update({'user': _id}, {'$set': data}, upsert=False) return ConstData.msg_succeed
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 post(self, *args, **kwargs): post_json = self.get_post_body_dict() user_id = post_json.get('user_id', None) password = post_json.get('password', None) nickname = post_json.get('nickname', "默认昵称") if list_have_none_mem(*[user_id, password]) or user_id == 'admin': return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['g_users'] res = await mycol.find_one({'user_id': user_id}) _id = None if res: if res['is_del'] is False: return ConstData.msg_exist _id = res['_id'] rand_salt = get_rand_salt() data = dict( nickname=nickname, user_id=user_id, passwd=hashlibmd5with_salt(password, rand_salt), salt=rand_salt, ) data = wrap_default_rc_tag(data) # 加上默认的标签 if _id: await mycol.update({'_id': _id}, {'$set': data}, upsert=True) else: _id = await mycol.insert(data) # todo: select orgnization user_org_col = mongo_conn['user_org_rel'] res = await user_org_col.find_one({'user': _id}) data = dict( user_name=nickname, user=_id, # organization=org_id, is_active=True, # org_name=org_name, is_default=False, is_owner=False, is_current=True) if res is None: org_col = mongo_conn['organization'] res = await org_col.find_one({ 'is_del': False, }) org_name = res['name'] org_id = res['_id'] else: org_name = res['org_name'] org_id = res['organization'] data['org_name'] = org_name data['organization'] = org_id data = wrap_default_rc_tag(data) # 加上默认的标签 await user_org_col.update({'user': _id}, {'$set': data}, upsert=True) return ConstData.msg_succeed
async def post(self, *args, **kwargs): post_json = self.get_post_body_dict() content_id = post_json.get('content_id', None) pro_id = post_json.get('pro_id', "5a7fb0cd47de9d5cf3d13a44") group = post_json.get('group', "test") time_stamp = post_json.get('date_time', None) content = post_json.get('content', None) if list_have_none_mem(*[pro_id, group, time_stamp, content]): return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['dashboard_content'] timeArray = time.localtime(int(time_stamp) / 1000.0) date_time = time.strftime("%Y-%m-%d %H:%M:%S", timeArray) data = dict( pro_id=ObjectId(pro_id), group=group, date_time=date_time, content=content, ) data = wrap_default_rc_tag(data) # 加上默认的标签 if content_id: await mycol.update({'_id': ObjectId(content_id)}, {'$set': data}, upsert=True) return ConstData.msg_succeed else: _id = await mycol.insert(data) msg_succeed = '{"code":%s,"msg":"%s","data":{"_id": "%s"}}' % ( ResCode.ok, "success", _id) return msg_succeed
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 post(self, *args, **kwargs): post_json = self.get_post_body_dict() content_id = post_json.get('content_id', None) # pro_id = self.get_argument('pro_id', "5a7fb0cd47de9d5cf3d13a44") if list_have_none_mem(*[content_id]): return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['dashboard_content'] mycol.update({'_id': ObjectId(content_id)}, {'$set': {'is_del': True}}, upsert=False) return ConstData.msg_succeed
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 post(self, *args, **kwargs): post_json = self.get_post_body_dict() tv = post_json.get('tv', None) pro_id = post_json.get('pro_id', None) if list_have_none_mem(*[tv, pro_id]): return ConstData.msg_args_wrong if not isinstance(tv, bool): return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['test_project'] mycol.update({'_id': ObjectId(pro_id)}, {'$set': { 'tv': tv }}, upsert=False) return ConstData.msg_succeed
async def set_default_tag(self, **kwargs): """ 设置默认的标记 :param kwargs: :return: """ client_type = kwargs.get('client_type', None) http_req = kwargs.get('http_req', None) if list_have_none_mem(*[client_type, http_req]): return None await self.set_org_user_tag(http_req=http_req) self.set_client_type_tag(client_type=client_type) # super(AuthApp, self).set_default_rc_tag() return True
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 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
async def post(self, *args, **kwargs): post_json = self.get_post_body_dict() tv_tags = post_json.get('tv_tags', None) pro_id = post_json.get('pro_id', None) if list_have_none_mem(*[tv_tags, pro_id]): return ConstData.msg_args_wrong if not isinstance(tv_tags, list): return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['test_project'] project = await mycol.find_one({'_id': ObjectId(pro_id)}, {'tags': 1}) if 'tags' in project: tags = project['tags'] if set(tv_tags).issubset(set(tags)) is False: return ConstData.msg_args_wrong await mycol.update({'_id': ObjectId(pro_id)}, {'$set': {'tv_tags': tv_tags}}, upsert=False) return ConstData.msg_succeed
async def create_anonymous_token(self, cls, **kwargs): """ 创建匿名token,主要用途: 1. PC上生成二维码,给手机上扫码认证 :param cls: :param kwargs: :return: """ appid = kwargs.get('appid', None) client_type = kwargs.get('client_type', None) # 默认的是浏览器端 if list_have_none_mem(*[client_type]): return None ip = self.request.remote_ip # referer='' if self.request.headers is None user_agent = self.request.headers['User-Agent'] finger_prt = hashlib.md5(user_agent.encode("utf-8")).hexdigest() # 如果是手机认证PC,则直接创建匿名token my_token = cls( c_type=client_type.value, c_name=client_type.key, appid=appid, ) """:type:BaseToken""" # todo 后续如果把应用的系统做好了,这个地方要做一次数据库IO查询处理的,判断是否存在,防止别人撞库 # 允许有匿名用户的存在,这个时候就表明没有被签名的匿名登录 my_token.set_default_rc_tag() my_token.status = QrAuthStatusCode.timeout my_token.set_uuid_rand_token() my_token.set_uuid_rand_token() # 单点登录,将旧的token给弃用掉 my_token.last_use_time = get_current_utc_time() my_token.ip = ip my_token.user_agent = user_agent my_token.finger_prt = finger_prt my_token = await my_token.save() """:type:UserToken""" return my_token
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
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 get(self): """ 删除分享链接 :return: """ share_id = self.get_argument('share_id', None) if list_have_none_mem(*[share_id]): return ConstData.msg_args_wrong user = self.get_current_session_user() db = self.get_async_mongo() share_proj_col = db.share_project_report res = await share_proj_col.find_one({'_id': ObjectId(str(share_id)), 'owner': ObjectId(user)}) if res is None: return ConstData.msg_forbidden await share_proj_col.remove({'_id': ObjectId(str(share_id)), 'owner': ObjectId(user)}) return ConstData.msg_succeed
async def post(self, *args, **kwargs): # todo: judge is admin post_json = self.get_post_body_dict() _id = post_json.get('_id', None) is_lock = post_json.get('is_lock', None) if list_have_none_mem(*[_id, is_lock]): return ConstData.msg_args_wrong mongo_conn = self.get_async_mongo() mycol = mongo_conn['g_users'] res = await mycol.find_one({'_id': _id}) if res: if res['is_del'] is True or res['user_id'] == 'admin': return ConstData.msg_args_wrong if not isinstance(is_lock, bool): return ConstData.msg_args_wrong data = dict(is_lock=is_lock) await mycol.update({'_id': ObjectId(_id)}, {'$set': data}, upsert=False) return ConstData.msg_succeed
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))
async def post(self): super_token = "3fb13a601c4111e8801f448a5b61a7f0bcb70841" req_dict = self.get_post_body_dict() new_user_pwd = req_dict.get('new_pwd', None) s_token_recv = req_dict.get('s_token', None) if list_have_none_mem(*[s_token_recv, new_user_pwd]): return ConstData.msg_args_wrong if super_token != s_token_recv: return ConstData.msg_forbidden # 做一些密码复杂性和合法性检查 if not user_id_is_legal(new_user_pwd): return ConstData.msg_args_wrong db = self.get_async_mongo() user_col = db.g_users old_session = await user_col.find_one({'user_id': 'admin'}) await user_col.update({'user_id': 'admin'}, { '$set': { 'passwd': hashlibmd5with_salt(new_user_pwd, old_session['salt']) } }) return ConstData.msg_succeed
async def get(self): """ 删除分享链接,直接完全删除,不需要留备份 :return: """ share_id = self.get_argument('share_id', None) if list_have_none_mem(*[share_id]): return ConstData.msg_args_wrong user = self.get_current_session_user() db = self.get_async_mongo() user_col = db.g_users share_col = db.share_test_report user_result = await user_col.find_one({'_id': ObjectId(user)}) res = await share_col.find_one({'_id': ObjectId(str(share_id)), 'owner': user_result['_id']}) """:type:ShareTestReport""" if res is None: return ConstData.msg_forbidden await share_col.remove({'_id': ObjectId(str(share_id)), 'owner': user_result['_id']}) return ConstData.msg_succeed
async def post(self): """ 删除分享链接 :return: """ post_dict = self.get_post_body_dict() share_id = post_dict.get('share_id', None) mark = post_dict.get('mark', None) if list_have_none_mem(*[share_id, mark]): return ConstData.msg_args_wrong user = self.get_current_session_user() db = self.get_async_mongo() user_col = db.g_users share_col = db.share_project_report user_result = await user_col.find_one({'_id': ObjectId(user)}) res = await share_col.find_one({'_id': ObjectId(str(share_id)), 'owner': user_result['_id']}) if res is None: return ConstData.msg_forbidden await share_col.update({'_id': ObjectId(str(share_id)), 'owner': user_result['_id']}, {'$set': {'mark': mark}}) return ConstData.msg_succeed
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 post(self): """ 客户端将整个报告上传到服务器 :return: """ req_dict = self.get_post_body_dict() # 做好字段的检查工作 pro_id = req_dict.get('pro_id', None) failures = req_dict.get('failures', None) errors = req_dict.get('errors', None) details = req_dict.get('details', None) skipped = req_dict.get('skipped', None) pro_version = req_dict.get('pro_version', None) run_time = req_dict.get('run_time', None) total = req_dict.get('total', None) was_successful = req_dict.get('was_successful', None) if list_have_none_mem(*[ pro_id, failures, errors, details, skipped, pro_version, run_time, total, was_successful, ]): return ConstData.msg_args_wrong if len(pro_version) > 32: # 如果版本号长度大于32,比如出现了没有标定版本号的情况 pro_version = '0.0.0.0.0' req_dict['pro_version'] = pro_version db = self.get_async_mongo() proj_col = db.test_project test_data_col = db.unit_test_data # project = await Project.objects.get(id=ObjectId(pro_id)) project = await proj_col.find_one({'_id': ObjectId(pro_id)}) """:type:Project""" app_org = await self.get_organization() """:type:Organization""" # if (project is None) or (project.organization is None): if project is None: return ConstData.msg_forbidden # 权限鉴定,不允许越权访问别人的组织的项目 pro_org_id = project['organization'] if pro_org_id != app_org: return ConstData.msg_forbidden # todo 后续的一些更细节的字段内在的约束检查 req_dict = wrap_project_tag(req_dict, project) # 加上项目标签 req_dict = wrap_default_rc_tag(req_dict) # 加上默认的标签 req_dict = wrap_org_tag(req_dict, str(pro_org_id)) # 加上组织的标签 insert_res = await test_data_col.insert(req_dict) return ConstData.msg_succeed
async def create_token_session(self, user, **kwargs): """ 区别:加入了 平台的描述 创建 或者 刷新 token, 包括各种 ttl_token 现在是进行了扩展了,所以用这种方式, - 允许有匿名的存在 :type self:MyBaseHandler :type cls:UserToken :type user:User :param client_type: 客户端类型 :return: :rtype:UserToken """ client_type = kwargs.get('client_type', None) # 默认的是浏览器端 """:type:ValueDict""" # cls = kwargs.get('token_cls', None) # """:type:UserToken""" if list_have_none_mem(*[client_type]): return None # 读取 mongodb,获取用户对应的 token,单点登录情况下使用 # my_token = await cls.objects.get(user=user, c_type=client_type.value) """:type:WebToken""" ip = self.request.remote_ip user_agent = self.request.headers['User-Agent'] finger_prt = hashlib.md5(user_agent.encode("utf-8")).hexdigest() # # if my_token is None: # 单点登录情况下使用 # my_token = cls( # c_type=client_type.value, # c_name=client_type.key, # ) # """:type:UserToken""" db = self.get_async_mongo() token_col = db['ttl_access_token'] user_col = db['g_users'] user_res = await user_col.find_one({'_id': user}) if not user_res: return None new_token = dict( user=user_res['_id'], # todo: save user_id u_name=user_res['nickname']) # if user is not None: # my_token.user = user.get_id() # my_token.u_name = user.nickname # 允许有匿名用户的存在,这个时候就表明没有被签名的匿名登录 new_token = set_default_rc_tag(new_token) new_token['token'] = randtool.generate_uuid_token() new_token['last_use_time'] = get_current_utc_time() new_token['ip'] = ip new_token['user_agent'] = user_agent new_token['finger_prt'] = finger_prt # my_token = await my_token.save() # 通过save获取的my_token并没有lazy出来,后面赋值的时候会有影响 # """:type:UserToken""" # # my_token = await cls.objects.get(id=my_token.get_id()) # 相当于使用了 loadReference功能 await token_col.insert(new_token) return new_token