Skip to content
This repository has been archived by the owner on Sep 5, 2019. It is now read-only.

Commit

Permalink
Allows to pass the group when creating users
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Sommerhalder committed Aug 18, 2017
1 parent 7b933bf commit 416723f
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 4 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Changelog
---------

- Allows to pass the group when creating users.
[msom]

0.15.0 (2017-08-17)
~~~~~~~~~~~~~~~~~~~

Expand Down
5 changes: 3 additions & 2 deletions onegov/user/collections/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ def query(self):

def add(self, username, password, role,
data=None, second_factor=None, active=True, realname=None,
signup_token=None):
signup_token=None, group=None):
""" Add a user to the collection.
The arguments given to this function are the attributes of the
Expand All @@ -109,7 +109,8 @@ def add(self, username, password, role,
second_factor=second_factor,
active=active,
realname=realname,
signup_token=signup_token
signup_token=signup_token,
group_id=group.id if group else None
)

self.session.add(user)
Expand Down
6 changes: 6 additions & 0 deletions onegov/user/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ def test_user_add(session):

assert users.by_username(user.username).username == 'dmr@example.org'

groups = UserGroupCollection(session)
group = groups.add(name='group')

user = users.add('abc@example.org', 'p@ssw0rd', 'root', group=group)
assert users.by_username(user.username).group.name == 'group'


def test_user_add_conflict(session):

Expand Down

0 comments on commit 416723f

Please sign in to comment.