Example #1
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
Example #2
0
    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