fix: native annotations (#10037)

* fix: native annotations

* Add test

* Add comment to test
This commit is contained in:
Ville Brofeldt 2020-06-12 21:53:26 +03:00 committed by GitHub
parent 373651efa4
commit a3393c1bc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 17 additions and 8 deletions

View File

@ -196,6 +196,7 @@ class QueryContext:
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

View File

@ -84,6 +84,9 @@ class BaseDatasource(
# 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

View File

@ -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
@ -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

View File

@ -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

View File

@ -43,10 +43,9 @@ from dateutil import relativedelta as rdelta
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 (
@ -405,7 +404,7 @@ class BaseViz:
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

View File

@ -177,12 +177,18 @@ class CoreTests(SupersetTestCase):
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):