Skip to content

Commit

Permalink
Update role based on usernames not emails. (#1749)
Browse files Browse the repository at this point in the history
  • Loading branch information
bkyryliuk authored Dec 2, 2016
1 parent 95580a0 commit 9d4c3d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions superset/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1139,12 +1139,12 @@ class Superset(BaseSupersetView):
def update_role(self):
"""Assigns a list of found users to the given role."""
data = request.get_json(force=True)
user_emails = data['user_emails']
usernames = data['usernames']
role_name = data['role_name']
role = sm.find_role(role_name)
role.user = []
for user_email in user_emails:
user = sm.find_user(email=user_email)
for username in usernames:
user = sm.find_user(username=username)
if user:
role.user.append(user)
db.session.commit()
Expand Down
10 changes: 5 additions & 5 deletions tests/access_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ def test_update_role_do_not_exist(self):
self.get_resp(
'/superset/update_role/',
data=json.dumps({
'user_emails': ['gamma@fab.org'],
'usernames': ['gamma'],
'role_name': update_role_str,
})
)
Expand All @@ -370,28 +370,28 @@ def test_update_role(self):
resp = self.client.post(
'/superset/update_role/',
data=json.dumps({
'user_emails': ['gamma@fab.org'],
'usernames': ['gamma'],
'role_name': update_role_str
}),
follow_redirects=True
)
update_role = sm.find_role(update_role_str)
self.assertEquals(
update_role.user, [sm.find_user(email='gamma@fab.org')])
update_role.user, [sm.find_user(username='gamma')])
self.assertEquals(resp.status_code, 201)

resp = self.client.post(
'/superset/update_role/',
data=json.dumps({
'user_emails': ['alpha@fab.org', 'unknown@fab.org'],
'usernames': ['alpha', 'unknown'],
'role_name': update_role_str
}),
follow_redirects=True
)
self.assertEquals(resp.status_code, 201)
update_role = sm.find_role(update_role_str)
self.assertEquals(
update_role.user, [sm.find_user(email='alpha@fab.org')])
update_role.user, [sm.find_user(username='alpha')])

db.session.delete(update_role)
db.session.commit()
Expand Down

0 comments on commit 9d4c3d8

Please sign in to comment.