You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by be...@apache.org on 2024/05/29 00:47:00 UTC
(superset) branch remove-repeated-code created (now 9935f4ea4e)
This is an automated email from the ASF dual-hosted git repository.
beto pushed a change to branch remove-repeated-code
in repository https://gitbox.apache.org/repos/asf/superset.git
at 9935f4ea4e chore: remove duplicate code
This branch includes the following new commits:
new 9935f4ea4e chore: remove duplicate code
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(superset) 01/01: chore: remove duplicate code
Posted by be...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
beto pushed a commit to branch remove-repeated-code
in repository https://gitbox.apache.org/repos/asf/superset.git
commit 9935f4ea4e4e8cf35b2b8f1ec0ca2e431dc379ee
Author: Beto Dealmeida <ro...@dealmeida.net>
AuthorDate: Tue May 28 20:46:52 2024 -0400
chore: remove duplicate code
---
superset/connectors/sqla/models.py | 42 --------------------------------------
superset/models/helpers.py | 4 +++-
superset/sql_parse.py | 1 -
3 files changed, 3 insertions(+), 44 deletions(-)
diff --git a/superset/connectors/sqla/models.py b/superset/connectors/sqla/models.py
index a566079b0f..bed7bb3968 100644
--- a/superset/connectors/sqla/models.py
+++ b/superset/connectors/sqla/models.py
@@ -1603,48 +1603,6 @@ class SqlaTable(
if is_alias_used_in_orderby(col):
col.name = f"{col.name}__"
- def get_sqla_row_level_filters(
- self,
- template_processor: BaseTemplateProcessor,
- ) -> list[TextClause]:
- """
- Return the appropriate row level security filters for this table and the
- current user. A custom username can be passed when the user is not present in the
- Flask global namespace.
-
- :param template_processor: The template processor to apply to the filters.
- :returns: A list of SQL clauses to be ANDed together.
- """
- all_filters: list[TextClause] = []
- filter_groups: dict[int | str, list[TextClause]] = defaultdict(list)
- try:
- for filter_ in security_manager.get_rls_filters(self):
- clause = self.text(
- f"({template_processor.process_template(filter_.clause)})"
- )
- if filter_.group_key:
- filter_groups[filter_.group_key].append(clause)
- else:
- all_filters.append(clause)
-
- if is_feature_enabled("EMBEDDED_SUPERSET"):
- for rule in security_manager.get_guest_rls_filters(self):
- clause = self.text(
- f"({template_processor.process_template(rule['clause'])})"
- )
- all_filters.append(clause)
-
- grouped_filters = [or_(*clauses) for clauses in filter_groups.values()]
- all_filters.extend(grouped_filters)
- return all_filters
- except TemplateError as ex:
- raise QueryObjectValidationError(
- _(
- "Error in jinja expression in RLS filters: %(msg)s",
- msg=ex.message,
- )
- ) from ex
-
def text(self, clause: str) -> TextClause:
return self.db_engine_spec.get_text_clause(clause)
diff --git a/superset/models/helpers.py b/superset/models/helpers.py
index dffb285663..496a7c0630 100644
--- a/superset/models/helpers.py
+++ b/superset/models/helpers.py
@@ -805,7 +805,7 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
def get_sqla_row_level_filters(
self,
- template_processor: BaseTemplateProcessor,
+ template_processor: BaseTemplateProcessor | None,
) -> list[TextClause]:
"""
Return the appropriate row level security filters for this table and the
@@ -815,6 +815,8 @@ class ExploreMixin: # pylint: disable=too-many-public-methods
:param template_processor: The template processor to apply to the filters.
:returns: A list of SQL clauses to be ANDed together.
"""
+ template_processor = template_processor or self.get_template_processor()
+
all_filters: list[TextClause] = []
filter_groups: dict[Union[int, str], list[TextClause]] = defaultdict(list)
try:
diff --git a/superset/sql_parse.py b/superset/sql_parse.py
index f32647042b..0bdbfd8bd7 100644
--- a/superset/sql_parse.py
+++ b/superset/sql_parse.py
@@ -1227,7 +1227,6 @@ def get_rls_for_table(
if not dataset:
return None
- template_processor = dataset.get_template_processor()
predicate = " AND ".join(
str(filter_)
for filter_ in dataset.get_sqla_row_level_filters(template_processor)