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

Commitf57139d

Browse files
bgamariJohnVillalovos
authored andcommitted
feat(users): add approve and reject methods to User
As requested in#1604.Co-authored-by: John Villalovos <john@sodarock.com>
1 parent8f8611a commitf57139d

File tree

4 files changed

+85
-0
lines changed

4 files changed

+85
-0
lines changed

‎docs/gl_objects/users.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,13 @@ List a user's starred projects
111111

112112
user.starred_projects.list()
113113

114+
If the GitLab instance has new user account approval enabled some users may
115+
have ``user.state == 'blocked_pending_approval'``. Administrators can approve
116+
and reject such users::
117+
118+
user.approve()
119+
user.reject()
120+
114121
User custom attributes
115122
======================
116123

‎gitlab/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,14 @@ class GitlabUnfollowError(GitlabOperationError):
294294
pass
295295

296296

297+
classGitlabUserApproveError(GitlabOperationError):
298+
pass
299+
300+
301+
classGitlabUserRejectError(GitlabOperationError):
302+
pass
303+
304+
297305
# For an explanation of how these type-hints work see:
298306
# https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators
299307
#

‎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+
GitlabUserApproveError: 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+
GitlabUserRejectError: If the user could not be rejected
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
@cli.register_custom_action("User")
287323
@exc.on_http_error(exc.GitlabBanError)
288324
defban(self,**kwargs:Any)->Union[Dict[str,Any],requests.Response]:

‎tests/unit/objects/test_users.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,32 @@ def resp_activate():
8080
yieldrsps
8181

8282

83+
@pytest.fixture
84+
defresp_approve():
85+
withresponses.RequestsMock()asrsps:
86+
rsps.add(
87+
method=responses.POST,
88+
url="http://localhost/api/v4/users/1/approve",
89+
json={"message":"Success"},
90+
content_type="application/json",
91+
status=201,
92+
)
93+
yieldrsps
94+
95+
96+
@pytest.fixture
97+
defresp_reject():
98+
withresponses.RequestsMock()asrsps:
99+
rsps.add(
100+
method=responses.POST,
101+
url="http://localhost/api/v4/users/1/reject",
102+
json={"message":"Success"},
103+
content_type="application/json",
104+
status=201,
105+
)
106+
yieldrsps
107+
108+
83109
@pytest.fixture
84110
defresp_ban():
85111
withresponses.RequestsMock()asrsps:
@@ -242,6 +268,14 @@ def test_user_activate_deactivate(user, resp_activate):
242268
user.deactivate()
243269

244270

271+
deftest_user_approve_(user,resp_approve):
272+
user.approve()
273+
274+
275+
deftest_user_approve_reject(user,resp_reject):
276+
user.reject()
277+
278+
245279
deftest_user_ban(user,resp_ban):
246280
user.ban()
247281

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp