You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ma...@apache.org on 2019/07/28 00:42:25 UTC
[incubator-superset] branch master updated: [log] Disable Log view
when FAB security views are disabled (#7920)
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 5487575 [log] Disable Log view when FAB security views are disabled (#7920)
5487575 is described below
commit 54875756bb63349105f846471db742cfb07d0614
Author: Daniel Vaz Gaspar <da...@gmail.com>
AuthorDate: Sun Jul 28 01:42:10 2019 +0100
[log] Disable Log view when FAB security views are disabled (#7920)
* [log] Disable Log view when FAB security views are disabled
* [tests] New, config flag SUPERSET_LOG_VIEW to have more control
* [tests] Fix, flake8
* [log] Fix, pylint
* [log] Fix, pylint at log module
* [log] Fix, pylint at log module
* [log] Fix, black
---
superset/views/__init__.py | 2 ++
superset/views/core.py | 29 ------------------
superset/views/{ => log}/__init__.py | 28 +++++++++++------
superset/views/log/api.py | 46 ++++++++++++++++++++++++++++
superset/views/{__init__.py => log/views.py} | 35 +++++++++++++++------
5 files changed, 93 insertions(+), 47 deletions(-)
diff --git a/superset/views/__init__.py b/superset/views/__init__.py
index f43043d..0b69633 100644
--- a/superset/views/__init__.py
+++ b/superset/views/__init__.py
@@ -23,3 +23,5 @@ from . import annotations # noqa
from . import datasource # noqa
from . import schedules # noqa
from . import tags # noqa
+from .log import views # noqa
+from .log import api as log_api # noqa
diff --git a/superset/views/core.py b/superset/views/core.py
index 5d3411e..558a30c 100755
--- a/superset/views/core.py
+++ b/superset/views/core.py
@@ -591,35 +591,6 @@ class DashboardAddView(DashboardModelView): # noqa
appbuilder.add_view_no_menu(DashboardAddView)
-class LogModelView(SupersetModelView):
- datamodel = SQLAInterface(models.Log)
-
- list_title = _("Logs")
- show_title = _("Show Log")
- add_title = _("Add Log")
- edit_title = _("Edit Log")
-
- list_columns = ("user", "action", "dttm")
- edit_columns = ("user", "action", "dttm", "json")
- base_order = ("dttm", "desc")
- label_columns = {
- "user": _("User"),
- "action": _("Action"),
- "dttm": _("dttm"),
- "json": _("JSON"),
- }
-
-
-appbuilder.add_view(
- LogModelView,
- "Action Log",
- label=__("Action Log"),
- category="Security",
- category_label=__("Security"),
- icon="fa-list-ol",
-)
-
-
@app.route("/health")
def health():
return "OK"
diff --git a/superset/views/__init__.py b/superset/views/log/__init__.py
similarity index 62%
copy from superset/views/__init__.py
copy to superset/views/log/__init__.py
index f43043d..c6c5676 100644
--- a/superset/views/__init__.py
+++ b/superset/views/log/__init__.py
@@ -14,12 +14,22 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from . import base # noqa
-from . import api # noqa
-from . import core # noqa
-from . import sql_lab # noqa
-from . import dashboard # noqa
-from . import annotations # noqa
-from . import datasource # noqa
-from . import schedules # noqa
-from . import tags # noqa
+# pylint: disable=C,R,W
+from flask_babel import lazy_gettext as _
+
+
+class LogMixin:
+ list_title = _("Logs")
+ show_title = _("Show Log")
+ add_title = _("Add Log")
+ edit_title = _("Edit Log")
+
+ list_columns = ("user", "action", "dttm")
+ edit_columns = ("user", "action", "dttm", "json")
+ base_order = ("dttm", "desc")
+ label_columns = {
+ "user": _("User"),
+ "action": _("Action"),
+ "dttm": _("dttm"),
+ "json": _("JSON"),
+ }
diff --git a/superset/views/log/api.py b/superset/views/log/api.py
new file mode 100644
index 0000000..4136e5a
--- /dev/null
+++ b/superset/views/log/api.py
@@ -0,0 +1,46 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+from flask_appbuilder import ModelRestApi
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+
+from superset import app, appbuilder
+import superset.models.core as models
+from . import LogMixin
+
+
+class LogRestApi(LogMixin, ModelRestApi):
+ datamodel = SQLAInterface(models.Log)
+
+ class_permission_name = "LogModelView"
+ method_permission_name = {
+ "get_list": "list",
+ "get": "show",
+ "post": "add",
+ "put": "edit",
+ "delete": "delete",
+ "info": "list",
+ }
+ resource_name = "log"
+ allow_browser_login = True
+ list_columns = ("user.username", "action", "dttm")
+
+
+if (
+ not app.config.get("FAB_ADD_SECURITY_VIEWS") is False
+ or app.config.get("SUPERSET_LOG_VIEW") is False
+):
+ appbuilder.add_api(LogRestApi)
diff --git a/superset/views/__init__.py b/superset/views/log/views.py
similarity index 53%
copy from superset/views/__init__.py
copy to superset/views/log/views.py
index f43043d..4c11a89 100644
--- a/superset/views/__init__.py
+++ b/superset/views/log/views.py
@@ -14,12 +14,29 @@
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
-from . import base # noqa
-from . import api # noqa
-from . import core # noqa
-from . import sql_lab # noqa
-from . import dashboard # noqa
-from . import annotations # noqa
-from . import datasource # noqa
-from . import schedules # noqa
-from . import tags # noqa
+# pylint: disable=C,R,W
+from flask_appbuilder.models.sqla.interface import SQLAInterface
+from flask_babel import gettext as __
+
+from superset import app, appbuilder
+import superset.models.core as models
+from superset.views.base import SupersetModelView
+from . import LogMixin
+
+
+class LogModelView(LogMixin, SupersetModelView):
+ datamodel = SQLAInterface(models.Log)
+
+
+if (
+ not app.config.get("FAB_ADD_SECURITY_VIEWS") is False
+ or app.config.get("SUPERSET_LOG_VIEW") is False
+):
+ appbuilder.add_view(
+ LogModelView,
+ "Action Log",
+ label=__("Action Log"),
+ category="Security",
+ category_label=__("Security"),
+ icon="fa-list-ol",
+ )