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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/palace/manager/api/circulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,33 @@ class BaseCirculationApiSettings(BaseSettings):
)
}

subscription_activation_date: datetime.date | None = FormField(
default=None,
form=ConfigurationFormItem(
label=_("Collection Subscription Activation Date"),
type=ConfigurationFormItemType.DATE,
description=(
"A date before which this collection is considered inactive. Associated libraries"
" will not be considered to be subscribed until this date). If not specified,"
" it will not restrict any associated library's subscription status."
),
required=False,
),
)
subscription_expiration_date: datetime.date | None = FormField(
default=None,
form=ConfigurationFormItem(
label=_("Collection Subscription Expiration Date"),
type=ConfigurationFormItemType.DATE,
description=(
"A date after which this collection is considered inactive. Associated libraries"
" will not be considered to be subscribed beyond this date). If not specified,"
" it will not restrict any associated library's subscription status."
),
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).



SettingsType = TypeVar("SettingsType", bound=BaseCirculationApiSettings, covariant=True)
LibrarySettingsType = TypeVar("LibrarySettingsType", bound=BaseSettings, covariant=True)
Expand Down
1 change: 1 addition & 0 deletions src/palace/manager/integration/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ class ConfigurationFormItemType(Enum):
"""Enumeration of configuration setting types"""

TEXT = None
DATE = "date-picker"
TEXTAREA = "textarea"
SELECT = "select"
LIST = "list"
Expand Down
22 changes: 22 additions & 0 deletions tests/manager/api/admin/test_form_data.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from werkzeug.datastructures import ImmutableMultiDict

from palace.manager.api.admin.form_data import ProcessFormData
Expand Down Expand Up @@ -30,6 +32,22 @@ class MockSettings(BaseSettings):
label="Field 3",
),
)
field4: datetime.date | None = FormField(
None,
form=ConfigurationFormItem(
label="Another date field with a date type",
type=ConfigurationFormItemType.DATE,
description="A python date.",
),
)
field5: 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():
Expand All @@ -41,9 +59,13 @@ def test_get_settings():
("field2_value3", "blah blah"),
("field2_value4", "blah blah blah"),
("field3", "value5"),
("field4", "2024-10-23"),
("field5", ""),
]
)
settings = ProcessFormData.get_settings(MockSettings, data)
assert settings.field1 == ["value1", "value2"]
assert settings.field2 == ["value3", "value4"]
assert settings.field3 == "value5"
assert settings.field4 == datetime.date(2024, 10, 23)
assert settings.field5 is None
Loading