Esempio n. 1
0
    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
Esempio n. 2
0
    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
Esempio n. 3
0
    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