diff options
| author | Ben Gamari <ben@smart-cactus.org> | 2022-06-09 11:11:35 -0400 |
|---|---|---|
| committer | Nejc Habjan <nejc.habjan@siemens.com> | 2022-06-25 17:50:43 +0200 |
| commit | f57139d8f1dafa6eb19d0d954b3634c19de6413c (patch) | |
| tree | 4cca8c42dffae9028b2d91390aed3a60a2e27b36 /gitlab | |
| parent | 8f8611a1263b8c19fd19ce4a904a310b0173b6bf (diff) | |
| download | gitlab-f57139d8f1dafa6eb19d0d954b3634c19de6413c.tar.gz | |
feat(users): add approve and reject methods to User
As requested in #1604.
Co-authored-by: John Villalovos <john@sodarock.com>
Diffstat (limited to 'gitlab')
| -rw-r--r-- | gitlab/exceptions.py | 8 | ||||
| -rw-r--r-- | gitlab/v4/objects/users.py | 36 |
2 files changed, 44 insertions, 0 deletions
diff --git a/gitlab/exceptions.py b/gitlab/exceptions.py index 602a452..1f7999e 100644 --- a/gitlab/exceptions.py +++ b/gitlab/exceptions.py @@ -294,6 +294,14 @@ class GitlabUnfollowError(GitlabOperationError): pass +class GitlabUserApproveError(GitlabOperationError): + pass + + +class GitlabUserRejectError(GitlabOperationError): + pass + + # For an explanation of how these type-hints work see: # https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators # diff --git a/gitlab/v4/objects/users.py b/gitlab/v4/objects/users.py index 9e76bd5..bef9fbe 100644 --- a/gitlab/v4/objects/users.py +++ b/gitlab/v4/objects/users.py @@ -284,6 +284,42 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): return server_data @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabUserApproveError) + def approve(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: + """Approve a user creation request. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabUserApproveError: If the user could not be activated + + Returns: + The new object data (*not* a RESTObject) + """ + path = f"/users/{self.encoded_id}/approve" + return self.manager.gitlab.http_post(path, **kwargs) + + @cli.register_custom_action("User") + @exc.on_http_error(exc.GitlabUserRejectError) + def reject(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: + """Reject a user creation request. + + Args: + **kwargs: Extra options to send to the server (e.g. sudo) + + Raises: + GitlabAuthenticationError: If authentication is not correct + GitlabUserRejectError: If the user could not be rejected + + Returns: + The new object data (*not* a RESTObject) + """ + path = f"/users/{self.encoded_id}/reject" + return self.manager.gitlab.http_post(path, **kwargs) + + @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. |
