diff options
Diffstat (limited to 'gitlab')
-rw-r--r-- | gitlab/exceptions.py | 8 | ||||
-rw-r--r-- | gitlab/objects.py | 14 |
2 files changed, 22 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 |