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 all 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
10 changes: 10 additions & 0 deletions superset/views/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -1513,6 +1513,16 @@ 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 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)
Expand Down