mirror of https://github.com/apache/superset.git
Prevent people from deleting datasources that have associate slices (#3163)
This commit is contained in:
parent
d01e67a159
commit
a141695b2b
|
@ -0,0 +1,12 @@
|
|||
from superset.views.base import SupersetModelView
|
||||
from superset.utils import SupersetException
|
||||
from flask import Markup
|
||||
|
||||
|
||||
class DatasourceModelView(SupersetModelView):
|
||||
def pre_delete(self, obj):
|
||||
if obj.slices:
|
||||
raise SupersetException(Markup(
|
||||
"Cannot delete a datasource that has slices attached to it."
|
||||
"Here's the list of associated slices: " +
|
||||
"".join([o.slice_link for o in obj.slices])))
|
|
@ -33,7 +33,7 @@ from superset import conf, db, import_util, utils, sm, get_session
|
|||
from superset.utils import (
|
||||
flasher, MetricPermException, DimSelector, DTTM_ALIAS
|
||||
)
|
||||
from superset.connectors.base import BaseDatasource, BaseColumn, BaseMetric
|
||||
from superset.connectors.base.models import BaseDatasource, BaseColumn, BaseMetric
|
||||
from superset.models.helpers import AuditMixinNullable, QueryResult, set_perm
|
||||
|
||||
DRUID_TZ = conf.get("DRUID_TZ")
|
||||
|
|
|
@ -3,19 +3,19 @@ import logging
|
|||
|
||||
import sqlalchemy as sqla
|
||||
|
||||
from flask import Markup, flash, redirect, abort
|
||||
from flask import Markup, flash, redirect
|
||||
from flask_appbuilder import CompactCRUDMixin, expose
|
||||
from flask_appbuilder.models.sqla.interface import SQLAInterface
|
||||
|
||||
from flask_babel import lazy_gettext as _
|
||||
from flask_babel import gettext as __
|
||||
|
||||
import superset
|
||||
from superset import db, utils, appbuilder, sm, security
|
||||
from superset.connectors.connector_registry import ConnectorRegistry
|
||||
from superset.utils import has_access
|
||||
from superset.views.base import BaseSupersetView
|
||||
from superset.connectors.base.views import DatasourceModelView
|
||||
from superset.views.base import (
|
||||
BaseSupersetView,
|
||||
SupersetModelView, validate_json, DeleteMixin, ListWidgetWithCheckboxes,
|
||||
DatasourceFilter, get_datasource_exist_error_mgs)
|
||||
|
||||
|
@ -149,7 +149,7 @@ appbuilder.add_view(
|
|||
category_icon='fa-database',)
|
||||
|
||||
|
||||
class DruidDatasourceModelView(SupersetModelView, DeleteMixin): # noqa
|
||||
class DruidDatasourceModelView(DatasourceModelView, DeleteMixin): # noqa
|
||||
datamodel = SQLAInterface(models.DruidDatasource)
|
||||
list_widget = ListWidgetWithCheckboxes
|
||||
list_columns = [
|
||||
|
|
|
@ -11,8 +11,7 @@ from sqlalchemy import (
|
|||
)
|
||||
import sqlalchemy as sa
|
||||
from sqlalchemy import asc, and_, desc, select
|
||||
from sqlalchemy.ext.compiler import compiles
|
||||
from sqlalchemy.sql.expression import ColumnClause, TextAsFrom
|
||||
from sqlalchemy.sql.expression import TextAsFrom
|
||||
from sqlalchemy.orm import backref, relationship
|
||||
from sqlalchemy.sql import table, literal_column, text, column
|
||||
|
||||
|
@ -21,7 +20,7 @@ from flask_appbuilder import Model
|
|||
from flask_babel import lazy_gettext as _
|
||||
|
||||
from superset import db, utils, import_util, sm
|
||||
from superset.connectors.base import BaseDatasource, BaseColumn, BaseMetric
|
||||
from superset.connectors.base.models import BaseDatasource, BaseColumn, BaseMetric
|
||||
from superset.utils import DTTM_ALIAS, QueryStatus
|
||||
from superset.models.helpers import QueryResult
|
||||
from superset.models.core import Database
|
||||
|
|
|
@ -3,7 +3,7 @@ import logging
|
|||
|
||||
from past.builtins import basestring
|
||||
|
||||
from flask import Markup, flash, redirect, abort
|
||||
from flask import Markup, flash, redirect
|
||||
from flask_appbuilder import CompactCRUDMixin, expose
|
||||
from flask_appbuilder.models.sqla.interface import SQLAInterface
|
||||
import sqlalchemy as sa
|
||||
|
@ -13,6 +13,7 @@ from flask_babel import gettext as __
|
|||
|
||||
from superset import appbuilder, db, utils, security, sm
|
||||
from superset.utils import has_access
|
||||
from superset.connectors.base.views import DatasourceModelView
|
||||
from superset.views.base import (
|
||||
SupersetModelView, ListWidgetWithCheckboxes, DeleteMixin, DatasourceFilter,
|
||||
get_datasource_exist_error_mgs,
|
||||
|
@ -133,7 +134,7 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
|
|||
appbuilder.add_view_no_menu(SqlMetricInlineView)
|
||||
|
||||
|
||||
class TableModelView(SupersetModelView, DeleteMixin): # noqa
|
||||
class TableModelView(DatasourceModelView, DeleteMixin): # noqa
|
||||
datamodel = SQLAInterface(models.SqlaTable)
|
||||
list_columns = [
|
||||
'link', 'database',
|
||||
|
|
Loading…
Reference in New Issue