summaryrefslogtreecommitdiff
path: root/gitlab/v4/objects/users.py
diff options
context:
space:
mode:
authorBen Gamari <ben@smart-cactus.org>2022-06-09 11:11:35 -0400
committerNejc Habjan <nejc.habjan@siemens.com>2022-06-25 17:50:43 +0200
commitf57139d8f1dafa6eb19d0d954b3634c19de6413c (patch)
tree4cca8c42dffae9028b2d91390aed3a60a2e27b36 /gitlab/v4/objects/users.py
parent8f8611a1263b8c19fd19ce4a904a310b0173b6bf (diff)
downloadgitlab-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/v4/objects/users.py')
-rw-r--r--gitlab/v4/objects/users.py36
1 files changed, 36 insertions, 0 deletions
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.