def edit_admins(self): user_id = self.get_argument("user_id", "") user_name = self.get_argument("user_name", "") telephone = self.get_argument("telephone", "") roles = self.get_arguments("role[]") self.logger.info("user_id:" + user_id + " username:"******" telephone:" + telephone) if user_id == "" or user_name == "" or telephone == "": self.set_status(400) return {"result": False, 'msg': err_msgs['PARAMS_MISSING']} # 更新User表中的信息 usr_db = UserDao(session=self.session) user_info = usr_db.user(user_id) old_tel = user_info['telephone'] # 当手机号发生改变时判断该手机号是否存在 if old_tel != telephone and usr_db.get_user_id_by_tel(telephone): result = {'result': False, 'msg': err_msgs['TEL_EXIST']} self.set_status(400) return result usr_db.update_user(user_id, user_name, telephone) usr_rle_db = UserConfDao(session=self.session) # 通知该用户,其已经发生变化。 redis = RedisBase() redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_ADMIN) # 删除admin的相关信息 usr_rle_db.delete_company_user(user_id, UserConf.ACC_COM_ID, UserConf.TYPE_ROLE_ADMIN) # 重新插入admin for role in roles: usr_rle_db.insert_role(user_id, UserConf.ACC_COM_ID, role, UserConf.TYPE_ROLE_ADMIN) # 日志 self.log_user_action(self.get_token().get("uuid"), "edit_admin", user_id) result = {'result': True} return result
def delete_manager(self, user_id): self.logger.info("user_id:" + user_id) token = self.request.headers.get("user_token", None) redis = RedisBase() token_info = redis.get_token_info(token) company_uuid = token_info['company_uuid'] usr_rle_db = UserConfDao(session=self.session) usr_rle_db.delete_company_user(user_id, company_uuid, UserConf.TYPE_ROLE_MGR) usr_status_db = UserLastStatusDao(session=self.session) statuses = usr_status_db.get_status_by_userid_and_role_group( user_id, Users.ROLE_MANAGER) for status in statuses: if company_uuid == status.company_uuid and redis.exists_token( status.token): u_token_info = redis.get_token_info(status.token) u_token_info['status'] = { 'code': CODE_USER_DELETED, 'msg': token_status[CODE_USER_DELETED]['msg'] } redis.set_token(status.token, json.dumps(u_token_info), False) has_managers = usr_rle_db.has_role(user_id, UserConf.TYPE_ROLE_MGR) if not has_managers: usr_db = UserDao(session=self.session) usr_db.delete_user(user_id, Users.ROLE_MANAGER) usr_status_db.del_status(user_id, Users.ROLE_MANAGER) # 通知该用户,其已经发生变化。 redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_VIEWER) # 日志 self.log_user_action(token_info.get("uuid"), "delete_manager", user_id) result = {'result': True} return result
def edit_manager(self): user_id = self.get_argument("user_id", "") user_name = self.get_argument("user_name", "") telephone = self.get_argument("telephone", "") roles = self.get_arguments("role[]") # data = json.loads(self.request.body) # user_id = data.get("user_id","") # user_name = data.get("user_name","") # telephone = data.get("telephone","") # roles = data.get("role",[]) self.logger.info("user_id:" + user_id + " username:"******" telephone:" + telephone + " roles:" + ','.join(roles)) if user_id == "" or user_name == "" or telephone == "" or roles == []: 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'] # 更新User表中的信息 usr_db = UserDao(session=self.session) user_info = usr_db.user(user_id) old_tel = user_info['telephone'] # 当手机号发生改变时判断该手机号是否存在 if old_tel != telephone and usr_db.get_user_id_by_tel(telephone): result = {'result': False, 'msg': err_msgs['TEL_EXIST']} self.set_status(400) return result usr_db.update_user(user_id, user_name, telephone) usr_rle_db = UserConfDao(session=self.session) # 通知该用户,其已经发生变化。 redis = RedisBase() redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_MANAGER) # 下面的是东辉的版本 貌似不能用 # 获取用户当前角色判断角色是否发生改变 # roles_old = usr_rle_db.get_spec_roles(user_id,company_uuid,UserConf.TYPE_ROLE_MGR) # if sorted(roles_old) != sorted(roles): # usr_status_db = UserLastStatusDao(session=self.session) # statuses = usr_status_db.get_status_by_userid_and_role_group(user_id,Users.ROLE_MANAGER) # for status in statuses: # if company_uuid==status.company_uuid and redis.exists_token(status.token): # mgr_token_info = redis.get_token_info(status.token) # mgr_token_info['status'] = { # 'code': CODE_USER_MODIFIED, # 'msg': token_status[CODE_USER_MODIFIED]['msg'] # } # redis.set_token(status.token,json.dumps(mgr_token_info),False) # 删除manager的相关信息 usr_rle_db.delete_company_user(user_id, company_uuid, UserConf.TYPE_ROLE_MGR) # 重新插入manager for role in roles: usr_rle_db.insert_role(user_id, company_uuid, role, UserConf.TYPE_ROLE_MGR) # 日志 self.log_user_action(token_info.get("uuid"), "edit_manager", user_id) result = {'result': True} return result
def edit_viewer(self): user_id = self.get_argument("user_id", "") 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("user_id:" + user_id + " username:"******" telephone:" + telephone + " roles:" + role + " qq:" + qq + " weixin:" + weixin + " weibo" + weibo) if user_id == "" or 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'] # 更新User表中的信息 usr_db = UserDao(session=self.session) user_info = usr_db.user(user_id) old_tel = user_info['telephone'] # 当手机号发生改变时判断该手机号是否存在 if old_tel != telephone and usr_db.get_user_id_by_tel(telephone): result = {'result': False, 'msg': err_msgs['TEL_EXIST']} self.set_status(400) return result usr_db.update_user(user_id, user_name, telephone) # 删除user_conf表中对应的角色 usr_rle_db = UserConfDao(session=self.session) usr_rle_db.delete_company_user(user_id, company_uuid, UserConf.TYPE_ROLE_VIEWER) # 插入新的角色 usr_rle_db.insert_role(user_id, company_uuid, role, UserConf.TYPE_ROLE_VIEWER) # 删除账户信息 usr_rle_db.delete_account(user_id) # 插入账户信息 if qq != '': usr_rle_db.insert_account(user_id=user_id, type=UserConf.TYPE_QQ, account=qq) if weixin != '': usr_rle_db.insert_account(user_id=user_id, type=UserConf.TYPE_WX, account=weixin) if weibo != '': usr_rle_db.insert_account(user_id=user_id, type=UserConf.TYPE_WB, account=weibo) # 通知该用户,其已经发生变化。 redis = RedisBase() redis.user_change(user_id, CODE_USER_MODIFIED, Users.ROLE_VIEWER) # 日志 self.log_user_action(token_info.get("uuid"), "edit_viewer", user_id) result = {'result': True} return result