diff options
| author | Antoine Auger <antoineauger@users.noreply.github.com> | 2022-06-13 11:12:02 +0200 |
|---|---|---|
| committer | Antoine Auger <antoineauger@users.noreply.github.com> | 2022-06-13 11:22:07 +0200 |
| commit | 0d44b118f85f92e7beb1a05a12bdc6e070dce367 (patch) | |
| tree | 008938e9b2fd1515b8f49cc832c0fc733a73b05e /gitlab/v4/objects | |
| parent | 384031c530e813f55da52f2b2c5635ea935f9d91 (diff) | |
| download | gitlab-0d44b118f85f92e7beb1a05a12bdc6e070dce367.tar.gz | |
feat(users): add ban and unban methods
Diffstat (limited to 'gitlab/v4/objects')
| -rw-r--r-- | gitlab/v4/objects/users.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py index acd3b2f..9e76bd5 100644 --- a/gitlab/v4/objects/users.py +++ b/gitlab/v4/objects/users.py @@ -283,6 +283,48 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): self._attrs["state"] = "active" return server_data + @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabBanError) + def ban(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: + """Ban the user. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabBanError: If the user could not be banned + + Returns: + Whether the user has been banned + """ + path = f"/users/{self.encoded_id}/ban" + server_data = self.manager.gitlab.http_post(path, **kwargs) + if server_data: + self._attrs["state"] = "banned" + return server_data + + @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabUnbanError) + def unban(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: + """Unban the user. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabUnbanError: If the user could not be unbanned + + Returns: + Whether the user has been unbanned + """ + path = f"/users/{self.encoded_id}/unban" + 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" |
