| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -111,6 +111,13 @@ List a user's starred projects | |||
| 111 | 111 | ||
| 112 | 112 | user.starred_projects.list() | |
| 113 | 113 | ||
| 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 | + | ||
| 114 | 121 | User custom attributes | |
| 115 | 122 | ====================== | |
| 116 | 123 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -298,6 +298,14 @@ class GitlabUnfollowError(GitlabOperationError): | |||
| 298 | 298 | pass | |
| 299 | 299 | ||
| 300 | 300 | ||
| 301 | + class GitlabUserApproveError(GitlabOperationError): | ||
| 302 | + pass | ||
| 303 | + | ||
| 304 | + | ||
| 305 | + class GitlabUserRejectError(GitlabOperationError): | ||
| 306 | + pass | ||
| 307 | + | ||
| 308 | + | ||
| 301 | 309 | # For an explanation of how these type-hints work see: | |
| 302 | 310 | # https://mypy.readthedocs.io/en/stable/generics.html#declaring-decorators | |
| 303 | 311 | # | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -283,6 +283,42 @@ 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.GitlabUserApproveError) | ||
| 288 | + def approve(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 | + return self.manager.gitlab.http_post(path, **kwargs) | ||
| 303 | + | ||
| 304 | + @cli.register_custom_action("User") | ||
| 305 | + @exc.on_http_error(exc.GitlabUserRejectError) | ||
| 306 | + def reject(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 | + return self.manager.gitlab.http_post(path, **kwargs) | ||
| 321 | + | ||
| 286 | 322 | @cli.register_custom_action("User") | |
| 287 | 323 | @exc.on_http_error(exc.GitlabBanError) | |
| 288 | 324 | def ban(self, **kwargs: Any) -> Union[Dict[str, Any], requests.Response]: | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -80,6 +80,32 @@ def resp_activate(): | |||
| 80 | 80 | yield rsps | |
| 81 | 81 | ||
| 82 | 82 | ||
| 83 | + @pytest.fixture | ||
| 84 | + def resp_approve(): | ||
| 85 | + with responses.RequestsMock() as rsps: | ||
| 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 | + yield rsps | ||
| 94 | + | ||
| 95 | + | ||
| 96 | + @pytest.fixture | ||
| 97 | + def resp_reject(): | ||
| 98 | + with responses.RequestsMock() as rsps: | ||
| 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 | + yield rsps | ||
| 107 | + | ||
| 108 | + | ||
| 83 | 109 | @pytest.fixture | |
| 84 | 110 | def resp_ban(): | |
| 85 | 111 | with responses.RequestsMock() as rsps: | |
@@ -242,6 +268,14 @@ def test_user_activate_deactivate(user, resp_activate): | |||
| 242 | 268 | user.deactivate() | |
| 243 | 269 | ||
| 244 | 270 | ||
| 271 | + def test_user_approve_(user, resp_approve): | ||
| 272 | + user.approve() | ||
| 273 | + | ||
| 274 | + | ||
| 275 | + def test_user_approve_reject(user, resp_reject): | ||
| 276 | + user.reject() | ||
| 277 | + | ||
| 278 | + | ||
| 245 | 279 | def test_user_ban(user, resp_ban): | |
| 246 | 280 | user.ban() | |
| 247 | 281 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments