From 83ac85df3e6b078353ab03829f370a1c0027296b Mon Sep 17 00:00:00 2001 From: Alan Christie Date: Wed, 7 Dec 2022 15:37:02 +0000 Subject: [PATCH] feat: Ability to add/remove Project editors --- README.rst | 2 ++ src/squonk2/dm_api.py | 60 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) diff --git a/README.rst b/README.rst index 43485ab..64487d4 100644 --- a/README.rst +++ b/README.rst @@ -30,6 +30,7 @@ The following Squonk2 Data Manager API functions are available: - - ``DmApi.ping()`` +- ``DmApi.add_project_editor()`` - ``DmApi.create_project()`` - ``DmApi.delete_instance()`` - ``DmApi.delete_instance_token()`` @@ -55,6 +56,7 @@ The following Squonk2 Data Manager API functions are available: - - ``DmApi.get_version()`` - ``DmApi.list_project_files()`` - ``DmApi.put_unmanaged_project_files()`` +- ``DmApi.remove_project_editor()`` - ``DmApi.set_admin_state()`` - ``DmApi.set_job_exchange_rates()`` - ``DmApi.start_job_instance()`` diff --git a/src/squonk2/dm_api.py b/src/squonk2/dm_api.py index 70f296b..16055ae 100644 --- a/src/squonk2/dm_api.py +++ b/src/squonk2/dm_api.py @@ -446,6 +446,66 @@ def delete_project( timeout=timeout_s, )[0] + @classmethod + @synchronized + def add_project_editor( + cls, + access_token: str, + *, + project_id: str, + editor: str, + timeout_s: int = _READ_TIMEOUT_S, + ) -> DmApiRv: + """Adds a user to a Project as an Editor. + + :param access_token: A valid DM API access token. + :param project_id: The Project UUID. + :param editor: The username to add. + :param timeout_s: The API request timeout + """ + assert access_token + assert project_id + assert editor + + return DmApi.__request( + "PUT", + f"/project/{project_id}/editor/{editor}", + access_token=access_token, + expected_response_codes=[201], + error_message="Failed adding project editor", + timeout=timeout_s, + )[0] + + @classmethod + @synchronized + def remove_project_editor( + cls, + access_token: str, + *, + project_id: str, + editor: str, + timeout_s: int = _READ_TIMEOUT_S, + ) -> DmApiRv: + """Removes a user as an Editor from a Project. + + :param access_token: A valid DM API access token. + :param project_id: The Project UUID. + :param editor: The username to remove. + :param timeout_s: The API request timeout + """ + assert access_token + assert project_id + assert editor + + return DmApi.__request( + "DELETE", + f"/project/{project_id}/editor/{editor}", + access_token=access_token, + expected_response_codes=[204], + error_message="Failed removing project editor", + timeout=timeout_s, + )[0] + @classmethod @synchronized def put_unmanaged_project_files(