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

Commit32ad669

Browse files
committed
feat: add users activate, deactivate functionality
These were introduced in GitLab 12.4
1 parentac2266b commit32ad669

File tree

4 files changed

+80
-0
lines changed

4 files changed

+80
-0
lines changed

‎docs/gl_objects/users.rst‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ Block/Unblock a user::
6262
user.block()
6363
user.unblock()
6464

65+
Activate/Deactivate a user::
66+
67+
user.activate()
68+
user.deactivate()
69+
6570
Set the avatar image for a user::
6671

6772
# the avatar image can be passed as data (content of the file) or as a file

‎gitlab/exceptions.py‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,14 @@ class GitlabUnblockError(GitlabOperationError):
157157
pass
158158

159159

160+
classGitlabDeactivateError(GitlabOperationError):
161+
pass
162+
163+
164+
classGitlabActivateError(GitlabOperationError):
165+
pass
166+
167+
160168
classGitlabSubscribeError(GitlabOperationError):
161169
pass
162170

‎gitlab/tests/test_gitlab.py‎

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,31 @@ def resp_deployment_update(url, request):
695695
deployment.save()
696696
self.assertEqual(deployment.status,"failed")
697697

698+
deftest_user_activate_deactivate(self):
699+
@urlmatch(
700+
scheme="http",
701+
netloc="localhost",
702+
path="/api/v4/users/1/activate",
703+
method="post",
704+
)
705+
defresp_activate(url,request):
706+
headers= {"content-type":"application/json"}
707+
returnresponse(201, {},headers,None,5,request)
708+
709+
@urlmatch(
710+
scheme="http",
711+
netloc="localhost",
712+
path="/api/v4/users/1/deactivate",
713+
method="post",
714+
)
715+
defresp_deactivate(url,request):
716+
headers= {"content-type":"application/json"}
717+
returnresponse(201, {},headers,None,5,request)
718+
719+
withHTTMock(resp_activate),HTTMock(resp_deactivate):
720+
self.gl.users.get(1,lazy=True).activate()
721+
self.gl.users.get(1,lazy=True).deactivate()
722+
698723
deftest_update_submodule(self):
699724
@urlmatch(
700725
scheme="http",netloc="localhost",path="/api/v4/projects/1$",method="get"

‎gitlab/v4/objects.py‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,48 @@ def unblock(self, **kwargs):
340340
self._attrs["state"]="active"
341341
returnserver_data
342342

343+
@cli.register_custom_action("User")
344+
@exc.on_http_error(exc.GitlabDeactivateError)
345+
defdeactivate(self,**kwargs):
346+
"""Deactivate the user.
347+
348+
Args:
349+
**kwargs: Extra options to send to the server (e.g. sudo)
350+
351+
Raises:
352+
GitlabAuthenticationError: If authentication is not correct
353+
GitlabDeactivateError: If the user could not be deactivated
354+
355+
Returns:
356+
bool: Whether the user status has been changed
357+
"""
358+
path="/users/%s/deactivate"%self.id
359+
server_data=self.manager.gitlab.http_post(path,**kwargs)
360+
ifserver_data:
361+
self._attrs["state"]="deactivated"
362+
returnserver_data
363+
364+
@cli.register_custom_action("User")
365+
@exc.on_http_error(exc.GitlabActivateError)
366+
defactivate(self,**kwargs):
367+
"""Activate the user.
368+
369+
Args:
370+
**kwargs: Extra options to send to the server (e.g. sudo)
371+
372+
Raises:
373+
GitlabAuthenticationError: If authentication is not correct
374+
GitlabActivateError: If the user could not be activated
375+
376+
Returns:
377+
bool: Whether the user status has been changed
378+
"""
379+
path="/users/%s/activate"%self.id
380+
server_data=self.manager.gitlab.http_post(path,**kwargs)
381+
ifserver_data:
382+
self._attrs["state"]="active"
383+
returnserver_data
384+
343385

344386
classUserManager(CRUDMixin,RESTManager):
345387
_path="/users"

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp