Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

limit tables/views returned if schema is not provided #7358

Merged
merged 4 commits into from
Apr 23, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions superset/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -748,6 +748,10 @@ def table_cache_enabled(self):
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)
Expand Down
19 changes: 19 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,25 @@ def tables(self, db_id, schema, substr, force_refresh='false'):
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:
datability-io marked this conversation as resolved.
Show resolved Hide resolved
def is_default_tbl_or_view(tbl_or_view_name, schemas):
datability-io marked this conversation as resolved.
Show resolved Hide resolved
if tbl_or_view_name.startswith('{}.'.format(g.user.username)):
return True

for schema in schemas:
if tbl_or_view_name.startswith('{}.'.format(schema)):
return True
return False

table_names = [
tn for tn in table_names
if is_default_tbl_or_view(tn, database.default_schemas)
]
view_names = [
vn for vn in view_names
if is_default_tbl_or_view(vn, database.default_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)
Expand Down