def run(self) -> str: self.validate() try: datasource_id = self._cmd_params.datasource_id datasource_type = self._cmd_params.datasource_type chart_id = self._cmd_params.chart_id tab_id = self._cmd_params.tab_id form_data = self._cmd_params.form_data check_access(datasource_id, chart_id, datasource_type) contextual_key = cache_key(session.get("_id"), tab_id, datasource_id, chart_id, datasource_type) key = cache_manager.explore_form_data_cache.get(contextual_key) if not key or not tab_id: key = random_key() if form_data: state: TemporaryExploreState = { "owner": get_user_id(), "datasource_id": datasource_id, "datasource_type": DatasourceType(datasource_type), "chart_id": chart_id, "form_data": form_data, } cache_manager.explore_form_data_cache.set(key, state) cache_manager.explore_form_data_cache.set(contextual_key, key) return key except SQLAlchemyError as ex: logger.exception("Error running create command") raise TemporaryCacheCreateFailedError() from ex
def run(self) -> Optional[str]: try: actor = self._cmd_params.actor key = self._cmd_params.key state: TemporaryExploreState = cache_manager.explore_form_data_cache.get( key) if state: check_access(state["dataset_id"], state["chart_id"], actor) if self._refresh_timeout: cache_manager.explore_form_data_cache.set(key, state) return state["form_data"] return None except SQLAlchemyError as ex: logger.exception("Error running get command") raise TemporaryCacheGetFailedError() from ex
def run(self) -> bool: try: actor = self._cmd_params.actor key = self._cmd_params.key state: TemporaryExploreState = cache_manager.explore_form_data_cache.get( key) if state: dataset_id = state["dataset_id"] chart_id = state["chart_id"] check_access(dataset_id, chart_id, actor) if state["owner"] != get_owner(actor): raise TemporaryCacheAccessDeniedError() tab_id = self._cmd_params.tab_id contextual_key = cache_key(session.get("_id"), tab_id, dataset_id, chart_id) cache_manager.explore_form_data_cache.delete(contextual_key) return cache_manager.explore_form_data_cache.delete(key) return False except SQLAlchemyError as ex: logger.exception("Error running delete command") raise TemporaryCacheDeleteFailedError() from ex
def run(self) -> Optional[str]: self.validate() try: datasource_id = self._cmd_params.datasource_id chart_id = self._cmd_params.chart_id datasource_type = self._cmd_params.datasource_type key = self._cmd_params.key form_data = self._cmd_params.form_data check_access(datasource_id, chart_id, datasource_type) state: TemporaryExploreState = cache_manager.explore_form_data_cache.get( key) owner = get_user_id() if state and form_data: if state["owner"] != owner: raise TemporaryCacheAccessDeniedError() # Generate a new key if tab_id changes or equals 0 tab_id = self._cmd_params.tab_id contextual_key = cache_key(session.get("_id"), tab_id, datasource_id, chart_id, datasource_type) key = cache_manager.explore_form_data_cache.get(contextual_key) if not key or not tab_id: key = random_key() cache_manager.explore_form_data_cache.set( contextual_key, key) new_state: TemporaryExploreState = { "owner": owner, "datasource_id": datasource_id, "datasource_type": DatasourceType(datasource_type), "chart_id": chart_id, "form_data": form_data, } cache_manager.explore_form_data_cache.set(key, new_state) return key except SQLAlchemyError as ex: logger.exception("Error running update command") raise TemporaryCacheUpdateFailedError() from ex
def run(self) -> bool: try: key = self._cmd_params.key state: TemporaryExploreState = cache_manager.explore_form_data_cache.get( key) if state: datasource_id: int = state["datasource_id"] chart_id: Optional[int] = state["chart_id"] datasource_type = DatasourceType(state["datasource_type"]) check_access(datasource_id, chart_id, datasource_type) if state["owner"] != get_user_id(): raise TemporaryCacheAccessDeniedError() tab_id = self._cmd_params.tab_id contextual_key = cache_key(session.get("_id"), tab_id, datasource_id, chart_id, datasource_type) cache_manager.explore_form_data_cache.delete(contextual_key) return cache_manager.explore_form_data_cache.delete(key) return False except SQLAlchemyError as ex: logger.exception("Error running delete command") raise TemporaryCacheDeleteFailedError() from ex