feat: introduce hashids permalink keys (#19324)

* feat: introduce hashids permalink keys

* implement dashboard permalinks

* remove shorturl notice from UPDATING.md

* lint

* fix test

* introduce KeyValueResource

* make filterState optional

* fix test

* fix resource names

(cherry picked from commit f4b71abb22)
This commit is contained in:
Ville Brofeldt
2022-03-24 21:53:09 +02:00
committed by Ville Brofeldt
parent 18f82411c9
commit a6a2def6d3
39 changed files with 344 additions and 367 deletions

View File

@@ -16,7 +16,7 @@
# under the License.
import logging
from flask import current_app, g, request, Response
from flask import g, request, Response
from flask_appbuilder.api import BaseApi, expose, protect, safe
from marshmallow import ValidationError
@@ -98,12 +98,9 @@ class ExplorePermalinkRestApi(BaseApi):
500:
$ref: '#/components/responses/500'
"""
key_type = current_app.config["PERMALINK_KEY_TYPE"]
try:
state = self.add_model_schema.load(request.json)
key = CreateExplorePermalinkCommand(
actor=g.user, state=state, key_type=key_type,
).run()
key = CreateExplorePermalinkCommand(actor=g.user, state=state).run()
http_origin = request.headers.environ.get("HTTP_ORIGIN")
url = f"{http_origin}/superset/explore/p/{key}/"
return self.response(201, key=key, url=url)
@@ -159,10 +156,7 @@ class ExplorePermalinkRestApi(BaseApi):
$ref: '#/components/responses/500'
"""
try:
key_type = current_app.config["PERMALINK_KEY_TYPE"]
value = GetExplorePermalinkCommand(
actor=g.user, key=key, key_type=key_type
).run()
value = GetExplorePermalinkCommand(actor=g.user, key=key).run()
if not value:
return self.response_404()
return self.response(200, **value)