def run(self) -> str: self.validate() try: d_id, d_type = self.datasource.split("__") datasource_id = int(d_id) datasource_type = DatasourceType(d_type) check_chart_access(datasource_id, self.chart_id, datasource_type) value = { "chartId": self.chart_id, "datasourceId": datasource_id, "datasourceType": datasource_type, "datasource": self.datasource, "state": self.state, } command = CreateKeyValueCommand( resource=self.resource, value=value, ) key = command.run() if key.id is None: raise ExplorePermalinkCreateFailedError( "Unexpected missing key id") return encode_permalink_key(key=key.id, salt=self.salt) except SQLAlchemyError as ex: logger.exception("Error running create command") raise ExplorePermalinkCreateFailedError() from ex
def test_get_missing_chart(test_client, login_as_admin, chart, permalink_salt: str) -> None: from superset.key_value.models import KeyValueEntry chart_id = 1234 entry = KeyValueEntry( resource=KeyValueResource.EXPLORE_PERMALINK, value=pickle.dumps({ "chartId": chart_id, "datasourceId": chart.datasource.id, "datasourceType": DatasourceType.TABLE, "formData": { "slice_id": chart_id, "datasource": f"{chart.datasource.id}__{chart.datasource.type}", }, }), ) db.session.add(entry) db.session.commit() key = encode_permalink_key(entry.id, permalink_salt) resp = test_client.get(f"api/v1/explore/permalink/{key}") assert resp.status_code == 404 db.session.delete(entry) db.session.commit()
def run(self) -> str: self.validate() try: DashboardDAO.get_by_id_or_slug(self.dashboard_id) value = { "dashboardId": self.dashboard_id, "state": self.state, } user_id = get_user_id() key = UpsertKeyValueCommand( resource=self.resource, key=get_deterministic_uuid(self.salt, (user_id, value)), value=value, ).run() assert key.id # for type checks return encode_permalink_key(key=key.id, salt=self.salt) except SQLAlchemyError as ex: logger.exception("Error running create command") raise DashboardPermalinkCreateFailedError() from ex
def run(self) -> str: self.validate() try: DashboardDAO.get_by_id_or_slug(self.dashboard_id) value = { "dashboardId": self.dashboard_id, "state": self.state, } key = CreateKeyValueCommand( actor=self.actor, resource=self.resource, value=value, ).run() if key.id is None: raise DashboardPermalinkCreateFailedError("Unexpected missing key id") return encode_permalink_key(key=key.id, salt=self.salt) except SQLAlchemyError as ex: logger.exception("Error running create command") raise DashboardPermalinkCreateFailedError() from ex
def test_encode_permalink_id_valid() -> None: from superset.key_value.utils import encode_permalink_key salt = "abc" assert encode_permalink_key(1, salt) == "AyBn4lm9qG8"