Skip to content

Commit

Permalink
Make organization owner admin user by default
Browse files Browse the repository at this point in the history
Where this function is used by other model classes `is_admin` may be
missing, so a conditional check is necessary first.

Closes bennylopegh-97
  • Loading branch information
bennylope committed Apr 4, 2016
1 parent 92f01f3 commit 701d530
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion organizations/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,10 @@ def create_organization(user, name, slug=None, is_active=None,
if org_defaults is None:
org_defaults = {}
if org_user_defaults is None:
org_user_defaults = {}
if 'is_admin' in org_user_model._meta.get_all_field_names():
org_user_defaults = {'is_admin': True}
else:
org_user_defaults = {}

if slug is not None:
org_defaults.update({'slug': slug})
Expand Down
1 change: 1 addition & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def test_create_organization(self):
acme = create_organization(self.user, "Acme", org_defaults={"slug": "acme-slug"})
self.assertTrue(isinstance(acme, Organization))
self.assertEqual(self.user, acme.owner.organization_user.user)
self.assertTrue(acme.owner.organization_user.is_admin)

def test_create_custom_org(self):
custom = create_organization(self.user, "Custom", model=Account)
Expand Down

0 comments on commit 701d530

Please sign in to comment.