diff options
author | Gauvain Pocentek <gauvain@pocentek.net> | 2016-02-04 22:39:21 +0100 |
---|---|---|
committer | Gauvain Pocentek <gauvain@pocentek.net> | 2016-02-04 22:39:21 +0100 |
commit | e387de528ad21766747b91bb7e1cd91f6e4642b5 (patch) | |
tree | 4492fc98523188635c468a6a5b7bd8f547d0e5c4 | |
parent | 942468d344eac2a70f73ed69a43c27a87baf78db (diff) | |
download | gitlab-e387de528ad21766747b91bb7e1cd91f6e4642b5.tar.gz |
Add support for user block/unblock
-rw-r--r-- | gitlab/exceptions.py | 8 | ||||
-rw-r--r-- | gitlab/objects.py | 14 | ||||
-rw-r--r-- | tools/python_test.py | 3 |
3 files changed, 25 insertions, 0 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 74e6137..1b5ec6a 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -83,6 +83,14 @@ class GitlabBuildRetryError(GitlabOperationError): pass +class GitlabBlockError(GitlabOperationError): + pass + + +class GitlabUnblockError(GitlabOperationError): + pass + + def raise_error_from_response(response, error, expected_code=200): """Tries to parse gitlab error message from response and raises error. diff --git a/gitlab/objects.py b/gitlab/objects.py index f8c102b..a781cb1 100644 --- a/gitlab/objects.py +++ b/gitlab/objects.py @@ -527,6 +527,20 @@ class User(GitlabObject): user_id=self.id, **kwargs) + def block(self, **kwargs): + """Blocks the user.""" + url = '/users/%s/block' % self.id + r = self.gitlab._raw_put(url, **kwargs) + raise_error_from_response(r, GitlabBlockError) + self.state = 'blocked' + + def unblock(self, **kwargs): + """Unblocks the user.""" + url = '/users/%s/unblock' % self.id + r = self.gitlab._raw_put(url, **kwargs) + raise_error_from_response(r, GitlabUnblockError) + self.state = 'active' + class UserManager(BaseManager): obj_cls = User diff --git a/tools/python_test.py b/tools/python_test.py index 8791da2..aa881b1 100644 --- a/tools/python_test.py +++ b/tools/python_test.py @@ -40,6 +40,9 @@ for user in users_list: assert(new_user.username == user.username) assert(new_user.email == user.email) +new_user.block() +new_user.unblock() + # SSH keys key = new_user.keys.create({'title': 'testkey', 'key': SSH_KEY}) assert(len(new_user.keys.list()) == 1) |