Skip to content

Commit

Permalink
feat: Ability to add/remove Project editors
Browse files Browse the repository at this point in the history
  • Loading branch information
Alan Christie committed Dec 7, 2022
1 parent da818a9 commit 83ac85d
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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()``
Expand All @@ -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()``
Expand Down
60 changes: 60 additions & 0 deletions src/squonk2/dm_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 83ac85d

Please sign in to comment.