def _create(self): _redis = self.application.redis _request = json.loads(self.request.body) _user_uuid = _request.get("user_uuid") _app_name = _request.get("app_name") if _user_uuid == None or _app_name == None: self.setErrorCode(API_ERR.NO_PARA) return _app_key = str(uuid.uuid1()) _app_secret = str(uuid.uuid1()) _app_uuid = str(uuid.uuid1()) _user_email = _redis.hget( DeviceUser.__tablename__ + ".uuid." + _user_uuid, "user_email") _company_name = _redis.hget( DeviceUser.__tablename__ + ".uuid." + _user_uuid, "user_company") _app_values = { "uuid": _app_uuid, "user_uuid": _user_uuid, "app_name": _app_name, "app_key": _app_key, "app_secret": _app_secret, "app_billing_email": _user_email, "offline_message": PPCOM_OFFLINE["zh_cn"], "welcome_message": PPCOM_WELCOME["zh_cn"], "app_route_policy": APP_POLICY.BROADCAST, "show_ppcom_hover": SHOW_PPCOM_HOVER.NEVER, "ppcom_launcher_style": PPCOM_LAUNCHER_STYLE.DEFAULT, } if _company_name != None and len(_company_name) > 0: _app_values["company_name"] = _company_name _row = AppInfo(**_app_values) _row.async_add() _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _data = { "uuid": _data_uuid, "user_uuid": _user_uuid, "app_uuid": _app_uuid, "is_owner_user": True, "is_service_user": True, "is_distributor_user": True, "is_portal_user": False } _row = AppUserData(**_data) _row.async_add() _row.create_redis_keys(_redis) # create api_info self._create_kefu_client_apiinfo(_user_uuid, _app_uuid) self._create_console_client_apiinfo(_user_uuid, _app_uuid) _r = self.getReturnData() _r.update(_app_values) return
def _remove(self): _redis = self.application.redis _app = redis_hash_to_dict(_redis, AppInfo, _app_uuid) if _app == None: self.setErrorCode(API_ERR.NO_APP) return if _app.get("user_uuid") != _user_uuid: self.setErrorCode(API_ERR.NOT_OWNER) return _key = AppUserData.__tablename__ + ".app_uuid." + _app_uuid + ".is_service_user.True" _services = _redis.smembers() _key = AppUserData.__tablename__ + ".app_uuid." + _app_uuid + ".is_service_user.False" _users = _redis.smembers() _pi = _redis.pipeline() _data_key_pre = AppUserData.__tablename__ + ".app_uuid." + _app_uuid for _user_uuid in _sevices: _data_key = _data_key_pre + ".user_uuid." + _user_uuid + ".is_service_user.True" _pi.get(_data_key) _data_uuid_list = _pi.execute() for _i in _data_uuid_list: _row = AppUserData(uuid=_i) _row.async_delete(_redis) _row.delete_redis_keys(_redis) _row = AppInfo(uuid=_app_uuid) _row.async_delete(_redis) _row.delete_redis_keys(_redis) return
def _create_team(self, _request): from ppmessage.db.models import AppInfo _app_name = "PPMessage Lite Test Team" _app_uuid = self._app_uuid _app_key = str(uuid.uuid1()) _app_secret = str(uuid.uuid1()) _row = AppInfo(uuid=_app_uuid, app_name=_app_name, app_key=_app_key, app_secret=_app_secret) _row.create_redis_keys(_redis) _insert_into(_row) return True
def _create_team(self, _request): from ppmessage.db.models import AppInfo _app_name = _request.get("team_name") _app_uuid = self._app_uuid _app_key = str(uuid.uuid1()) _app_secret = str(uuid.uuid1()) _row = AppInfo(uuid=_app_uuid, app_name=_app_name, app_key=_app_key, app_secret=_app_secret) _row.create_redis_keys(self.application.redis) _insert_into(_row) return True
def create_app(_handler, _app_name, _user_uuid): _redis = _handler.application.redis _app_key = str(uuid.uuid1()) _app_secret = str(uuid.uuid1()) _app_uuid = str(uuid.uuid1()) _user_email = _redis.hget(DeviceUser.__tablename__ + ".uuid." + _user_uuid, "user_email") _company_name = _redis.hget( DeviceUser.__tablename__ + ".uuid." + _user_uuid, "user_company") _app_values = { "uuid": _app_uuid, "user_uuid": _user_uuid, "app_name": _app_name, "app_key": _app_key, "app_secret": _app_secret, "app_billing_email": _user_email, "app_route_policy": APP_POLICY.BROADCAST, } if _company_name != None and len(_company_name) > 0: _app_values["company_name"] = _company_name _row = AppInfo(**_app_values) _row.async_add() _row.create_redis_keys(_redis) _data_uuid = str(uuid.uuid1()) _data = { "uuid": _data_uuid, "user_uuid": _user_uuid, "app_uuid": _app_uuid, "is_owner_user": True, "is_service_user": True, "is_distributor_user": True, "is_portal_user": False } _row = AppUserData(**_data) _row.async_add() _row.create_redis_keys(_redis) # create api_info _create_kefu_client_apiinfo(_handler, _user_uuid, _app_uuid) _create_console_client_apiinfo(_handler, _user_uuid, _app_uuid) return _app_values
def _create_bootstrap_first_team(_session, _config): _user_config = _config.get("user") _team_config = _config.get("team") _app = AppInfo( createtime=datetime.datetime.now(), updatetime=datetime.datetime.now(), uuid=str(uuid.uuid1()), app_key=_encode(str(uuid.uuid1())), app_secret=_encode(str(uuid.uuid1())), user_uuid=_user_config.get("user_uuid"), app_name=_team_config.get("app_name"), company_name=_team_config.get("company_name") ) _session.add(_app) _session.commit() _team_config["app_uuid"] = _app.uuid return _config