fix(embedded): adding logic to check dataset used by filters (#24808)

(cherry picked from commit 7f9b0380e0)
This commit is contained in:
Vitor Avila
2023-07-31 18:10:57 -03:00
committed by Michael S. Molina
parent 161e05445c
commit bbe4e016d8
2 changed files with 69 additions and 2 deletions

View File

@@ -16,6 +16,7 @@
# under the License.
# pylint: disable=too-many-lines
"""A set of constants and methods to manage permissions and security"""
import json
import logging
import re
import time
@@ -2062,8 +2063,28 @@ class SupersetSecurityManager( # pylint: disable=too-many-public-methods
.filter(Dashboard.id.in_(dashboard_ids))
)
exists = db.session.query(query.exists()).scalar()
return exists
if db.session.query(query.exists()).scalar():
return True
# check for datasets that are only used by filters
dashboards_json = (
db.session.query(Dashboard.json_metadata)
.filter(Dashboard.id.in_(dashboard_ids))
.all()
)
for json_ in dashboards_json:
try:
json_metadata = json.loads(json_.json_metadata)
for filter_ in json_metadata.get("native_filter_configuration", []):
filter_dataset_ids = [
target.get("datasetId") for target in filter_.get("targets", [])
]
if datasource.id in filter_dataset_ids:
return True
except ValueError:
pass
return False
@staticmethod
def _get_current_epoch_time() -> float: