From 4578afdb941eef773ada37bf9e7d592f35ff754b Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 11:48:29 +0000 Subject: [PATCH] Add 15 minute default timeout to checkout/lock --- openapi.yaml | 6 ++++++ pyproject.toml | 2 +- src/openapi_server/apis/writing_api.py | 8 +++----- tests/test_writing_api.py | 10 +++++----- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/openapi.yaml b/openapi.yaml index dcec110..1789213 100644 --- a/openapi.yaml +++ b/openapi.yaml @@ -159,6 +159,12 @@ paths: schema: type: string style: simple + - name: timeout + schema: + type: int + required: false + in: query + description: After this many seconds, the judgment will be unlocked. Defaults to 900 (15 minutes). responses: "201": description: "A single judgment document, in Akoma Ntoso XML" diff --git a/pyproject.toml b/pyproject.toml index 39ae0e7..afe228c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -3,7 +3,7 @@ requires-python = ">=3.12, <4" [tool.poetry] name = "ds-caselaw-privileged-api" -version = "0.3.0" +version = "0.4.0" description = "" authors = ["David McKee "] license = "MIT" diff --git a/src/openapi_server/apis/writing_api.py b/src/openapi_server/apis/writing_api.py index 290b228..ddbcc74 100644 --- a/src/openapi_server/apis/writing_api.py +++ b/src/openapi_server/apis/writing_api.py @@ -84,20 +84,18 @@ async def judgment_uri_lock_put( response: Response, judgmentUri: DocumentURIString, token_basic: TokenModel = SECURITY_TOKEN_MODEL, - expires="0", + timeout: str = "900", # noqa: ASYNC109 ): """Locks edit access for a document for the current client. Returns the latest version of the locked document, along with the new lock state.""" client = client_for_basic_auth(token_basic) annotation = f"Judgment locked for editing by {token_basic.username}" - expires = bool( - int(expires), - ) # If expires is True then the lock will expire at midnight, otherwise the lock is permanent + timeout_seconds = int(timeout) with error_handling(): _ml_response = client.checkout_judgment( judgmentUri, annotation, - expires, + timeout_seconds=timeout_seconds, ) judgment = client.get_judgment_xml(judgmentUri, show_unpublished=True) return Response(status_code=201, content=judgment, media_type="application/xml") diff --git a/tests/test_writing_api.py b/tests/test_writing_api.py index fb170d6..671fb0a 100644 --- a/tests/test_writing_api.py +++ b/tests/test_writing_api.py @@ -82,7 +82,7 @@ def test_put_lock_success(mocked_client): mocked_client.return_value.checkout_judgment.assert_called_with( "judgment/uri", "Judgment locked for editing by user", - False, + timeout_seconds=900, ) assert response.status_code == 201 assert "" in response.text @@ -90,19 +90,19 @@ def test_put_lock_success(mocked_client): @patch("openapi_server.apis.writing_api.client_for_basic_auth") def test_put_lock_success_temporary(mocked_client): - """If expires is passed, the lock will expire""" + """If timeout is passed, the lock will expire""" mocked_client.return_value.checkout_judgment.return_value = None mocked_client.return_value.get_judgment_xml.return_value = b"" response = TestClient(app).request( "PUT", "/lock/judgment/uri", auth=("user", "pass"), - params={"expires": "1"}, + params={"timeout": "123"}, ) mocked_client.return_value.checkout_judgment.assert_called_with( "judgment/uri", "Judgment locked for editing by user", - True, + timeout_seconds=123, ) assert response.status_code == 201 assert "" in response.text @@ -123,7 +123,7 @@ def test_put_lock_failure(mocked_client): mocked_client.return_value.checkout_judgment.assert_called_with( "judgment/uri", "Judgment locked for editing by user", - False, + timeout_seconds=900, ) assert response.status_code == 409 assert "resource is locked by another user" in response.text