Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf47274e

Browse files
committed
users: Add approve and reject methods to User
1 parentae7d3b0 commitf47274e

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

‎docs/gl_objects/users.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ List a user's starred projects
106106

107107
user.starred_projects.list()
108108

109+
Administrators can approve and reject user creation requests
110+
111+
user.approve()
112+
109113
User custom attributes
110114
======================
111115

‎gitlab/exceptions.py‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,6 +285,11 @@ class GitlabFollowError(GitlabOperationError):
285285
classGitlabUnfollowError(GitlabOperationError):
286286
pass
287287

288+
classGitlabUserApproveError(GitlabOperationError):
289+
pass
290+
291+
classGitlabUserRejectError(GitlabOperationError):
292+
pass
288293

289294
# For an explanation of how these type-hints work see:
290295
# https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators

‎gitlab/v4/objects/users.py‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,42 @@ def activate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
283283
self._attrs["state"]="active"
284284
returnserver_data
285285

286+
@cli.register_custom_action("User")
287+
@exc.on_http_error(exc.GitlabUserApproveError)
288+
defapprove(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
289+
"""Approve a user creation request.
290+
291+
Args:
292+
**kwargs: Extra options to send to the server (e.g. sudo)
293+
294+
Raises:
295+
GitlabAuthenticationError: If authentication is not correct
296+
GitlabActivateError: If the user could not be activated
297+
298+
Returns:
299+
The new object data (*not* a RESTObject)
300+
"""
301+
path=f"/users/{self.encoded_id}/approve"
302+
returnself.manager.gitlab.http_post(path,**kwargs)
303+
304+
@cli.register_custom_action("User")
305+
@exc.on_http_error(exc.GitlabUserRejectError)
306+
defreject(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:
307+
"""Reject a user creation request.
308+
309+
Args:
310+
**kwargs: Extra options to send to the server (e.g. sudo)
311+
312+
Raises:
313+
GitlabAuthenticationError: If authentication is not correct
314+
GitlabActivateError: If the user could not be activated
315+
316+
Returns:
317+
The new object data (*not* a RESTObject)
318+
"""
319+
path=f"/users/{self.encoded_id}/reject"
320+
returnself.manager.gitlab.http_post(path,**kwargs)
321+
286322

287323
classUserManager(CRUDMixin,RESTManager):
288324
_path="/users"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp