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

Commite387de5

Browse files
author
Gauvain Pocentek
committed
Add support for user block/unblock
1 parent942468d commite387de5

File tree

3 files changed

+25
-0
lines changed

3 files changed

+25
-0
lines changed

‎gitlab/exceptions.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ class GitlabBuildRetryError(GitlabOperationError):
8383
pass
8484

8585

86+
classGitlabBlockError(GitlabOperationError):
87+
pass
88+
89+
90+
classGitlabUnblockError(GitlabOperationError):
91+
pass
92+
93+
8694
defraise_error_from_response(response,error,expected_code=200):
8795
"""Tries to parse gitlab error message from response and raises error.
8896

‎gitlab/objects.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,20 @@ def Key(self, id=None, **kwargs):
527527
user_id=self.id,
528528
**kwargs)
529529

530+
defblock(self,**kwargs):
531+
"""Blocks the user."""
532+
url='/users/%s/block'%self.id
533+
r=self.gitlab._raw_put(url,**kwargs)
534+
raise_error_from_response(r,GitlabBlockError)
535+
self.state='blocked'
536+
537+
defunblock(self,**kwargs):
538+
"""Unblocks the user."""
539+
url='/users/%s/unblock'%self.id
540+
r=self.gitlab._raw_put(url,**kwargs)
541+
raise_error_from_response(r,GitlabUnblockError)
542+
self.state='active'
543+
530544

531545
classUserManager(BaseManager):
532546
obj_cls=User

‎tools/python_test.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@
4040
assert(new_user.username==user.username)
4141
assert(new_user.email==user.email)
4242

43+
new_user.block()
44+
new_user.unblock()
45+
4346
# SSH keys
4447
key=new_user.keys.create({'title':'testkey','key':SSH_KEY})
4548
assert(len(new_user.keys.list())==1)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp