@@ -283,6 +283,48 @@ def activate(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]:
283
283
self ._attrs ["state" ] = "active"
284
284
return server_data
285
285
286
+ @cli .register_custom_action ("User" )
287
+ @exc .on_http_error (exc .GitlabBanError )
288
+ def ban (self , ** kwargs : Any ) -> Union [Dict [str , Any ], requests .Response ]:
289
+ """Ban the user.
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
+ GitlabBanError: If the user could not be banned
297
+
298
+ Returns:
299
+ Whether the user has been banned
300
+ """
301
+ path = f"/users/{ self .encoded_id } /ban"
302
+ server_data = self .manager .gitlab .http_post (path , ** kwargs )
303
+ if server_data :
304
+ self ._attrs ["state" ] = "banned"
305
+ return server_data
306
+
307
+ @cli .register_custom_action ("User" )
308
+ @exc .on_http_error (exc .GitlabUnbanError )
309
+ def unban (self , ** kwargs : Any ) -> Union [Dict [str , Any ], requests .Response ]:
310
+ """Unban the user.
311
+
312
+ Args:
313
+ **kwargs: Extra options to send to the server (e.g. sudo)
314
+
315
+ Raises:
316
+ GitlabAuthenticationError: If authentication is not correct
317
+ GitlabUnbanError: If the user could not be unbanned
318
+
319
+ Returns:
320
+ Whether the user has been unbanned
321
+ """
322
+ path = f"/users/{ self .encoded_id } /unban"
323
+ server_data = self .manager .gitlab .http_post (path , ** kwargs )
324
+ if server_data :
325
+ self ._attrs ["state" ] = "active"
326
+ return server_data
327
+
286
328
287
329
class UserManager (CRUDMixin , RESTManager ):
288
330
_path = "/users"
0 commit comments