Exemplo n.º 1
0
 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
         actor = self._cmd_params.actor
         form_data = self._cmd_params.form_data
         check_access(datasource_id, chart_id, actor, 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_owner(actor),
                 "datasource_id": datasource_id,
                 "datasource_type": 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
Exemplo n.º 2
0
 def delete(self, cmd_params: CommandParameters) -> bool:
     resource_id = cmd_params.resource_id
     actor = cmd_params.actor
     key = cache_key(resource_id, cmd_params.key)
     check_access(resource_id)
     entry: Entry = cache_manager.filter_state_cache.get(key)
     if entry:
         if entry["owner"] != get_owner(actor):
             raise TemporaryCacheAccessDeniedError()
         tab_id = cmd_params.tab_id
         contextual_key = cache_key(session.get("_id"), tab_id, resource_id)
         cache_manager.filter_state_cache.delete(contextual_key)
         return cache_manager.filter_state_cache.delete(key)
     return False
Exemplo n.º 3
0
 def create(self, cmd_params: CommandParameters) -> str:
     resource_id = cmd_params.resource_id
     actor = cmd_params.actor
     tab_id = cmd_params.tab_id
     contextual_key = cache_key(session.get("_id"), tab_id, resource_id)
     key = cache_manager.filter_state_cache.get(contextual_key)
     if not key or not tab_id:
         key = random_key()
     value = cast(str, cmd_params.value)  # schema ensures that value is not optional
     check_access(resource_id)
     entry: Entry = {"owner": get_owner(actor), "value": value}
     cache_manager.filter_state_cache.set(cache_key(resource_id, key), entry)
     cache_manager.filter_state_cache.set(contextual_key, key)
     return key
Exemplo n.º 4
0
 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
Exemplo n.º 5
0
    def run(self) -> Optional[str]:
        self.validate()
        try:
            dataset_id = self._cmd_params.dataset_id
            chart_id = self._cmd_params.chart_id
            actor = self._cmd_params.actor
            key = self._cmd_params.key
            form_data = self._cmd_params.form_data
            check_access(dataset_id, chart_id, actor)
            state: TemporaryExploreState = cache_manager.explore_form_data_cache.get(
                key)
            owner = get_owner(actor)
            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,
                                           dataset_id, chart_id)
                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,
                    "dataset_id": dataset_id,
                    "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
Exemplo n.º 6
0
    def update(self, cmd_params: CommandParameters) -> Optional[str]:
        resource_id = cmd_params.resource_id
        actor = cmd_params.actor
        key = cmd_params.key
        value = cast(str, cmd_params.value)  # schema ensures that value is not optional
        check_access(resource_id)
        entry: Entry = cache_manager.filter_state_cache.get(cache_key(resource_id, key))
        owner = get_owner(actor)
        if entry:
            if entry["owner"] != owner:
                raise TemporaryCacheAccessDeniedError()

            # Generate a new key if tab_id changes or equals 0
            contextual_key = cache_key(
                session.get("_id"), cmd_params.tab_id, resource_id
            )
            key = cache_manager.filter_state_cache.get(contextual_key)
            if not key or not cmd_params.tab_id:
                key = random_key()
                cache_manager.filter_state_cache.set(contextual_key, key)

            new_entry: Entry = {"owner": owner, "value": value}
            cache_manager.filter_state_cache.set(cache_key(resource_id, key), new_entry)
        return key