Skip to content

Commit

Permalink
fix: native annotations (apache#10037)
Browse files Browse the repository at this point in the history
* fix: native annotations

* Add test

* Add comment to test
  • Loading branch information
villebro authored and auxten committed Nov 20, 2020
1 parent 7cf0ed9 commit 1bc69c2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 8 deletions.
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"]
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

0 comments on commit 1bc69c2

Please sign in to comment.