def create_company(self): name = self.get_argument("name","") desc = self.get_argument("desc","") uuid = self.get_argument("uuid","").lower() prop = self.get_argument("property","") self.logger.info("name:"+name+" desc:"+desc) if name == "" or uuid == "": self.set_status(400) return {"result":False,'msg':err_msgs['PARAMS_MISSING']} token = self.request.headers.get("user_token",None) redis = RedisBase() token_info = redis.get_token_info(token) user_id = token_info['uuid'] parent_uuid = token_info['syndicate_uuid'] com_db = CompanyDao(session=self.session) es_index = self.build_es_index(parent_uuid,uuid) # 当uuid已存在时添加失败,返回推荐uuid if not com_db.insert_company(name,desc,prop,user_id,parent_uuid,uuid,es_index): result = { 'result': False, 'msg': err_msgs['COM_UUID_EXIST'], 'recommendation': self.build_company_uuid(uuid) } self.set_status(400) return result # 在es中创建公司索引,当公司索引创建失败时删除公司返回错误信息 if not EsBase().create_index(es_index): com_db.delete_company(uuid) result = { 'result': False, 'msg': err_msgs['INDEX_CREATE_ERR'] } self.set_status(400) return result # 在grout中设置公司的配置信息,设置失败删除公司和es中的索引,返回错误信息 if not self.post_company_grout(uuid,es_index): com_db.delete_company(uuid) EsBase().delete_index(es_index) result = { 'result': False, 'msg': err_msgs['COM_CONF_ERR'] } self.set_status(400) return result # 设置公司的关注媒体类型 self.set_com_media(uuid) self.log_user_action(self.get_token().get("uuid"),"create_company","-") result = { 'result': True } return result
def delete_syndicate(self,uuid): self.logger.info("uuid:"+uuid) com_db = CompanyDao(session=self.session) if com_db.delete_company(uuid): redis = RedisBase() # 改变当前登录超级运营员的token状态 tokens = redis.get_all_tokens() for r_token in tokens: t_info = json.loads(redis.get_value(r_token)) if t_info.get('syndicate_uuid') == uuid and t_info.get('role_group') == Users.ROLE_SUP_MGR: t_info['status'] = { 'code': CODE_COM_MODIFIED, 'msg': token_status[CODE_COM_MODIFIED]['msg'] } redis.set_value(r_token,json.dumps(t_info)) redis.expire(r_token,setting.KICKED_EXPIRE_TIME) # 删除其他表里该集团超级管理员的相关信息 user_db = UserDao(session=self.session) user_status_db = UserLastStatusDao(session=self.session) user_conf_db = UserConfDao(session=self.session) supers = user_conf_db.get_super_by_synid(uuid) for super in supers: # 改变当前登录的超级运营员的状态 user_status_db.del_status(super.user_id, Users.ROLE_SUP_MGR) user_conf_db.delete_user_by_usrid_and_type(super.user_id, UserConf.TYPE_ROLE_SUPMGR) user_db.delete_user(super.user_id, Users.ROLE_SUP_MGR) # 日志 self.log_user_action(self.get_token().get("uuid"),"delete_syndicate",uuid) return {'result': True} # 集团下还有公司删除失败 else: result = { 'result': False, 'msg': err_msgs['HAS_COMS'] } self.set_status(400) return result
def delete_company(self,uuid): self.logger.info("uuid:"+uuid) token = self.request.headers.get("user_token",None) redis = RedisBase() token_info = redis.get_token_info(token) usr_id = token_info['uuid'] company_uuid = token_info.get('company_uuid') parent_uuid = token_info['syndicate_uuid'] # 获取该公司下的所有运营员 user_conf_db = UserConfDao(session=self.session) mgrs = user_conf_db.get_managers_by_company_uuid(uuid) views = user_conf_db.get_viewers_by_company_uuid(uuid) com_db = CompanyDao(session=self.session) usr_status_db = UserLastStatusDao(session=self.session) if com_db.delete_company(uuid): # 删除该公司下的运营员 user_conf_db.delete_company_users(uuid) usr_db = UserDao(session=self.session) # 遍历该公司下的运营员,如果在其他公司不存在角色在用户表中删除该运营员 for mgr in mgrs: mgr_id = mgr['user_id'] if not user_conf_db.has_role(mgr_id,UserConf.TYPE_ROLE_MGR): usr_db.delete_user(mgr_id,Users.ROLE_MANAGER) usr_status_db.del_status(mgr_id,Users.ROLE_MANAGER) for view in views: view_id = view['user_id'] if not user_conf_db.has_role(view_id,UserConf.TYPE_ROLE_VIEWER): user_conf_db.delete_account(view_id) usr_db.delete_user(view_id,Users.ROLE_VIEWER) # 删除ES中的公司索引 es_index = self.build_es_index(parent_uuid,uuid) EsBase().delete_index(es_index) # 在grout中删除公司 self.delete_company_grout(uuid) # 删除公司时发送消息到频道中 redis.del_company(usr_id,uuid) # 查询token,更改状态 tokens = redis.get_all_tokens() for r_token in tokens: t_info = json.loads(redis.get_value(r_token)) # 将当前已登录用户com_uuid为被删除公司的用户token状态重置 if t_info.get('company_uuid') == uuid and t_info.get('uuid') != usr_id: t_info['status'] = { 'code': CODE_COM_MODIFIED, 'msg': token_status[CODE_COM_MODIFIED]['msg'] } redis.set_value(r_token,json.dumps(t_info)) redis.expire(r_token,setting.KICKED_EXPIRE_TIME) platform = usr_status_db.get_from_by_token(token) # 当超级运营员把当前选择公司删除,返回301 if uuid == company_uuid: kwargs = { "update_at": token_info.get("update_at"), } info = json.dumps(self.gen_token_info(usr_id, Users.ROLE_SUP_MGR, platform,**kwargs)) redis.set_token(token, info) self.set_status(301) # 日志 self.log_user_action(token_info.get("uuid"),"delete_company",uuid) result = { 'result': True } # 只有删除集团并且集团下还有公司才会删除失败 else: result = { 'result': False, 'msg': err_msgs['HAS_COMS'] } self.set_status(400) return result