superset-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From maximebeauche...@apache.org
Subject [incubator-superset] branch master updated: Prevent people from deleting datasources that have associate slices (#3163)
Date Wed, 19 Jul 2017 23:24:22 GMT
This is an automated email from the ASF dual-hosted git repository.

maximebeauchemin pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git


The following commit(s) were added to refs/heads/master by this push:
     new a141695  Prevent people from deleting datasources that have associate slices (#3163)
a141695 is described below

commit a141695b2b73df1d05d74c8ed8e22341e6e25edc
Author: Maxime Beauchemin <maximebeauchemin@gmail.com>
AuthorDate: Wed Jul 19 16:24:20 2017 -0700

    Prevent people from deleting datasources that have associate slices (#3163)
---
 superset/connectors/base/__init__.py            |  0
 superset/connectors/{base.py => base/models.py} |  0
 superset/connectors/base/views.py               | 12 ++++++++++++
 superset/connectors/druid/models.py             |  2 +-
 superset/connectors/druid/views.py              |  8 ++++----
 superset/connectors/sqla/models.py              |  5 ++---
 superset/connectors/sqla/views.py               |  5 +++--
 7 files changed, 22 insertions(+), 10 deletions(-)

diff --git a/superset/connectors/base/__init__.py b/superset/connectors/base/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/superset/connectors/base.py b/superset/connectors/base/models.py
similarity index 100%
rename from superset/connectors/base.py
rename to superset/connectors/base/models.py
diff --git a/superset/connectors/base/views.py b/superset/connectors/base/views.py
new file mode 100644
index 0000000..36cfe45
--- /dev/null
+++ b/superset/connectors/base/views.py
@@ -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])))
diff --git a/superset/connectors/druid/models.py b/superset/connectors/druid/models.py
index dc03726..b4e1556 100644
--- a/superset/connectors/druid/models.py
+++ b/superset/connectors/druid/models.py
@@ -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")
diff --git a/superset/connectors/druid/views.py b/superset/connectors/druid/views.py
index e123217..7ae3fb3 100644
--- a/superset/connectors/druid/views.py
+++ b/superset/connectors/druid/views.py
@@ -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 = [
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index 1cd0818..147c667 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -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
diff --git a/superset/connectors/sqla/views.py b/superset/connectors/sqla/views.py
index 5ba10da..cddd859 100644
--- a/superset/connectors/sqla/views.py
+++ b/superset/connectors/sqla/views.py
@@ -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',

-- 
To stop receiving notification emails like this one, please contact
['"commits@superset.apache.org" <commits@superset.apache.org>'].

Mime
View raw message