From 8288b6e0f2ad6dca894d8ee131b8071bb34eb561 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 11 Nov 2024 18:23:02 -0500 Subject: [PATCH 1/4] add helper for ensuring rights acts are active --- process_request/helpers.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/process_request/helpers.py b/process_request/helpers.py index 88156c9..7df1ee0 100644 --- a/process_request/helpers.py +++ b/process_request/helpers.py @@ -1,5 +1,6 @@ import json import re +from datetime import datetime import inflect import shortuuid @@ -17,6 +18,16 @@ CLOSED_TEXT = ["Restricted"] +def get_active_rights_acts(acts): + """Evaluates rights statement act end dates to determine if it is still active.""" + current_date = datetime.now() + for idx, act in reversed(list(enumerate(acts))): + statement_end = datetime.strptime(act['end_date'], "%Y-%m-%d") + if (current_date > statement_end): + acts.pop(idx) + return acts + + def get_container_indicators(item_json): """Returns container indicator(s) for an archival object. @@ -260,9 +271,10 @@ def get_rights_status(item_json, client): status = None if item_json.get("rights_statements"): for stmnt in item_json["rights_statements"]: - if any([act["restriction"].lower() == "disallow" for act in stmnt.get("acts", [])]): + active_acts = get_active_rights_acts(stmnt.get("acts", [])) + if any([act["restriction"].lower() == "disallow" for act in active_acts]): status = "closed" - elif any([act["restriction"].lower() == "conditional" for act in stmnt.get("acts", [])]): + elif any([act["restriction"].lower() == "conditional" for act in active_acts]): status = "conditional" elif [n for n in item_json.get("notes", []) if n.get("type") == "accessrestrict"]: notes = [n for n in item_json["notes"] if n.get("type") == "accessrestrict"] From 5580da1076b98e2a020e1e81748f9e2b1196c58f Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 11 Nov 2024 18:23:34 -0500 Subject: [PATCH 2/4] add tests --- process_request/tests.py | 99 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 93 insertions(+), 6 deletions(-) diff --git a/process_request/tests.py b/process_request/tests.py index acfce0d..0810f37 100644 --- a/process_request/tests.py +++ b/process_request/tests.py @@ -12,12 +12,13 @@ from django.urls import reverse from rest_framework.test import APIRequestFactory -from .helpers import (get_container_indicators, get_dates, get_file_versions, - get_formatted_resource_id, get_instance_data, - get_locations, get_parent_title, get_preferred_format, - get_resource_creators, get_restricted_in_container, - get_rights_info, get_rights_status, get_rights_text, - get_size, indicator_to_integer, prepare_values) +from .helpers import (get_active_rights_acts, get_container_indicators, + get_dates, get_file_versions, get_formatted_resource_id, + get_instance_data, get_locations, get_parent_title, + get_preferred_format, get_resource_creators, + get_restricted_in_container, get_rights_info, + get_rights_status, get_rights_text, get_size, + indicator_to_integer, prepare_values) from .models import User from .routines import AeonRequester, Mailer, Processor from .test_helpers import json_from_fixture, random_list, random_string @@ -55,6 +56,92 @@ def setUp(self): password=settings.ARCHIVESSPACE["password"], repository=settings.ARCHIVESSPACE["repo_id"]).client + def test_get_active_rights_acts(self): + """Assert """ + acts = [ + { + 'start_date': '1886-01-01', + 'end_date': '1967-12-31', + 'created_by': 'aquarius', + 'last_modified_by': 'aquarius', + 'create_time': '2022-06-08T20:55:05Z', + 'system_mtime': '2022-06-08T20:55:05Z', + 'user_mtime': '2022-06-08T20:55:05Z', + 'act_type': 'publish', + 'restriction': + 'disallow', + 'jsonmodel_type': + 'rights_statement_act', + 'notes': [] + }, + { + 'start_date': '1886-01-01', + 'end_date': '2020-12-31', + 'created_by': 'aquarius', + 'last_modified_by': 'aquarius', + 'create_time': '2022-06-08T20:55:05Z', + 'system_mtime': '2022-06-08T20:55:05Z', + 'user_mtime': '2022-06-08T20:55:05Z', + 'act_type': 'publish', + 'restriction': + 'disallow', + 'jsonmodel_type': + 'rights_statement_act', + 'notes': [] + }] + output = get_active_rights_acts(acts) + self.assertEqual(output, []) + + acts = [ + { + 'start_date': '1886-01-01', + 'end_date': '1967-12-31', + 'created_by': 'aquarius', + 'last_modified_by': 'aquarius', + 'create_time': '2022-06-08T20:55:05Z', + 'system_mtime': '2022-06-08T20:55:05Z', + 'user_mtime': '2022-06-08T20:55:05Z', + 'act_type': 'publish', + 'restriction': + 'disallow', + 'jsonmodel_type': + 'rights_statement_act', + 'notes': [] + }, + { + 'start_date': '1886-01-01', + 'end_date': '2070-12-31', + 'created_by': 'aquarius', + 'last_modified_by': 'aquarius', + 'create_time': '2022-06-08T20:55:05Z', + 'system_mtime': '2022-06-08T20:55:05Z', + 'user_mtime': '2022-06-08T20:55:05Z', + 'act_type': 'publish', + 'restriction': + 'disallow', + 'jsonmodel_type': + 'rights_statement_act', + 'notes': [] + }] + expected = [ + { + 'start_date': '1886-01-01', + 'end_date': '2070-12-31', + 'created_by': 'aquarius', + 'last_modified_by': 'aquarius', + 'create_time': '2022-06-08T20:55:05Z', + 'system_mtime': '2022-06-08T20:55:05Z', + 'user_mtime': '2022-06-08T20:55:05Z', + 'act_type': 'publish', + 'restriction': + 'disallow', + 'jsonmodel_type': + 'rights_statement_act', + 'notes': [] + }] + output = get_active_rights_acts(acts) + self.assertEqual(output, expected) + @patch("asnake.client.web_client.ASnakeClient") def test_get_resource_creators(self, mock_client): mock_client.get.return_value.json.return_value = {"results": [{"title": "Philanthropy Foundation"}]} From 9aca88ab364032259d128d4117ff197b81485701 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 11 Nov 2024 19:00:31 -0500 Subject: [PATCH 3/4] update fixtures --- fixtures/object_restricted_ancestor.json | 2 +- fixtures/object_restricted_rights_statement.json | 2 +- fixtures/object_restricted_rights_statement_conditional.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/fixtures/object_restricted_ancestor.json b/fixtures/object_restricted_ancestor.json index ce2f44f..6c3d5db 100644 --- a/fixtures/object_restricted_ancestor.json +++ b/fixtures/object_restricted_ancestor.json @@ -43,7 +43,7 @@ "external_documents": [], "acts": [{ "start_date": "2020-02-07", - "end_date": "2020-02-15", + "end_date": "2070-02-15", "created_by": "admin", "last_modified_by": "admin", "create_time": "2020-02-10T18:34:17Z", diff --git a/fixtures/object_restricted_rights_statement.json b/fixtures/object_restricted_rights_statement.json index d37597f..ea6611b 100644 --- a/fixtures/object_restricted_rights_statement.json +++ b/fixtures/object_restricted_rights_statement.json @@ -17,7 +17,7 @@ "external_documents": [], "acts": [{ "start_date": "2020-02-07", - "end_date": "2020-02-15", + "end_date": "2070-02-15", "created_by": "admin", "last_modified_by": "admin", "create_time": "2020-02-10T18:34:17Z", diff --git a/fixtures/object_restricted_rights_statement_conditional.json b/fixtures/object_restricted_rights_statement_conditional.json index c40f270..662ef7d 100644 --- a/fixtures/object_restricted_rights_statement_conditional.json +++ b/fixtures/object_restricted_rights_statement_conditional.json @@ -17,7 +17,7 @@ "external_documents": [], "acts": [{ "start_date": "2020-02-07", - "end_date": "2020-02-15", + "end_date": "2070-02-15", "created_by": "admin", "last_modified_by": "admin", "create_time": "2020-02-10T18:34:17Z", From 6c5bffd1bae261284b68f552c1fd78ef89f74432 Mon Sep 17 00:00:00 2001 From: Hillel Arnold Date: Mon, 11 Nov 2024 19:00:38 -0500 Subject: [PATCH 4/4] update docker compose file --- docker-compose.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 5e70f9d..496453b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3' - services: request-broker-db: image: postgres:14.4 @@ -14,6 +12,7 @@ services: entrypoint: /code/entrypoint.sh environment: - APPLICATION_PORT=${APPLICATION_PORT:-8000} + - SQL_PORT=5432 volumes: - .:/code ports: