From a6405d6b9d2fa8faf749cfea8719baae089df1f9 Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 11:42:57 +0000 Subject: [PATCH 1/5] Ensure precommit works with saxonche in api client --- .pre-commit-config.yaml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 5f6ca32..40ef437 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,3 +1,5 @@ +default_language_version: + python: "3.12" repos: - repo: https://github.com/pre-commit/pre-commit-hooks rev: v5.0.0 @@ -29,7 +31,7 @@ repos: [ "types-requests", "types-ujson", - "ds-caselaw-marklogic-api-client==17.2.0", + "ds-caselaw-marklogic-api-client==27.3.0", ] files: ^src/ From 4578afdb941eef773ada37bf9e7d592f35ff754b Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 11:48:29 +0000 Subject: [PATCH 2/5] 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 From 971cccf61b73c3aba74aa08853858453fdee9a44 Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 12:11:51 +0000 Subject: [PATCH 3/5] Fix trivial docker complaints --- Dockerfile | 2 +- docker-compose.yaml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 9f12309..70c5944 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM python:3.12 as service +FROM python:3.12 AS service RUN pip install poetry==1.6.1 diff --git a/docker-compose.yaml b/docker-compose.yaml index 144e333..70d065a 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,4 +1,3 @@ -version: "3.6" services: service: build: From fd438acef69a4db0d8643ecae9e6f7d862233914 Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 17:02:39 +0000 Subject: [PATCH 4/5] Add datestamps to the lock message --- setup.cfg | 2 +- src/openapi_server/apis/writing_api.py | 5 ++++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/setup.cfg b/setup.cfg index 1b113ef..0934f1d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -2,7 +2,7 @@ where = src [mypy] -python_version = 3.9 +python_version = 3.12 check_untyped_defs = True ignore_missing_imports = True warn_unused_ignores = True diff --git a/src/openapi_server/apis/writing_api.py b/src/openapi_server/apis/writing_api.py index ddbcc74..c53318e 100644 --- a/src/openapi_server/apis/writing_api.py +++ b/src/openapi_server/apis/writing_api.py @@ -1,3 +1,5 @@ +import datetime + from caselawclient.client_helpers import VersionAnnotation, VersionType from caselawclient.models.documents import DocumentURIString from fastapi import ( # noqa: F401 @@ -89,8 +91,9 @@ async def judgment_uri_lock_put( """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}" + now = datetime.datetime.now(tz=datetime.UTC).isoformat() timeout_seconds = int(timeout) + annotation = f"Judgment locked for editing by {token_basic.username} at {now} for {timeout_seconds} seconds" with error_handling(): _ml_response = client.checkout_judgment( judgmentUri, From cb1ebb313e8f3b9466f7c9d2d811be46960c4d1d Mon Sep 17 00:00:00 2001 From: David McKee Date: Wed, 6 Nov 2024 17:14:18 +0000 Subject: [PATCH 5/5] Add DEBUG environment variable locally --- .env.example | 1 + 1 file changed, 1 insertion(+) diff --git a/.env.example b/.env.example index d83bfaa..2b1c753 100644 --- a/.env.example +++ b/.env.example @@ -1,3 +1,4 @@ MARKLOGIC_API_CLIENT_HOST= MARKLOGIC_USER=fake_user MARKLOGIC_PASSWORD=fake_password +DEBUG=True