def delete_manager_v2(self, user_id): token_info = self.get_token() # 日志 self.log_user_action(token_info.get("uuid"), "delete_manager_v2", user_id) result = { 'result': True, } if (token_info is not None): syndicate_uuid = token_info.get("syndicate_uuid") #获取当前集团的所有公司 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) #判断此用户是否还有其他的角色,如果没有其他角色就删除此用户。 usr_has_other = usr_rfg_db.has_role(user_id, UserConf.TYPE_ROLE_MGR) if (not usr_has_other): usr_db = UserDao(session=self.session) usr_db.delete_user(user_id, Users.ROLE_MANAGER) # 通知该用户,其已经发生变化。 redis = RedisBase() redis.user_change(user_id, CODE_USER_DELETED, Users.ROLE_MANAGER) else: result = {'result': False, 'msg': err_msgs['No_AUTHENTICATION']} self.set_status(400) return result
def delete_viewer(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) if usr_rle_db.delete_viewer(user_id, company_uuid): usr_db = UserDao(session=self.session) usr_db.delete_user(user_id, Users.ROLE_VIEWER) # 通知该用户,其已经发生变化。 redis.user_change(user_id, CODE_USER_DELETED, Users.ROLE_VIEWER) # 日志 self.log_user_action(token_info.get("uuid"), "delete_viewer", user_id) 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_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 delete_admins(self, user_id): self.logger.info("user_id:" + user_id) usr_rle_db = UserConfDao(session=self.session) admins = usr_rle_db.get_admins() if len(admins) <= 1: result = {'result': False, 'msg': err_msgs['CANT_DEL_LAST_ADMIN']} self.set_status(400) return result usr_rle_db.delete_user_by_usrid_and_type(user_id, UserConf.TYPE_ROLE_ADMIN) redis = RedisBase() usr_status_db = UserLastStatusDao(session=self.session) statuses = usr_status_db.get_status_by_userid_and_role_group( user_id, Users.ROLE_ADMIN) for status in statuses: if 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) usr_status_db.del_status(user_id, Users.ROLE_ADMIN) usr_db = UserDao(session=self.session) usr_db.delete_user(user_id, Users.ROLE_ADMIN) # 日志 self.log_user_action(self.get_token().get("uuid"), "delete_admin", user_id) result = {'result': True} 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