Skip to content

Commit

Permalink
Prevent people from deleting datasources that have associate slices (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch authored Jul 19, 2017
1 parent d01e67a commit a141695
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 10 deletions.
Empty file.
File renamed without changes.
12 changes: 12 additions & 0 deletions superset/connectors/base/views.py
Original file line number Diff line number Diff line change
@@ -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])))
2 changes: 1 addition & 1 deletion superset/connectors/druid/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
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")
Expand Down
8 changes: 4 additions & 4 deletions superset/connectors/druid/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,19 @@

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)

Expand Down Expand Up @@ -149,7 +149,7 @@ def _delete(self, pk):
category_icon='fa-database',)


class DruidDatasourceModelView(SupersetModelView, DeleteMixin): # noqa
class DruidDatasourceModelView(DatasourceModelView, DeleteMixin): # noqa
datamodel = SQLAInterface(models.DruidDatasource)
list_widget = ListWidgetWithCheckboxes
list_columns = [
Expand Down
5 changes: 2 additions & 3 deletions superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
)
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

Expand All @@ -21,7 +20,7 @@
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
Expand Down
5 changes: 3 additions & 2 deletions superset/connectors/sqla/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

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
Expand All @@ -13,6 +13,7 @@

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,
Expand Down Expand Up @@ -133,7 +134,7 @@ def post_update(self, metric):
appbuilder.add_view_no_menu(SqlMetricInlineView)


class TableModelView(SupersetModelView, DeleteMixin): # noqa
class TableModelView(DatasourceModelView, DeleteMixin): # noqa
datamodel = SQLAInterface(models.SqlaTable)
list_columns = [
'link', 'database',
Expand Down

0 comments on commit a141695

Please sign in to comment.