Skip to content

Commit

Permalink
fix: Partially reverts #25007 (#25124)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-s-molina authored Aug 31, 2023
1 parent 9df1b26 commit 1144ac1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 2 additions & 0 deletions superset/initialization/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def init_views(self) -> None:
from superset.views.redirects import R
from superset.views.sql_lab.views import (
SavedQueryView,
SavedQueryViewApi,
SqlLab,
TableSchemaView,
TabStateView,
Expand Down Expand Up @@ -312,6 +313,7 @@ def init_views(self) -> None:
appbuilder.add_view_no_menu(R)
appbuilder.add_view_no_menu(ProfileView)
appbuilder.add_view_no_menu(SavedQueryView)
appbuilder.add_view_no_menu(SavedQueryViewApi)
appbuilder.add_view_no_menu(SliceAsync)
appbuilder.add_view_no_menu(SqlLab)
appbuilder.add_view_no_menu(SqlMetricInlineView)
Expand Down
38 changes: 36 additions & 2 deletions superset/views/sql_lab/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,23 @@
import simplejson as json
from flask import redirect, request, Response
from flask_appbuilder import expose
from flask_appbuilder.models.sqla.interface import SQLAInterface
from flask_appbuilder.security.decorators import has_access, has_access_api
from flask_babel import lazy_gettext as _
from sqlalchemy import and_

from superset import db
from superset.models.sql_lab import Query, TableSchema, TabState
from superset.constants import MODEL_VIEW_RW_METHOD_PERMISSION_MAP, RouteMethod
from superset.models.sql_lab import Query, SavedQuery, TableSchema, TabState
from superset.superset_typing import FlaskResponse
from superset.utils import core as utils
from superset.utils.core import get_user_id
from superset.views.base import BaseSupersetView, json_success
from superset.views.base import (
BaseSupersetView,
DeleteMixin,
json_success,
SupersetModelView,
)

logger = logging.getLogger(__name__)

Expand All @@ -43,6 +50,33 @@ def list(self) -> FlaskResponse:
return super().render_app_template()


class SavedQueryViewApi(
SupersetModelView, DeleteMixin
): # pylint: disable=too-many-ancestors
datamodel = SQLAInterface(SavedQuery)
include_route_methods = RouteMethod.CRUD_SET
route_base = "/savedqueryviewapi"
class_permission_name = "SavedQuery"

include_route_methods = {
RouteMethod.API_READ,
RouteMethod.API_CREATE,
RouteMethod.API_UPDATE,
RouteMethod.API_GET,
}

method_permission_name = MODEL_VIEW_RW_METHOD_PERMISSION_MAP

add_columns = ["label", "db_id", "schema", "description", "sql", "extra_json"]
edit_columns = add_columns
show_columns = add_columns + ["id"]

@has_access_api
@expose("show/<pk>")
def show(self, pk: int) -> FlaskResponse:
return super().show(pk)


def _get_owner_id(tab_state_id: int) -> int:
return db.session.query(TabState.user_id).filter_by(id=tab_state_id).scalar()

Expand Down

0 comments on commit 1144ac1

Please sign in to comment.