Skip to content

Commit

Permalink
[explore-v2] add config option for explore v2 beta users, and send th…
Browse files Browse the repository at this point in the history
…rough v2 path (#1671)

* add config option for explore v2 beta users, and send through v2 path

* fix long lines

* use role rather than user ids in config

* add test

* simplify role check

* remove extra  line

* use different test user for v2 tests
  • Loading branch information
Alanna Scott committed Dec 13, 2016
1 parent 2254a4d commit 34e107e
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
10 changes: 8 additions & 2 deletions superset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand All @@ -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,
Expand All @@ -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 \
Expand Down
21 changes: 21 additions & 0 deletions tests/core_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down

0 comments on commit 34e107e

Please sign in to comment.