def add_manager(self): user_name = self.get_argument("user_name", "") telephone = self.get_argument("telephone", "") roles = self.get_arguments("role[]") # data = json.loads(self.request.body) # user_name = data.get("user_name","") # telephone = data.get("telephone","") # roles = data.get("role",[]) self.logger.info("username:"******" telephone:" + telephone + " role:" + ','.join(roles)) if user_name == '' or telephone == '' or roles == []: self.set_status(400) return {"result": False, 'msg': err_msgs['PARAMS_MISSING']} match = False try: token = self.request.headers.get("user_token", None) redis = RedisBase() token_info = redis.get_token_info(token) company_uuid = token_info.get('company_uuid', None) usr_db = UserDao(session=self.session) match, usr_id, user_name = usr_db.insert_user( user_name, telephone, Users.ROLE_MANAGER) #增加用户。 except Exception, e: self.logger.error(traceback.format_exc())
def create_syndicate(self): name = self.get_argument("name","") desc = self.get_argument("desc","") uuid = self.get_argument("uuid","") user_name = self.get_argument("user_name","") telephone = self.get_argument("telephone","") self.logger.info("name:"+name+" desc:"+desc+" user_name:"+user_name+" telephone:"+telephone) if name == "" or user_name == "" or telephone == "" or uuid == "": self.set_status(400) return {"result":False,'msg':err_msgs['PARAMS_MISSING']} usr_db = UserDao(session= self.session) # 一个超级运营员只允许管理一个集团 if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR): result = { 'result': False, 'msg': err_msgs['ROLE_SUP_MGR_EXIST'] } self.set_status(400) return result match, usr_id, user_name = usr_db.insert_user(user_name,telephone, Users.ROLE_SUP_MGR) if not match: result = { 'result': False, 'msg': err_msgs['TEL_NAME_NOT_MATCH'], 'name': user_name } self.set_status(400) return result token = self.request.headers.get("user_token",None) redis = RedisBase() token_info = redis.get_token_info(token) user_id = token_info['uuid'] com_db = CompanyDao(session=self.session) # 当uuid已存在时插入失败,返回推荐uuid if not com_db.insert_company(name,desc,None,user_id,Company.NO_PARENT,uuid,None): result = { 'result': False, 'msg': err_msgs['COM_UUID_EXIST'], 'recommendation': self.build_company_uuid(uuid) } self.set_status(400) return result usr_rle_db = UserConfDao(session=self.session) usr_rle_db.insert_role(usr_id,uuid,UserConf.SUB_ROLE_SUP_MGR,UserConf.TYPE_ROLE_SUPMGR) # 日志 self.log_user_action(token_info.get("uuid"),"create_syndicate",uuid) result = { 'result': True } return result
def __add_manager_v2(self, user_name, telephone, roles, syndicate_uuid): ''' 增加用户的内核操作。 :param user_name: :param telephone: :param roles: [dict] 结构为{"company_uuid":[role1,role2],} :return: ''' try: user_db = UserDao(session=self.session) match, user_id, user_name_new = user_db.insert_user( user_name, telephone, Users.ROLE_MANAGER) #增加用户。 # 如果是更新则更新用户 if not match and user_id: user_db.update_user(user_id, user_name, telephone) #获取当前集团的所有公司 com_db = CompanyDao(session=self.session) company_list = com_db.get_companys(syndicate_uuid) cmpy_dict = { com_item['uuid']: com_item['name'] for com_item in company_list } company_ids = cmpy_dict.keys() #删除用户的原来角色配置。 usr_rfg_db = UserConfDao(session=self.session) usr_rfg_db.delete_manager_by_user_and_companys( user_id, company_ids) if (roles is not None): #插入新的角色配置。 usr_rfg_db.insert_manager_roles(user_id, roles) # 通知该用户,其已经发生变化。 redis = RedisBase() redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_MANAGER) except Exception, e: self.logger.error(traceback.format_exc())
def add_supmanager(self): user_name = self.get_argument("user_name", "") telephone = self.get_argument("telephone", "") syndicate = self.get_argument("syndicate", "") self.logger.info("username:"******" telephone:" + telephone + " syndicate:" + syndicate) if user_name == '' or telephone == '' or syndicate == '': self.set_status(400) return {"result": False, 'msg': err_msgs['PARAMS_MISSING']} usr_db = UserDao(session=self.session) # 一个超级运营员只允许管理一个集团 if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_SUP_MGR): result = {'result': False, 'msg': err_msgs['ROLE_SUP_MGR_EXIST']} self.set_status(400) return result match, usr_id, user_name = usr_db.insert_user(user_name, telephone, Users.ROLE_SUP_MGR) if not match: result = { 'result': False, 'msg': err_msgs['TEL_NAME_NOT_MATCH'], 'name': user_name } self.set_status(400) return result usr_rle_db = UserConfDao(session=self.session) usr_rle_db.insert_role(usr_id, syndicate, UserConf.SUB_ROLE_SUP_MGR, UserConf.TYPE_ROLE_SUPMGR) # 日志 self.log_user_action(self.get_token().get("uuid"), "add_supmgr", usr_id) result = {'result': True, 'user_id': usr_id} return result
def add_admin(self): user_name = self.get_argument("user_name", "") telephone = self.get_argument("telephone", "") roles = self.get_arguments("role[]") if user_name == '' or telephone == '': self.set_status(400) return {"result": False, 'msg': err_msgs['PARAMS_MISSING']} usr_db = UserDao(session=self.session) # 一个手机号只能存在一个管理员角色 if usr_db.exist_role_group_by_tel(telephone, Users.ROLE_ADMIN): result = {'result': False, 'msg': err_msgs['ROLE_ADMIN_EXIST']} self.set_status(400) return result match, usr_id, user_name = usr_db.insert_user(user_name, telephone, Users.ROLE_ADMIN) if not match: result = { 'result': False, 'msg': err_msgs['TEL_NAME_NOT_MATCH'], 'name': user_name } self.set_status(400) return result usr_rle_db = UserConfDao(session=self.session) for role in roles: usr_rle_db.insert_role(usr_id, UserConf.ACC_COM_ID, role, UserConf.TYPE_ROLE_ADMIN) # 日志 self.log_user_action(self.get_token().get("uuid"), "add_admin", usr_id) result = {'result': True, 'user_id': usr_id} return result
def test_insert_user(self): usr_db = UserDao(session=self.session) print usr_db.insert_user(u"小gg", "133132132132", Users.ROLE_ADMIN)
def add_viewer(self): user_name = self.get_argument("user_name", "") telephone = self.get_argument("telephone", "") role = self.get_argument("role", "") qq = self.get_argument("qq", "") weixin = self.get_argument("weixin", "") weibo = self.get_argument("weibo", "") self.logger.info("username:"******" telephone:" + telephone + " roles:" + role + " qq:" + qq + " weixin:" + weixin + " weibo:" + weibo) if user_name == "" or telephone == "" or role == "": 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) company_uuid = token_info['company_uuid'] usr_db = UserDao(session=self.session) match, usr_id, user_name = usr_db.insert_user( user_name, telephone, Users.ROLE_VIEWER) #增加用户。 usr_rle_db = UserConfDao(session=self.session) if usr_rle_db.viewer_is_exist(usr_id, company_uuid): # 判断当前用户在该公司是否存在观察者角色 result = {'result': False, 'msg': err_msgs['VIEW_EXIST']} self.set_status(400) return result if not match: result = { 'result': False, 'msg': err_msgs['TEL_NAME_NOT_MATCH'], 'name': user_name } self.set_status(400) return result usr_rle_db.insert_role(user_id=usr_id, company_uuid=company_uuid, role=role, role_type=UserConf.TYPE_ROLE_VIEWER) if qq != '': usr_rle_db.insert_account(user_id=usr_id, type=UserConf.TYPE_QQ, account=qq) if weixin != '': usr_rle_db.insert_account(user_id=usr_id, type=UserConf.TYPE_WX, account=weixin) if weibo != '': usr_rle_db.insert_account(user_id=usr_id, type=UserConf.TYPE_WB, account=weibo) # 通知该用户,其已经发生变化。 redis = RedisBase() redis.user_change(usr_id, CODE_USER_MODIFIED, Users.ROLE_VIEWER) # 日志 self.log_user_action(token_info.get("uuid"), "add_viewer", usr_id) result = {'result': True, 'user_id': usr_id} return result