mirror of https://github.com/apache/superset.git
Add all_tables endpoint to allow airpal / superset perm sync. (#1614)
This commit is contained in:
parent
7a98f84890
commit
1624e7de7d
|
@ -1575,6 +1575,31 @@ class Superset(BaseSupersetView):
|
|||
ccount for dt, ccount in qry if dt}
|
||||
return Response(json.dumps(payload), mimetype="application/json")
|
||||
|
||||
@api
|
||||
@has_access_api
|
||||
@expose("/all_tables/<db_id>")
|
||||
def all_tables(self, db_id):
|
||||
"""Endpoint that returns all tables and views from the database"""
|
||||
database = (
|
||||
db.session
|
||||
.query(models.Database)
|
||||
.filter_by(id=db_id)
|
||||
.one()
|
||||
)
|
||||
all_tables = []
|
||||
all_views = []
|
||||
schemas = database.all_schema_names()
|
||||
for schema in schemas:
|
||||
all_tables.extend(database.all_table_names(schema=schema))
|
||||
all_views.extend(database.all_view_names(schema=schema))
|
||||
if not schemas:
|
||||
all_tables.extend(database.all_table_names())
|
||||
all_views.extend(database.all_view_names())
|
||||
|
||||
return Response(
|
||||
json.dumps({"tables": all_tables, "views": all_views}),
|
||||
mimetype="application/json")
|
||||
|
||||
@api
|
||||
@has_access_api
|
||||
@expose("/tables/<db_id>/<schema>")
|
||||
|
|
|
@ -427,10 +427,19 @@ class CoreTests(SupersetTestCase):
|
|||
|
||||
def test_fetch_datasource_metadata(self):
|
||||
self.login(username='admin')
|
||||
url = '/superset/fetch_datasource_metadata?datasource_type=table&datasource_id=1';
|
||||
url = '/superset/fetch_datasource_metadata?datasource_type=table&' \
|
||||
'datasource_id=1'
|
||||
resp = json.loads(self.get_resp(url))
|
||||
self.assertEqual(len(resp['field_options']), 20)
|
||||
|
||||
def test_fetch_all_tables(self):
|
||||
self.login(username='admin')
|
||||
database = self.get_main_database(db.session)
|
||||
url = '/superset/all_tables/{}'.format(database.id)
|
||||
resp = json.loads(self.get_resp(url))
|
||||
self.assertIn('tables', resp)
|
||||
self.assertIn('views', resp)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
|
Loading…
Reference in New Issue