Loading docs/gl_objects/users.rst +5 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,11 @@ Block/Unblock a user:: user.block() user.unblock() Activate/Deactivate a user:: user.activate() user.deactivate() Set the avatar image for a user:: # the avatar image can be passed as data (content of the file) or as a file Loading gitlab/exceptions.py +8 −0 Original line number Diff line number Diff line Loading @@ -157,6 +157,14 @@ class GitlabUnblockError(GitlabOperationError): pass class GitlabDeactivateError(GitlabOperationError): pass class GitlabActivateError(GitlabOperationError): pass class GitlabSubscribeError(GitlabOperationError): pass Loading gitlab/tests/test_gitlab.py +25 −0 Original line number Diff line number Diff line Loading @@ -695,6 +695,31 @@ class TestGitlab(unittest.TestCase): deployment.save() self.assertEqual(deployment.status, "failed") def test_user_activate_deactivate(self): @urlmatch( scheme="http", netloc="localhost", path="/api/v4/users/1/activate", method="post", ) def resp_activate(url, request): headers = {"content-type": "application/json"} return response(201, {}, headers, None, 5, request) @urlmatch( scheme="http", netloc="localhost", path="/api/v4/users/1/deactivate", method="post", ) def resp_deactivate(url, request): headers = {"content-type": "application/json"} return response(201, {}, headers, None, 5, request) with HTTMock(resp_activate), HTTMock(resp_deactivate): self.gl.users.get(1, lazy=True).activate() self.gl.users.get(1, lazy=True).deactivate() def test_update_submodule(self): @urlmatch( scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" Loading gitlab/v4/objects.py +42 −0 Original line number Diff line number Diff line Loading @@ -340,6 +340,48 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): self._attrs["state"] = "active" return server_data @cli.register_custom_action("User") @exc.on_http_error(exc.GitlabDeactivateError) def deactivate(self, **kwargs): """Deactivate the user. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeactivateError: If the user could not be deactivated Returns: bool: Whether the user status has been changed """ path = "/users/%s/deactivate" % self.id server_data = self.manager.gitlab.http_post(path, **kwargs) if server_data: self._attrs["state"] = "deactivated" return server_data @cli.register_custom_action("User") @exc.on_http_error(exc.GitlabActivateError) def activate(self, **kwargs): """Activate the user. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabActivateError: If the user could not be activated Returns: bool: Whether the user status has been changed """ path = "/users/%s/activate" % self.id server_data = self.manager.gitlab.http_post(path, **kwargs) if server_data: self._attrs["state"] = "active" return server_data class UserManager(CRUDMixin, RESTManager): _path = "/users" Loading Loading
docs/gl_objects/users.rst +5 −0 Original line number Diff line number Diff line Loading @@ -62,6 +62,11 @@ Block/Unblock a user:: user.block() user.unblock() Activate/Deactivate a user:: user.activate() user.deactivate() Set the avatar image for a user:: # the avatar image can be passed as data (content of the file) or as a file Loading
gitlab/exceptions.py +8 −0 Original line number Diff line number Diff line Loading @@ -157,6 +157,14 @@ class GitlabUnblockError(GitlabOperationError): pass class GitlabDeactivateError(GitlabOperationError): pass class GitlabActivateError(GitlabOperationError): pass class GitlabSubscribeError(GitlabOperationError): pass Loading
gitlab/tests/test_gitlab.py +25 −0 Original line number Diff line number Diff line Loading @@ -695,6 +695,31 @@ class TestGitlab(unittest.TestCase): deployment.save() self.assertEqual(deployment.status, "failed") def test_user_activate_deactivate(self): @urlmatch( scheme="http", netloc="localhost", path="/api/v4/users/1/activate", method="post", ) def resp_activate(url, request): headers = {"content-type": "application/json"} return response(201, {}, headers, None, 5, request) @urlmatch( scheme="http", netloc="localhost", path="/api/v4/users/1/deactivate", method="post", ) def resp_deactivate(url, request): headers = {"content-type": "application/json"} return response(201, {}, headers, None, 5, request) with HTTMock(resp_activate), HTTMock(resp_deactivate): self.gl.users.get(1, lazy=True).activate() self.gl.users.get(1, lazy=True).deactivate() def test_update_submodule(self): @urlmatch( scheme="http", netloc="localhost", path="/api/v4/projects/1$", method="get" Loading
gitlab/v4/objects.py +42 −0 Original line number Diff line number Diff line Loading @@ -340,6 +340,48 @@ class User(SaveMixin, ObjectDeleteMixin, RESTObject): self._attrs["state"] = "active" return server_data @cli.register_custom_action("User") @exc.on_http_error(exc.GitlabDeactivateError) def deactivate(self, **kwargs): """Deactivate the user. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabDeactivateError: If the user could not be deactivated Returns: bool: Whether the user status has been changed """ path = "/users/%s/deactivate" % self.id server_data = self.manager.gitlab.http_post(path, **kwargs) if server_data: self._attrs["state"] = "deactivated" return server_data @cli.register_custom_action("User") @exc.on_http_error(exc.GitlabActivateError) def activate(self, **kwargs): """Activate the user. Args: **kwargs: Extra options to send to the server (e.g. sudo) Raises: GitlabAuthenticationError: If authentication is not correct GitlabActivateError: If the user could not be activated Returns: bool: Whether the user status has been changed """ path = "/users/%s/activate" % self.id server_data = self.manager.gitlab.http_post(path, **kwargs) if server_data: self._attrs["state"] = "active" return server_data class UserManager(CRUDMixin, RESTManager): _path = "/users" Loading