diff options
| author | Max Wittig <max.wittig@siemens.com> | 2019-10-25 11:13:06 +0200 |
|---|---|---|
| committer | Max Wittig <max.wittig@siemens.com> | 2019-10-25 11:13:06 +0200 |
| commit | 32ad66921e408f6553b9d60b6b4833ed3180f549 (patch) | |
| tree | dc0b664dd13b17f9584971f2c730ad5b0b55ad84 /gitlab/v4/objects.py | |
| parent | ac2266b66553cec11740bd5246e23d649606b5ef (diff) | |
| download | gitlab-32ad66921e408f6553b9d60b6b4833ed3180f549.tar.gz | |
feat: add users activate, deactivate functionality
These were introduced in GitLab 12.4
Diffstat (limited to 'gitlab/v4/objects.py')
| -rw-r--r-- | gitlab/v4/objects.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gitlab/v4/objects.py b/gitlab/v4/objects.py index 474cc2b..fcac301 100644 --- a/gitlab/v4/objects.py +++ b/gitlab/v4/objects.py @@ -340,6 +340,48 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): self._attrs["state"] = "active" return server_data + @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabDeactivateError) + def deactivate(self, **kwargs): + """Deactivate the user. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabDeactivateError: If the user could not be deactivated + + Returns: + bool: Whether the user status has been changed + """ + path = "/users/%s/deactivate" % self.id + server_data = self.manager.gitlab.http_post(path, **kwargs) + if server_data: + self._attrs["state"] = "deactivated" + return server_data + + @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabActivateError) + def activate(self, **kwargs): + """Activate the user. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabActivateError: If the user could not be activated + + Returns: + bool: Whether the user status has been changed + """ + path = "/users/%s/activate" % self.id + server_data = self.manager.gitlab.http_post(path, **kwargs) + if server_data: + self._attrs["state"] = "active" + return server_data + class UserManager(CRUDMixin, RESTManager): _path = "/users" |
