Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: native annotations #10037

Merged
merged 3 commits into from
Jun 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions superset/common/query_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ def cache_key(self, query_obj: QueryObject, **kwargs: Any) -> Optional[str]:
extra_cache_keys=extra_cache_keys,
rls=security_manager.get_rls_ids(self.datasource)
if config["ENABLE_ROW_LEVEL_SECURITY"]
and self.datasource.is_rls_supported
else [],
changed_on=self.datasource.changed_on,
**kwargs
Expand Down
3 changes: 3 additions & 0 deletions superset/connectors/base/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ def metric_class(self) -> Type["BaseMetric"]:
# Used to do code highlighting when displaying the query in the UI
query_language: Optional[str] = None

# Only some datasources support Row Level Security
is_rls_supported: bool = False

@property
def name(self) -> str:
# can be a Column or a property pointing to one
Expand Down
2 changes: 1 addition & 1 deletion superset/connectors/sqla/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
# under the License.
# pylint: disable=C,R,W
import logging
import re
from collections import OrderedDict
from datetime import datetime, timedelta
from typing import Any, Dict, Hashable, List, NamedTuple, Optional, Tuple, Union
Expand Down Expand Up @@ -394,6 +393,7 @@ class SqlaTable(Model, BaseDatasource):

type = "table"
query_language = "sql"
is_rls_supported = True
metric_class = SqlMetric
column_class = TableColumn
owner_class = security_manager.user_model
Expand Down
2 changes: 1 addition & 1 deletion superset/views/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ class AnnotationLayerModelView(SupersetModelView): # pylint: disable=too-many-a
add_title = _("Add Annotation Layer")
edit_title = _("Edit Annotation Layer")

list_columns = ["name", "descr"]
list_columns = ["id", "name", "descr"]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will make the CRUD view slightly uglier with the id, but is necessary based on discussions with @dpgaspar

edit_columns = ["name", "descr"]
add_columns = edit_columns

Expand Down
5 changes: 2 additions & 3 deletions superset/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,9 @@
from flask import request
from flask_babel import lazy_gettext as _
from geopy.point import Point
from markdown import markdown
from pandas.tseries.frequencies import to_offset

from superset import app, cache, get_manifest_files, security_manager
from superset import app, cache, security_manager
from superset.constants import NULL_STRING
from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
from superset.exceptions import (
Expand Down Expand Up @@ -405,7 +404,7 @@ def cache_key(self, query_obj: QueryObjectDict, **extra: Any) -> str:
cache_dict["extra_cache_keys"] = self.datasource.get_extra_cache_keys(query_obj)
cache_dict["rls"] = (
security_manager.get_rls_ids(self.datasource)
if config["ENABLE_ROW_LEVEL_SECURITY"]
if config["ENABLE_ROW_LEVEL_SECURITY"] and self.datasource.is_rls_supported
else []
)
cache_dict["changed_on"] = self.datasource.changed_on
Expand Down
12 changes: 9 additions & 3 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,12 +177,18 @@ def test_annotation_json_endpoint(self):
db.session.add(annotation)
db.session.commit()

resp = self.get_resp(
resp_annotations = json.loads(
self.get_resp("annotationlayermodelview/api/read")
)
# the UI needs id and name to function
self.assertIn("id", resp_annotations["result"][0])
self.assertIn("name", resp_annotations["result"][0])

layer = self.get_resp(
f"/superset/annotation_json/{layer.id}?form_data="
+ quote(json.dumps({"time_range": "100 years ago : now"}))
)

assert "my_annotation" in resp
self.assertIn("my_annotation", layer)

def test_admin_only_permissions(self):
def assert_admin_permission_in(role_name, assert_func):
Expand Down