mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
Prevent people from deleting datasources that have associate slices (#3163)
This commit is contained in:
parent
d01e67a159
commit
a141695b2b
0
superset/connectors/base/__init__.py
Normal file
0
superset/connectors/base/__init__.py
Normal file
12
superset/connectors/base/views.py
Normal file
12
superset/connectors/base/views.py
Normal file
@ -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 (
|
from superset.utils import (
|
||||||
flasher, MetricPermException, DimSelector, DTTM_ALIAS
|
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
|
from superset.models.helpers import AuditMixinNullable, QueryResult, set_perm
|
||||||
|
|
||||||
DRUID_TZ = conf.get("DRUID_TZ")
|
DRUID_TZ = conf.get("DRUID_TZ")
|
||||||
|
@ -3,19 +3,19 @@ import logging
|
|||||||
|
|
||||||
import sqlalchemy as sqla
|
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 import CompactCRUDMixin, expose
|
||||||
from flask_appbuilder.models.sqla.interface import SQLAInterface
|
from flask_appbuilder.models.sqla.interface import SQLAInterface
|
||||||
|
|
||||||
from flask_babel import lazy_gettext as _
|
from flask_babel import lazy_gettext as _
|
||||||
from flask_babel import gettext as __
|
from flask_babel import gettext as __
|
||||||
|
|
||||||
import superset
|
|
||||||
from superset import db, utils, appbuilder, sm, security
|
from superset import db, utils, appbuilder, sm, security
|
||||||
from superset.connectors.connector_registry import ConnectorRegistry
|
from superset.connectors.connector_registry import ConnectorRegistry
|
||||||
from superset.utils import has_access
|
from superset.utils import has_access
|
||||||
from superset.views.base import BaseSupersetView
|
from superset.connectors.base.views import DatasourceModelView
|
||||||
from superset.views.base import (
|
from superset.views.base import (
|
||||||
|
BaseSupersetView,
|
||||||
SupersetModelView, validate_json, DeleteMixin, ListWidgetWithCheckboxes,
|
SupersetModelView, validate_json, DeleteMixin, ListWidgetWithCheckboxes,
|
||||||
DatasourceFilter, get_datasource_exist_error_mgs)
|
DatasourceFilter, get_datasource_exist_error_mgs)
|
||||||
|
|
||||||
@ -149,7 +149,7 @@ appbuilder.add_view(
|
|||||||
category_icon='fa-database',)
|
category_icon='fa-database',)
|
||||||
|
|
||||||
|
|
||||||
class DruidDatasourceModelView(SupersetModelView, DeleteMixin): # noqa
|
class DruidDatasourceModelView(DatasourceModelView, DeleteMixin): # noqa
|
||||||
datamodel = SQLAInterface(models.DruidDatasource)
|
datamodel = SQLAInterface(models.DruidDatasource)
|
||||||
list_widget = ListWidgetWithCheckboxes
|
list_widget = ListWidgetWithCheckboxes
|
||||||
list_columns = [
|
list_columns = [
|
||||||
|
@ -11,8 +11,7 @@ from sqlalchemy import (
|
|||||||
)
|
)
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
from sqlalchemy import asc, and_, desc, select
|
from sqlalchemy import asc, and_, desc, select
|
||||||
from sqlalchemy.ext.compiler import compiles
|
from sqlalchemy.sql.expression import TextAsFrom
|
||||||
from sqlalchemy.sql.expression import ColumnClause, TextAsFrom
|
|
||||||
from sqlalchemy.orm import backref, relationship
|
from sqlalchemy.orm import backref, relationship
|
||||||
from sqlalchemy.sql import table, literal_column, text, column
|
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 flask_babel import lazy_gettext as _
|
||||||
|
|
||||||
from superset import db, utils, import_util, sm
|
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.utils import DTTM_ALIAS, QueryStatus
|
||||||
from superset.models.helpers import QueryResult
|
from superset.models.helpers import QueryResult
|
||||||
from superset.models.core import Database
|
from superset.models.core import Database
|
||||||
|
@ -3,7 +3,7 @@ import logging
|
|||||||
|
|
||||||
from past.builtins import basestring
|
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 import CompactCRUDMixin, expose
|
||||||
from flask_appbuilder.models.sqla.interface import SQLAInterface
|
from flask_appbuilder.models.sqla.interface import SQLAInterface
|
||||||
import sqlalchemy as sa
|
import sqlalchemy as sa
|
||||||
@ -13,6 +13,7 @@ from flask_babel import gettext as __
|
|||||||
|
|
||||||
from superset import appbuilder, db, utils, security, sm
|
from superset import appbuilder, db, utils, security, sm
|
||||||
from superset.utils import has_access
|
from superset.utils import has_access
|
||||||
|
from superset.connectors.base.views import DatasourceModelView
|
||||||
from superset.views.base import (
|
from superset.views.base import (
|
||||||
SupersetModelView, ListWidgetWithCheckboxes, DeleteMixin, DatasourceFilter,
|
SupersetModelView, ListWidgetWithCheckboxes, DeleteMixin, DatasourceFilter,
|
||||||
get_datasource_exist_error_mgs,
|
get_datasource_exist_error_mgs,
|
||||||
@ -133,7 +134,7 @@ class SqlMetricInlineView(CompactCRUDMixin, SupersetModelView): # noqa
|
|||||||
appbuilder.add_view_no_menu(SqlMetricInlineView)
|
appbuilder.add_view_no_menu(SqlMetricInlineView)
|
||||||
|
|
||||||
|
|
||||||
class TableModelView(SupersetModelView, DeleteMixin): # noqa
|
class TableModelView(DatasourceModelView, DeleteMixin): # noqa
|
||||||
datamodel = SQLAInterface(models.SqlaTable)
|
datamodel = SQLAInterface(models.SqlaTable)
|
||||||
list_columns = [
|
list_columns = [
|
||||||
'link', 'database',
|
'link', 'database',
|
||||||
|
Loading…
Reference in New Issue
Block a user