mirror of
https://github.com/apache/superset.git
synced 2024-09-12 00:29:39 -04:00
limit tables/views returned if schema is not provided (#7358)
* limit tables/views returned if schema is not provided * fix typo * improve code performance * handle the case when table name or view name does not present a schema
This commit is contained in:
parent
5f14b559e2
commit
4bc69c0a61
@ -748,6 +748,10 @@ class Database(Model, AuditMixinNullable, ImportMixin):
|
||||
def table_cache_timeout(self):
|
||||
return self.metadata_cache_timeout.get('table_cache_timeout')
|
||||
|
||||
@property
|
||||
def default_schemas(self):
|
||||
return self.get_extra().get('default_schemas', [])
|
||||
|
||||
@classmethod
|
||||
def get_password_masked_url_from_uri(cls, uri):
|
||||
url = make_url(uri)
|
||||
|
@ -1513,6 +1513,16 @@ class Superset(BaseSupersetView):
|
||||
table_names = [tn for tn in table_names if substr in tn]
|
||||
view_names = [vn for vn in view_names if substr in vn]
|
||||
|
||||
if not schema and database.default_schemas:
|
||||
def get_schema(tbl_or_view_name):
|
||||
return tbl_or_view_name.split('.')[0] if '.' in tbl_or_view_name else None
|
||||
|
||||
user_schema = g.user.email.split('@')[0]
|
||||
valid_schemas = set(database.default_schemas + [user_schema])
|
||||
|
||||
table_names = [tn for tn in table_names if get_schema(tn) in valid_schemas]
|
||||
view_names = [vn for vn in view_names if get_schema(vn) in valid_schemas]
|
||||
|
||||
max_items = config.get('MAX_TABLE_NAMES') or len(table_names)
|
||||
total_items = len(table_names) + len(view_names)
|
||||
max_tables = len(table_names)
|
||||
|
Loading…
Reference in New Issue
Block a user