diff --git a/superset/views.py b/superset/views.py index 92abaec4aa4d..13e3246b5f2a 100755 --- a/superset/views.py +++ b/superset/views.py @@ -1419,6 +1419,8 @@ def explore(self, datasource_type, datasource_id): viz_type = request.args.get("viz_type") slice_id = request.args.get('slice_id') slc = None + user_id = g.user.get_id() if g.user else None + if slice_id: slc = db.session.query(models.Slice).filter_by(id=slice_id).first() @@ -1464,6 +1466,10 @@ def explore(self, datasource_type, datasource_id): return self.save_or_overwrite_slice( request.args, slc, slice_add_perm, slice_edit_perm) + # find out if user is in explore v2 beta group + # and set flag `is_in_explore_v2_beta` + is_in_explore_v2_beta = sm.find_role('explore-v2-beta') in get_user_roles() + # handle different endpoints if request.args.get("csv") == "true": payload = viz_obj.get_csv() @@ -1474,7 +1480,7 @@ def explore(self, datasource_type, datasource_id): mimetype="application/csv") elif request.args.get("standalone") == "true": return self.render_template("superset/standalone.html", viz=viz_obj, standalone_mode=True) - elif request.args.get("V2") == "true": + elif request.args.get("V2") == "true" or is_in_explore_v2_beta: # bootstrap data for explore V2 bootstrap_data = { "can_add": slice_add_perm, @@ -1485,7 +1491,7 @@ def explore(self, datasource_type, datasource_id): "datasource_id": datasource_id, "datasource_name": viz_obj.datasource.name, "datasource_type": datasource_type, - "user_id": g.user.get_id() if g.user else None, + "user_id": user_id, "viz": json.loads(viz_obj.get_json()) } table_name = viz_obj.datasource.table_name \ diff --git a/tests/core_tests.py b/tests/core_tests.py index c7f05f4e7907..1db00a6c4647 100644 --- a/tests/core_tests.py +++ b/tests/core_tests.py @@ -137,6 +137,27 @@ def test_slices(self): print("[{name}]/[{method}]: {url}".format(**locals())) self.client.get(url) + def test_slices_V2(self): + # Add explore-v2-beta role to admin user + # Test all slice urls as user with with explore-v2-beta role + sm.add_role('explore-v2-beta') + + appbuilder.sm.add_user( + 'explore_beta', 'explore_beta', ' user', 'explore_beta@airbnb.com', + appbuilder.sm.find_role('explore-v2-beta'), + password='general') + self.login(username='explore_beta', password='general') + + Slc = models.Slice + urls = [] + for slc in db.session.query(Slc).all(): + urls += [ + (slc.slice_name, 'slice_url', slc.slice_url), + ] + for name, method, url in urls: + print("[{name}]/[{method}]: {url}".format(**locals())) + response = self.client.get(url) + def test_dashboard(self): self.login(username='admin') urls = {}