mirror of
https://github.com/apache/superset.git
synced 2026-04-19 16:14:52 +00:00
feat(database): Database Filtering via custom configuration (#24580)
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
# under the License.
|
||||
from typing import Any
|
||||
|
||||
from flask import g
|
||||
from flask import current_app, g
|
||||
from flask_babel import lazy_gettext as _
|
||||
from sqlalchemy import or_
|
||||
from sqlalchemy.orm import Query
|
||||
@@ -41,6 +41,19 @@ class DatabaseFilter(BaseFilter): # pylint: disable=too-few-public-methods
|
||||
# TODO(bogdan): consider caching.
|
||||
|
||||
def apply(self, query: Query, value: Any) -> Query:
|
||||
"""
|
||||
Dynamic Filters need to be applied to the Query before we filter
|
||||
databases with anything else. This way you can show/hide databases using
|
||||
Feature Flags for example in conjuction with the regular role filtering.
|
||||
If not, if an user has access to all Databases it would skip this dynamic
|
||||
filtering.
|
||||
"""
|
||||
|
||||
if dynamic_filters := current_app.config["EXTRA_DYNAMIC_QUERY_FILTERS"]:
|
||||
if dynamic_databases_filter := dynamic_filters.get("databases"):
|
||||
query = dynamic_databases_filter(query)
|
||||
|
||||
# We can proceed with default filtering now
|
||||
if security_manager.can_access_all_databases():
|
||||
return query
|
||||
database_perms = security_manager.user_view_menu_names("database_access")
|
||||
|
||||
Reference in New Issue
Block a user