Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add configuration settings for collections subscriptions. (PP-1850) #2153

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

tdilauro
Copy link
Contributor

@tdilauro tdilauro commented Nov 4, 2024

Description

Adds start and end date configuration settings for collection subscriptions.

NB: Submitting this PR as draft, since additional work is needed fully implement the subscription functionality.

  • CM Admin UI: support date picker field in configuration forms.
  • CM backend: New functionality to use the configuration settings to block libraries from using the collection.

Motivation and Context

Support automatic activation/deactivation of library associations with a collection.

[Jira PP-1850]

How Has This Been Tested?

Checklist

  • I have updated the documentation accordingly.
  • All new and existing tests passed.

@tdilauro tdilauro requested a review from a team November 4, 2024 14:24
Copy link

codecov bot commented Nov 4, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.11%. Comparing base (17948cb) to head (ffef549).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2153   +/-   ##
=======================================
  Coverage   91.11%   91.11%           
=======================================
  Files         363      363           
  Lines       41297    41300    +3     
  Branches     8841     8841           
=======================================
+ Hits        37629    37632    +3     
  Misses       2406     2406           
  Partials     1262     1262           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@dbernstein dbernstein self-requested a review November 4, 2024 16:37
Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added some comments with a couple questions on this one

),
required=False,
),
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be adding these settings for every circulation API? It seems like we only really want them for OPDS importer based APIs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they could be handy more generally; but, I'm fine moving them to the OPDS collections setting hierarchy for now.

I'm planning to implement the subscription (vs. association) concept across all collection types, but the absence of these settings on a collection would be interpreted as always subscribed (i.e., no restriction).

@@ -570,6 +570,33 @@ class BaseCirculationApiSettings(BaseSettings):
)
}

subscription_activation_date: str | None = FormField(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since these are coming in as dates, should we be setting the type here to reflect that, rather then just a generic str?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try using subscription_activation_date: datetime.date | None = FormField( ... for these, but ran into type errors in Pydantic.

I can dig into that some more as I do the implementation.

@jonathangreen
Copy link
Member

I was thinking about this one, and I'm wondering if we want to store the subscription end dates as full datetime. We are going to need a particular time to say a subscription ends, and we will need to think about what timezone that should be in.

A couple options I was thinking about:

  • Have the UI allow choosing the date and time the subscription ends
  • Choose the date, and use the users timezone to come up with an end datetime that gets sent to the CM
  • Allow both selecting a date and the timezone the subscription end should be enforced in

@tdilauro
Copy link
Contributor Author

tdilauro commented Nov 25, 2024

I was thinking about this one, and I'm wondering if we want to store the subscription end dates as full datetime. We are going to need a particular time to say a subscription ends, and we will need to think about what timezone that should be in.

My original thought on this was to use UTC to make this easier to manage with the distributors, who might also be enforcing their subscriptions. It would make things simpler. If libraries are able to negotiate a single "grace" day on each end of the subscription.

We could always add an offset later.

@tdilauro tdilauro force-pushed the feature/collection-active-date-configuration branch 2 times, most recently from 5f5febf to 413c3bd Compare January 13, 2025 02:42
@tdilauro
Copy link
Contributor Author

@jonathangreen Would you take another look at this one? Especially the pyupgrade pre-commit exception. If you'd like, I could pull those config settings out into their own module to reduce the surface area of the exception.

@jonathangreen
Copy link
Member

I think it would be good to elaborate a bit more about the details of the issue you are working around in pydantic. I added a little test to try to understand what was happening, and it seemed like pydantic was working fine in this instance with a datetime.date | None annotation.

diff --git a/tests/manager/api/admin/test_form_data.py b/tests/manager/api/admin/test_form_data.py
index 1c1a02023..d4a8ad220 100644
diff --git a/tests/manager/api/admin/test_form_data.py b/tests/manager/api/admin/test_form_data.py
index 1c1a02023..d4a8ad220 100644
--- a/tests/manager/api/admin/test_form_data.py
+++ b/tests/manager/api/admin/test_form_data.py
@@ -1,3 +1,5 @@
+import datetime
+
 from werkzeug.datastructures import ImmutableMultiDict

 from palace.manager.api.admin.form_data import ProcessFormData
@@ -46,6 +48,22 @@ class MockSettings(BaseSettings):
             description="Another date.",
         ),
     )
+    field6: datetime.date | None = FormField(
+        None,
+        form=ConfigurationFormItem(
+            label="Another date field with a date type",
+            type=ConfigurationFormItemType.DATE,
+            description="A python date.",
+        ),
+    )
+    field7: datetime.date | None = FormField(
+        None,
+        form=ConfigurationFormItem(
+            label="Another date field with a date type",
+            type=ConfigurationFormItemType.DATE,
+            description="A python date.",
+        ),
+    )


 def test_get_settings():
@@ -59,6 +77,8 @@ def test_get_settings():
             ("field3", "value5"),
             ("field4", "2024-10-23"),
             ("field5", ""),
+            ("field6", "2024-10-23"),
+            ("field7", ""),
         ]
     )
     settings = ProcessFormData.get_settings(MockSettings, data)
@@ -67,3 +87,5 @@ def test_get_settings():
     assert settings.field3 == "value5"
     assert settings.field4 == "2024-10-23"
     assert settings.field5 is None
+    assert settings.field6 == datetime.date(2024, 10, 23)
+    assert settings.field7 is None

@tdilauro tdilauro force-pushed the feature/collection-active-date-configuration branch from 413c3bd to 9030d8f Compare January 16, 2025 15:59
@tdilauro
Copy link
Contributor Author

I think it would be good to elaborate a bit more about the details of the issue you are working around in pydantic. I added a little test to try to understand what was happening, and it seemed like pydantic was working fine in this instance with a datetime.date | None annotation.

@jonathangreen Well, you're right! It is working without errors now. A quick check doesn't show anything pertinent that has changed since this PR first went in, so I'm a little baffled. I had similar params in when I was initially testing this, too. SMH

At any rate, this is ready for another look.

Copy link
Member

@jonathangreen jonathangreen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants