mirror of
https://github.com/apache/superset.git
synced 2026-04-24 02:25:13 +00:00
feat(dashboard): make permalink deterministic (#20632)
This commit is contained in:
@@ -22,13 +22,19 @@ from superset.dashboards.dao import DashboardDAO
|
||||
from superset.dashboards.permalink.commands.base import BaseDashboardPermalinkCommand
|
||||
from superset.dashboards.permalink.exceptions import DashboardPermalinkCreateFailedError
|
||||
from superset.dashboards.permalink.types import DashboardPermalinkState
|
||||
from superset.key_value.commands.create import CreateKeyValueCommand
|
||||
from superset.key_value.utils import encode_permalink_key
|
||||
from superset.key_value.commands.upsert import UpsertKeyValueCommand
|
||||
from superset.key_value.utils import encode_permalink_key, get_deterministic_uuid
|
||||
from superset.utils.core import get_user_id
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class CreateDashboardPermalinkCommand(BaseDashboardPermalinkCommand):
|
||||
"""
|
||||
Get or create a permalink key for the given dashboard in certain state.
|
||||
Will reuse the key for the same user and dashboard state.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
dashboard_id: str,
|
||||
@@ -45,12 +51,13 @@ class CreateDashboardPermalinkCommand(BaseDashboardPermalinkCommand):
|
||||
"dashboardId": self.dashboard_id,
|
||||
"state": self.state,
|
||||
}
|
||||
key = CreateKeyValueCommand(
|
||||
user_id = get_user_id()
|
||||
key = UpsertKeyValueCommand(
|
||||
resource=self.resource,
|
||||
key=get_deterministic_uuid(self.salt, (user_id, value)),
|
||||
value=value,
|
||||
).run()
|
||||
if key.id is None:
|
||||
raise DashboardPermalinkCreateFailedError("Unexpected missing key id")
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user