use user.org instead of passing org as a separate argument

This commit is contained in:
Kumar Vora 2016-05-20 14:28:08 -05:00
parent ad85b9a62c
commit c1c2db4a73
3 changed files with 10 additions and 12 deletions

View File

@ -89,7 +89,7 @@ def idp_initiated():
if 'RedashGroups' in authn_response.ava:
group_names = authn_response.ava.get('RedashGroups')
user.update_group_assignments(group_names, current_org)
user.update_group_assignments(group_names)
url = url_for('redash.index')

View File

@ -337,9 +337,9 @@ class User(ModelTimestampsMixin, BaseModel, BelongsToOrgMixin, UserMixin, Permis
def verify_password(self, password):
return self.password_hash and pwd_context.verify(password, self.password_hash)
def update_group_assignments(self, group_names, org):
groups = Group.find_by_name(org, group_names)
groups.append(org.default_group)
def update_group_assignments(self, group_names):
groups = Group.find_by_name(self.org, group_names)
groups.append(self.org.default_group)
self.groups = map(lambda g: g.id, groups)
self.save()

View File

@ -416,19 +416,17 @@ class TestQueryAll(BaseTestCase):
class TestUser(BaseTestCase):
def test_default_group_always_added(self):
user = self.factory.user
org1 = self.factory.create_org()
user = self.factory.create_user()
user.update_group_assignments(["g_unknown"], org1)
self.assertItemsEqual([org1.default_group.id], user.groups)
user.update_group_assignments(["g_unknown"])
self.assertItemsEqual([user.org.default_group.id], user.groups)
def test_update_group_assignments(self):
user = self.factory.user
org1 = self.factory.create_org()
new_group = models.Group.create(id='999', name="g1", org=org1)
new_group = models.Group.create(id='999', name="g1", org=user.org)
user.update_group_assignments(["g1"], org1)
self.assertItemsEqual([org1.default_group.id, new_group.id], user.groups)
user.update_group_assignments(["g1"], user.org)
self.assertItemsEqual([user.org.default_group.id, new_group.id], user.groups)
class TestGroup(BaseTestCase):