| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -62,6 +62,11 @@ Block/Unblock a user:: | |||
| 62 | 62 | user.block() | |
| 63 | 63 | user.unblock() | |
| 64 | 64 | ||
| 65 | + Activate/Deactivate a user:: | ||
| 66 | + | ||
| 67 | + user.activate() | ||
| 68 | + user.deactivate() | ||
| 69 | + | ||
| 65 | 70 | Set the avatar image for a user:: | |
| 66 | 71 | ||
| 67 | 72 | # the avatar image can be passed as data (content of the file) or as a file | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -157,6 +157,14 @@ class GitlabUnblockError(GitlabOperationError): | |||
| 157 | 157 | pass | |
| 158 | 158 | ||
| 159 | 159 | ||
| 160 | + class GitlabDeactivateError(GitlabOperationError): | ||
| 161 | + pass | ||
| 162 | + | ||
| 163 | + | ||
| 164 | + class GitlabActivateError(GitlabOperationError): | ||
| 165 | + pass | ||
| 166 | + | ||
| 167 | + | ||
| 160 | 168 | class GitlabSubscribeError(GitlabOperationError): | |
| 161 | 169 | pass | |
| 162 | 170 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -695,6 +695,31 @@ def resp_deployment_update(url, request): | |||
| 695 | 695 | deployment.save() | |
| 696 | 696 | self.assertEqual(deployment.status, "failed") | |
| 697 | 697 | ||
| 698 | + def test_user_activate_deactivate(self): | ||
| 699 | + @urlmatch( | ||
| 700 | + scheme="http", | ||
| 701 | + netloc="localhost", | ||
| 702 | + path="/api/v4/users/1/activate", | ||
| 703 | + method="post", | ||
| 704 | + ) | ||
| 705 | + def resp_activate(url, request): | ||
| 706 | + headers = {"content-type": "application/json"} | ||
| 707 | + return response(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 | + def resp_deactivate(url, request): | ||
| 716 | + headers = {"content-type": "application/json"} | ||
| 717 | + return response(201, {}, headers, None, 5, request) | ||
| 718 | + | ||
| 719 | + with HTTMock(resp_activate), HTTMock(resp_deactivate): | ||
| 720 | + self.gl.users.get(1, lazy=True).activate() | ||
| 721 | + self.gl.users.get(1, lazy=True).deactivate() | ||
| 722 | + | ||
| 698 | 723 | def test_update_submodule(self): | |
| 699 | 724 | @urlmatch( | |
| 700 | 725 | scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -340,6 +340,48 @@ def unblock(self, **kwargs): | |||
| 340 | 340 | self._attrs["state"] = "active" | |
| 341 | 341 | return server_data | |
| 342 | 342 | ||
| 343 | + @cli.register_custom_action("User") | ||
| 344 | + @exc.on_http_error(exc.GitlabDeactivateError) | ||
| 345 | + def deactivate(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 | + if server_data: | ||
| 361 | + self._attrs["state"] = "deactivated" | ||
| 362 | + return server_data | ||
| 363 | + | ||
| 364 | + @cli.register_custom_action("User") | ||
| 365 | + @exc.on_http_error(exc.GitlabActivateError) | ||
| 366 | + def activate(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 | + if server_data: | ||
| 382 | + self._attrs["state"] = "active" | ||
| 383 | + return server_data | ||
| 384 | + | ||
| 343 | 385 | ||
| 344 | 386 | class UserManager(CRUDMixin, RESTManager): | |
| 345 | 387 | _path = "/users" | |
| Back | FazBrowse Home | New Git URL |
0 commit comments