refrncr 0.1.0rc2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- refrncr/__init__.py +0 -0
- refrncr/api/__init__.py +1 -0
- refrncr/api/contracts.py +223 -0
- refrncr/api/documentation.py +187 -0
- refrncr/api/http.py +153 -0
- refrncr/api/routes.py +736 -0
- refrncr/api_key_persistence.py +59 -0
- refrncr/api_keys.py +229 -0
- refrncr/app.py +215 -0
- refrncr/argon2_benchmark.py +121 -0
- refrncr/audit.py +931 -0
- refrncr/audit_guard.py +226 -0
- refrncr/audit_history.py +279 -0
- refrncr/audit_presentation.py +423 -0
- refrncr/authorization.py +26 -0
- refrncr/browser_security.py +87 -0
- refrncr/change_status.py +36 -0
- refrncr/cli.py +619 -0
- refrncr/clock.py +27 -0
- refrncr/concept_contracts.py +78 -0
- refrncr/concept_persistence.py +308 -0
- refrncr/concept_upgrade.py +107 -0
- refrncr/dataset_diff.py +424 -0
- refrncr/dataset_export.py +819 -0
- refrncr/dataset_upgrade.py +95 -0
- refrncr/dataset_versions.py +1330 -0
- refrncr/datatypes.py +338 -0
- refrncr/db/__init__.py +0 -0
- refrncr/db/base.py +5 -0
- refrncr/db/session.py +32 -0
- refrncr/db/types.py +30 -0
- refrncr/diff_classification.py +234 -0
- refrncr/diff_contracts.py +117 -0
- refrncr/diff_persistence.py +594 -0
- refrncr/errors.py +13 -0
- refrncr/field_contracts.py +3 -0
- refrncr/hierarchy.py +518 -0
- refrncr/hierarchy_contracts.py +42 -0
- refrncr/hierarchy_import.py +417 -0
- refrncr/hierarchy_persistence.py +130 -0
- refrncr/installation_policy.py +28 -0
- refrncr/installation_settings.py +59 -0
- refrncr/login_security.py +263 -0
- refrncr/mapping_updates.py +147 -0
- refrncr/migrations/env.py +78 -0
- refrncr/migrations/script.py.mako +21 -0
- refrncr/migrations/versions/0001_ref_33_community_users.py +70 -0
- refrncr/migrations/versions/0002_ref_34_community_teams.py +27 -0
- refrncr/migrations/versions/0003_ref_35_team_memberships.py +31 -0
- refrncr/migrations/versions/0004_ref_36_access_grants.py +47 -0
- refrncr/migrations/versions/0005_ref_72_datasets.py +47 -0
- refrncr/migrations/versions/0006_ref_74_dataset_fields.py +46 -0
- refrncr/migrations/versions/0007_ref_75_dataset_business_key.py +37 -0
- refrncr/migrations/versions/0008_ref_79_dataset_records.py +78 -0
- refrncr/migrations/versions/0009_ref_80_record_revision.py +64 -0
- refrncr/migrations/versions/0010_ref_121_field_display_order.py +136 -0
- refrncr/migrations/versions/0011_ref_130_dataset_content_updated.py +23 -0
- refrncr/migrations/versions/0012_ref_73_dataset_team_governance.py +76 -0
- refrncr/migrations/versions/0013_ref_39_audit_history.py +16 -0
- refrncr/migrations/versions/0014_ref_145_field_datatypes.py +106 -0
- refrncr/migrations/versions/0015_ref_83_dataset_versions.py +138 -0
- refrncr/migrations/versions/0016_ref_84_active_concepts.py +50 -0
- refrncr/migrations/versions/0017_ref_154_source_formats.py +24 -0
- refrncr/migrations/versions/0018_ref_160_new_version.py +112 -0
- refrncr/migrations/versions/0019_ref_162_presentation_metadata.py +38 -0
- refrncr/migrations/versions/0020_ref_162_icon_names.py +23 -0
- refrncr/migrations/versions/0021_ref_40_api_keys.py +54 -0
- refrncr/migrations/versions/0022_ref_31_security_audit.py +34 -0
- refrncr/migrations/versions/0023_ref_176_effective_dates.py +37 -0
- refrncr/migrations/versions/0024_ref_177_mapping_tables.py +78 -0
- refrncr/migrations/versions/0025_ref_177_mapping_fields.py +45 -0
- refrncr/migrations/versions/0026_ref_177_mapping_field_roles.py +76 -0
- refrncr/migrations/versions/0027_ref_177_standalone_source_context.py +54 -0
- refrncr/migrations/versions/0028_ref_179_hierarchies.py +183 -0
- refrncr/migrations/versions/0029_ref_195_dark_mode.py +49 -0
- refrncr/migrations/versions/0030_ref_205_typed_draft_values.py +93 -0
- refrncr/migrations/versions/0031_ref_239_mapping_source_versions.py +59 -0
- refrncr/migrations/versions/0032_ref_239_source_version_policy.py +28 -0
- refrncr/migrations/versions/0033_ref_301_source_update_notes.py +24 -0
- refrncr/migrations/versions/0034_ref_238_dataset_visits.py +36 -0
- refrncr/migrations/versions/0035_ref_294_installation_settings.py +40 -0
- refrncr/models.py +841 -0
- refrncr/operational.py +349 -0
- refrncr/overview.py +389 -0
- refrncr/overview_persistence.py +112 -0
- refrncr/persistence.py +1639 -0
- refrncr/ports.py +728 -0
- refrncr/presentation.py +92 -0
- refrncr/presentation_metadata.py +122 -0
- refrncr/published_contracts.py +92 -0
- refrncr/record_identity.py +82 -0
- refrncr/record_import.py +2425 -0
- refrncr/record_intervals.py +130 -0
- refrncr/record_search.py +119 -0
- refrncr/review_tokens.py +56 -0
- refrncr/services.py +3290 -0
- refrncr/source_formats.py +429 -0
- refrncr/static/css/base.css +20 -0
- refrncr/static/css/components/buttons.css +27 -0
- refrncr/static/css/components/cards-badges.css +22 -0
- refrncr/static/css/components/dialog.css +98 -0
- refrncr/static/css/components/feedback.css +27 -0
- refrncr/static/css/components/forms.css +117 -0
- refrncr/static/css/components/hierarchy.css +68 -0
- refrncr/static/css/components/overview.css +70 -0
- refrncr/static/css/components/select.css +66 -0
- refrncr/static/css/components/tables.css +228 -0
- refrncr/static/css/layouts/api-docs.css +75 -0
- refrncr/static/css/layouts/api-keys.css +6 -0
- refrncr/static/css/layouts/app-shell.css +88 -0
- refrncr/static/css/layouts/auth.css +12 -0
- refrncr/static/css/layouts/configuration.css +164 -0
- refrncr/static/css/layouts/import.css +210 -0
- refrncr/static/css/layouts/overview.css +22 -0
- refrncr/static/css/layouts/page.css +95 -0
- refrncr/static/css/layouts/settings.css +58 -0
- refrncr/static/css/no-script-view-transitions.css +2 -0
- refrncr/static/css/refrncr.css +19 -0
- refrncr/static/css/swagger-ui.css +3 -0
- refrncr/static/css/tokens.css +77 -0
- refrncr/static/css/utilities.css +3 -0
- refrncr/static/fonts/ibm-plex-mono/ibm-plex-mono-latin-400-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-mono/ibm-plex-mono-latin-ext-400-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-sans/ibm-plex-sans-latin-400-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-sans/ibm-plex-sans-latin-600-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-sans/ibm-plex-sans-latin-700-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-400-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-600-normal.woff2 +0 -0
- refrncr/static/fonts/ibm-plex-sans/ibm-plex-sans-latin-ext-700-normal.woff2 +0 -0
- refrncr/static/fonts/instrument-sans/instrument-sans-latin-500-normal.woff2 +0 -0
- refrncr/static/fonts/instrument-sans/instrument-sans-latin-600-normal.woff2 +0 -0
- refrncr/static/fonts/instrument-sans/instrument-sans-latin-700-normal.woff2 +0 -0
- refrncr/static/fonts/instrument-sans/instrument-sans-latin-ext-500-normal.woff2 +0 -0
- refrncr/static/fonts/instrument-sans/instrument-sans-latin-ext-600-normal.woff2 +0 -0
- refrncr/static/fonts/instrument-sans/instrument-sans-latin-ext-700-normal.woff2 +0 -0
- refrncr/static/images/favicon.svg +1 -0
- refrncr/static/images/lucide-1.46.0.svg +11195 -0
- refrncr/static/images/lucide-legacy-0.468.0.svg +445 -0
- refrncr/static/images/refrncr-loader.svg +1 -0
- refrncr/static/images/refrncr-wordmark-primary.svg +1 -0
- refrncr/static/images/refrncr-wordmark-reversed.svg +1 -0
- refrncr/static/images/theme-preview-dark.svg +1 -0
- refrncr/static/images/theme-preview-light.svg +1 -0
- refrncr/static/images/theme-preview-system.svg +1 -0
- refrncr/static/js/api-docs.js +109 -0
- refrncr/static/js/api-key-secret.js +25 -0
- refrncr/static/js/audit-time.js +147 -0
- refrncr/static/js/field-order.js +103 -0
- refrncr/static/js/hierarchy-columns.js +54 -0
- refrncr/static/js/icon-picker.js +171 -0
- refrncr/static/js/key-generation.js +52 -0
- refrncr/static/js/mapping-table-form.js +53 -0
- refrncr/static/js/navigation.js +132 -0
- refrncr/static/js/overview-greeting.js +25 -0
- refrncr/static/js/record-search.js +37 -0
- refrncr/static/js/refrncr.js +1157 -0
- refrncr/static/js/section-tabs.js +97 -0
- refrncr/static/js/select.js +500 -0
- refrncr/static/js/swagger-ui-bundle.js +2 -0
- refrncr/static/js/version-diff.js +6 -0
- refrncr/static/js/view-transitions.js +34 -0
- refrncr/static/licenses/ASSET-SOURCES.md +173 -0
- refrncr/static/licenses/LICENSE-Lucide-0.468.0.txt +15 -0
- refrncr/static/licenses/LICENSE-Lucide.txt +43 -0
- refrncr/static/licenses/LICENSE-Swagger-UI-bundle.txt +129 -0
- refrncr/static/licenses/LICENSE-Swagger-UI.txt +202 -0
- refrncr/static/licenses/NOTICE-Swagger-UI.txt +2 -0
- refrncr/static/licenses/OFL-IBM-Plex-Mono.txt +93 -0
- refrncr/static/licenses/OFL-IBM-Plex-Sans.txt +93 -0
- refrncr/static/licenses/OFL-Instrument-Sans.txt +93 -0
- refrncr/templates/base.html +72 -0
- refrncr/templates/components/account.html +14 -0
- refrncr/templates/components/branding.html +10 -0
- refrncr/templates/components/concept.html +57 -0
- refrncr/templates/components/dataset_card.html +55 -0
- refrncr/templates/components/dataset_icon.html +36 -0
- refrncr/templates/components/dataset_navigation.html +15 -0
- refrncr/templates/components/export_access.html +66 -0
- refrncr/templates/components/export_action.html +32 -0
- refrncr/templates/components/field_metadata.html +32 -0
- refrncr/templates/components/flash_messages.html +5 -0
- refrncr/templates/components/icons.html +118 -0
- refrncr/templates/components/import_action.html +11 -0
- refrncr/templates/components/mapping.html +14 -0
- refrncr/templates/components/mapping_update.html +15 -0
- refrncr/templates/components/mapping_usage.html +37 -0
- refrncr/templates/components/navigation.html +9 -0
- refrncr/templates/components/record_search.html +49 -0
- refrncr/templates/components/record_status_filter.html +19 -0
- refrncr/templates/components/relationships.html +6 -0
- refrncr/templates/components/search_field.html +10 -0
- refrncr/templates/components/section_tabs.html +5 -0
- refrncr/templates/components/side_panel.html +26 -0
- refrncr/templates/components/table_row.html +7 -0
- refrncr/templates/components/version_diff.html +21 -0
- refrncr/templates/components.html +86 -0
- refrncr/templates/layouts/auth/base.html +15 -0
- refrncr/templates/layouts/page.html +17 -0
- refrncr/templates/layouts/settings.html +41 -0
- refrncr/templates/pages/api/docs.html +42 -0
- refrncr/templates/pages/api_keys/base.html +2 -0
- refrncr/templates/pages/api_keys/create.html +16 -0
- refrncr/templates/pages/api_keys/list.html +24 -0
- refrncr/templates/pages/api_keys/revoke.html +16 -0
- refrncr/templates/pages/api_keys/secret.html +19 -0
- refrncr/templates/pages/audit/detail.html +30 -0
- refrncr/templates/pages/audit/error.html +7 -0
- refrncr/templates/pages/audit/list.html +50 -0
- refrncr/templates/pages/auth/login.html +46 -0
- refrncr/templates/pages/auth/setup.html +46 -0
- refrncr/templates/pages/datasets/_breadcrumbs.html +2 -0
- refrncr/templates/pages/datasets/_edit_form.html +60 -0
- refrncr/templates/pages/datasets/_edit_general_form.html +20 -0
- refrncr/templates/pages/datasets/_edit_ownership_form.html +16 -0
- refrncr/templates/pages/datasets/_record_form_fields.html +28 -0
- refrncr/templates/pages/datasets/_record_panels.html +81 -0
- refrncr/templates/pages/datasets/_record_table.html +86 -0
- refrncr/templates/pages/datasets/_source_notice.html +25 -0
- refrncr/templates/pages/datasets/_team_choice.html +6 -0
- refrncr/templates/pages/datasets/_version_status.html +14 -0
- refrncr/templates/pages/datasets/concept_required.html +11 -0
- refrncr/templates/pages/datasets/concepts/_banner.html +2 -0
- refrncr/templates/pages/datasets/concepts/_version_row.html +13 -0
- refrncr/templates/pages/datasets/concepts/discard.html +34 -0
- refrncr/templates/pages/datasets/create.html +83 -0
- refrncr/templates/pages/datasets/delete.html +34 -0
- refrncr/templates/pages/datasets/detail.html +160 -0
- refrncr/templates/pages/datasets/empty_records.html +19 -0
- refrncr/templates/pages/datasets/export_error.html +12 -0
- refrncr/templates/pages/datasets/export_period.html +34 -0
- refrncr/templates/pages/datasets/fields/_form_fields.html +24 -0
- refrncr/templates/pages/datasets/fields/_table.html +35 -0
- refrncr/templates/pages/datasets/fields/create.html +19 -0
- refrncr/templates/pages/datasets/fields/edit.html +24 -0
- refrncr/templates/pages/datasets/fields/read.html +22 -0
- refrncr/templates/pages/datasets/hierarchy/_tree.html +37 -0
- refrncr/templates/pages/datasets/hierarchy/_view_panels.html +13 -0
- refrncr/templates/pages/datasets/hierarchy/delete.html +25 -0
- refrncr/templates/pages/datasets/hierarchy/node_form.html +45 -0
- refrncr/templates/pages/datasets/hierarchy.html +120 -0
- refrncr/templates/pages/datasets/hierarchy_import.html +31 -0
- refrncr/templates/pages/datasets/import/_mapping_status.html +24 -0
- refrncr/templates/pages/datasets/import/differences.html +95 -0
- refrncr/templates/pages/datasets/import/error_report.html +11 -0
- refrncr/templates/pages/datasets/import/mapping.html +45 -0
- refrncr/templates/pages/datasets/import/mapping_info.html +4 -0
- refrncr/templates/pages/datasets/import/preview.html +11 -0
- refrncr/templates/pages/datasets/import/source_format.html +104 -0
- refrncr/templates/pages/datasets/import/source_format_fragments.html +1 -0
- refrncr/templates/pages/datasets/import/unavailable.html +7 -0
- refrncr/templates/pages/datasets/import/upload.html +8 -0
- refrncr/templates/pages/datasets/import/wizard.html +58 -0
- refrncr/templates/pages/datasets/import/worksheet.html +4 -0
- refrncr/templates/pages/datasets/list.html +26 -0
- refrncr/templates/pages/datasets/records/delete.html +5 -0
- refrncr/templates/pages/datasets/records/form.html +20 -0
- refrncr/templates/pages/datasets/records/restore_error.html +6 -0
- refrncr/templates/pages/datasets/records.html +44 -0
- refrncr/templates/pages/datasets/search_error.html +7 -0
- refrncr/templates/pages/datasets/versions/_mapping_records.html +22 -0
- refrncr/templates/pages/datasets/versions/_navigation.html +1 -0
- refrncr/templates/pages/datasets/versions/cancel.html +27 -0
- refrncr/templates/pages/datasets/versions/diff_detail.html +38 -0
- refrncr/templates/pages/datasets/versions/list.html +40 -0
- refrncr/templates/pages/datasets/versions/publish.html +40 -0
- refrncr/templates/pages/datasets/versions/review.html +111 -0
- refrncr/templates/pages/datasets/versions/review_error.html +8 -0
- refrncr/templates/pages/error.html +13 -0
- refrncr/templates/pages/index.html +16 -0
- refrncr/templates/pages/overview.html +63 -0
- refrncr/templates/pages/settings/appearance.html +25 -0
- refrncr/templates/pages/settings/dataset_access.html +28 -0
- refrncr/templates/pages/teams/_membership_controls.html +11 -0
- refrncr/templates/pages/teams/_team_form_fields.html +7 -0
- refrncr/templates/pages/teams/_team_panels.html +15 -0
- refrncr/templates/pages/teams/list.html +16 -0
- refrncr/templates/pages/teams/members.html +8 -0
- refrncr/templates/pages/teams/readonly.html +9 -0
- refrncr/templates/pages/users/_user_form_fields.html +13 -0
- refrncr/templates/pages/users/_user_panels.html +43 -0
- refrncr/templates/pages/users/list.html +19 -0
- refrncr/upload_names.py +9 -0
- refrncr/version_contracts.py +209 -0
- refrncr/version_persistence.py +629 -0
- refrncr/version_upgrade.py +94 -0
- refrncr/web.py +4990 -0
- refrncr/xml_security.py +16 -0
- refrncr-0.1.0rc2.dist-info/METADATA +357 -0
- refrncr-0.1.0rc2.dist-info/RECORD +293 -0
- refrncr-0.1.0rc2.dist-info/WHEEL +5 -0
- refrncr-0.1.0rc2.dist-info/entry_points.txt +2 -0
- refrncr-0.1.0rc2.dist-info/licenses/LICENSE +95 -0
- refrncr-0.1.0rc2.dist-info/top_level.txt +1 -0
refrncr/__init__.py
ADDED
|
File without changes
|
refrncr/api/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""REF-107 HTTP adapter. Business reads belong to DatasetVersionService."""
|
refrncr/api/contracts.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
"""Additive v1 JSON contracts; no ORM, authorization or datatype parsing."""
|
|
2
|
+
|
|
3
|
+
from datetime import date
|
|
4
|
+
from decimal import Decimal
|
|
5
|
+
from typing import Annotated, Literal
|
|
6
|
+
|
|
7
|
+
from pydantic import (
|
|
8
|
+
BaseModel,
|
|
9
|
+
ConfigDict,
|
|
10
|
+
Field,
|
|
11
|
+
StrictBool,
|
|
12
|
+
StrictFloat,
|
|
13
|
+
StrictInt,
|
|
14
|
+
StrictStr,
|
|
15
|
+
WithJsonSchema,
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class Contract(BaseModel):
|
|
20
|
+
model_config = ConfigDict(extra="forbid", strict=True, frozen=True)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
class SelectionQuery(Contract):
|
|
24
|
+
effective_date: date | None = Field(
|
|
25
|
+
default=None,
|
|
26
|
+
description=(
|
|
27
|
+
"Business date in ISO calendar-date format YYYY-MM-DD, with zero-padded month "
|
|
28
|
+
"and day (for example 2026-09-30). Selects the latest publication effective "
|
|
29
|
+
"on or before that date."
|
|
30
|
+
),
|
|
31
|
+
examples=["2026-09-30"],
|
|
32
|
+
)
|
|
33
|
+
version: int | None = Field(
|
|
34
|
+
default=None,
|
|
35
|
+
ge=1,
|
|
36
|
+
le=2147483647,
|
|
37
|
+
description="Explicit immutable published version number.",
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
class PageQuery(Contract):
|
|
42
|
+
offset: int = Field(
|
|
43
|
+
default=0,
|
|
44
|
+
ge=0,
|
|
45
|
+
le=2147483647,
|
|
46
|
+
description="Zero-based offset; canonical ASCII whole number.",
|
|
47
|
+
)
|
|
48
|
+
limit: int = Field(
|
|
49
|
+
default=50,
|
|
50
|
+
ge=1,
|
|
51
|
+
le=100,
|
|
52
|
+
description="Page size; canonical ASCII whole number, maximum 100.",
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class CollectionQuery(PageQuery, SelectionQuery):
|
|
57
|
+
pass
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
class HistoryQuery(PageQuery):
|
|
61
|
+
valid_from: date | None = Field(
|
|
62
|
+
default=None, description="Inclusive lower bound in YYYY-MM-DD format."
|
|
63
|
+
)
|
|
64
|
+
valid_to: date | None = Field(
|
|
65
|
+
default=None, description="Exclusive upper bound in YYYY-MM-DD format."
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
class Pagination(PageQuery):
|
|
70
|
+
total: int = Field(ge=0)
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
class Links(Contract):
|
|
74
|
+
"""Application-relative pagination links; next/previous are null at boundaries."""
|
|
75
|
+
|
|
76
|
+
self: str
|
|
77
|
+
next: str | None
|
|
78
|
+
previous: str | None
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
class SourceMetadata(Contract):
|
|
82
|
+
dataset_key: str
|
|
83
|
+
version: int = Field(ge=1)
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
class VersionMetadata(Contract):
|
|
87
|
+
"""Selected publication metadata with a half-open effective period."""
|
|
88
|
+
|
|
89
|
+
number: int = Field(ge=1)
|
|
90
|
+
published_at: str = Field(examples=["2000-01-01T00:00:00Z"])
|
|
91
|
+
effective_from: str = Field(examples=["2000-01-01"])
|
|
92
|
+
effective_to: str | None = Field(
|
|
93
|
+
examples=["2001-01-01"],
|
|
94
|
+
description="Exclusive end; null when no later non-cancelled version exists.",
|
|
95
|
+
)
|
|
96
|
+
source: SourceMetadata | None = None
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
class VersionListItem(VersionMetadata):
|
|
100
|
+
"""One published version in effective-period order."""
|
|
101
|
+
|
|
102
|
+
status: Literal["Current", "Scheduled", "Expired"]
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
class Dataset(Contract):
|
|
106
|
+
key: str
|
|
107
|
+
name: str
|
|
108
|
+
description: str
|
|
109
|
+
icon: str | None
|
|
110
|
+
kind: Literal["reference", "mapping", "hierarchy"]
|
|
111
|
+
version: VersionMetadata
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class HierarchyMetadata(Contract):
|
|
115
|
+
depth: int = Field(ge=0)
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
class FieldMetadata(Contract):
|
|
119
|
+
"""Published Field metadata, in display order; definition/unit are nullable plain text."""
|
|
120
|
+
|
|
121
|
+
key: str
|
|
122
|
+
name: str
|
|
123
|
+
datatype: Literal[
|
|
124
|
+
"string", "integer", "number", "float", "boolean", "date", "time", "datetime", "timestamp"
|
|
125
|
+
]
|
|
126
|
+
is_identifier: bool
|
|
127
|
+
is_required: bool
|
|
128
|
+
is_unique: bool
|
|
129
|
+
display_position: int = Field(ge=1)
|
|
130
|
+
definition: str | None
|
|
131
|
+
unit: str | None
|
|
132
|
+
mapping_role: Literal["source_identifier", "source_context", "mapping_target"] | None = None
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
class DatasetDetail(Dataset):
|
|
136
|
+
fields: tuple[FieldMetadata, ...]
|
|
137
|
+
hierarchy: HierarchyMetadata | None = None
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
CanonicalDecimal = Annotated[Decimal, WithJsonSchema({"type": "number"}, mode="serialization")]
|
|
141
|
+
CanonicalValue = StrictStr | StrictBool | StrictInt | StrictFloat | CanonicalDecimal | None
|
|
142
|
+
|
|
143
|
+
|
|
144
|
+
class Record(Contract):
|
|
145
|
+
"""Opaque business identifier and canonical values for every published Field key.
|
|
146
|
+
|
|
147
|
+
Single/composite identifiers share the same contract. Values use native JSON types;
|
|
148
|
+
temporal values are canonical strings, UTC Timestamp ends in Z, absent values are null.
|
|
149
|
+
Decimal numbers retain exact precision; consumers need an exact JSON number parser.
|
|
150
|
+
"""
|
|
151
|
+
|
|
152
|
+
identifier: str = Field(min_length=1, max_length=2667, pattern=r"^[A-Za-z0-9_-]+$")
|
|
153
|
+
values: dict[str, CanonicalValue]
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
class RecordInterval(Record):
|
|
157
|
+
"""One unchanged visible Record state over a half-open period."""
|
|
158
|
+
|
|
159
|
+
valid_from: str = Field(examples=["2026-01-01"])
|
|
160
|
+
valid_to: str | None = Field(
|
|
161
|
+
examples=["2026-07-01"], description="Exclusive end; null for an open period."
|
|
162
|
+
)
|
|
163
|
+
version: int = Field(ge=1, description="Version in which this state began.")
|
|
164
|
+
|
|
165
|
+
|
|
166
|
+
class HierarchyNode(Contract):
|
|
167
|
+
id: str
|
|
168
|
+
parent_id: str | None
|
|
169
|
+
name: str
|
|
170
|
+
values: dict[str, CanonicalValue]
|
|
171
|
+
record_identifier: str | None
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class HierarchyData(Contract):
|
|
175
|
+
fields: tuple[FieldMetadata, ...]
|
|
176
|
+
nodes: tuple[HierarchyNode, ...]
|
|
177
|
+
records: tuple[Record, ...]
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
class Detail[T](Contract):
|
|
181
|
+
data: T
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
class Collection[T](Contract):
|
|
185
|
+
data: tuple[T, ...]
|
|
186
|
+
pagination: Pagination
|
|
187
|
+
links: Links
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
class RecordDetail(Detail[Record]):
|
|
191
|
+
version: VersionMetadata
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
class RecordCollection(Collection[Record]):
|
|
195
|
+
version: VersionMetadata
|
|
196
|
+
|
|
197
|
+
|
|
198
|
+
class HierarchyRecord(Contract):
|
|
199
|
+
identifier: str
|
|
200
|
+
node_id: str
|
|
201
|
+
parent_id: str | None
|
|
202
|
+
levels: tuple[str, ...]
|
|
203
|
+
leaf: str
|
|
204
|
+
values: dict[str, CanonicalValue]
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class HierarchyRecordCollection(Collection[HierarchyRecord]):
|
|
208
|
+
version: VersionMetadata
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
class HierarchyResponse(Contract):
|
|
212
|
+
data: HierarchyData
|
|
213
|
+
version: VersionMetadata
|
|
214
|
+
|
|
215
|
+
|
|
216
|
+
class Error(Contract):
|
|
217
|
+
error: Literal[
|
|
218
|
+
"invalid_api_credentials",
|
|
219
|
+
"not_found",
|
|
220
|
+
"invalid_request",
|
|
221
|
+
"method_not_allowed",
|
|
222
|
+
"service_unavailable",
|
|
223
|
+
]
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
"""Public documentation composed from the registered FastAPI routes."""
|
|
2
|
+
|
|
3
|
+
from copy import deepcopy
|
|
4
|
+
from importlib.resources import files
|
|
5
|
+
|
|
6
|
+
from fastapi.openapi.utils import get_openapi
|
|
7
|
+
from starlette.responses import HTMLResponse
|
|
8
|
+
|
|
9
|
+
from refrncr.api.http import SAFE_HEADERS, CanonicalJSONResponse
|
|
10
|
+
|
|
11
|
+
DESCRIPTION = """
|
|
12
|
+
Read-only access to **published data** using exactly one
|
|
13
|
+
`Authorization: Bearer <api-key>` header. Browser cookies and sessions do not authenticate
|
|
14
|
+
this API. Use Authorize to enter the key alone; it is retained only in this page's memory.
|
|
15
|
+
Missing, invalid, expired or revoked keys return 401. Missing and inaccessible resources
|
|
16
|
+
both return 404. All data responses are JSON; 304 has no body.
|
|
17
|
+
|
|
18
|
+
Keys use their owner's current dataset export rights. The installation's Dataset access
|
|
19
|
+
policy defaults to Everyone, allowing every active user to read published datasets.
|
|
20
|
+
In either stricter mode, administrators, owning-team members and explicitly granted users
|
|
21
|
+
or teams can read them. Dataset lists contain only authorized datasets; other datasets
|
|
22
|
+
return 404. Revoked grants, changed team membership or ownership, and policy changes apply
|
|
23
|
+
to the next request. An in-flight consistent read may finish. This dataset-level check
|
|
24
|
+
does not change version selection: Scheduled publications remain available by version or
|
|
25
|
+
future effective date, even though file export does not offer them.
|
|
26
|
+
|
|
27
|
+
Snapshot reads accept optional `effective_date=YYYY-MM-DD` and `version=<number>` selectors.
|
|
28
|
+
The former chooses the latest publication effective on or before that business date; the
|
|
29
|
+
latter chooses an immutable published version. When combined, that version must be effective
|
|
30
|
+
on the date. Collections additionally accept `offset` and `limit`, in canonical ASCII
|
|
31
|
+
whole-number notation
|
|
32
|
+
(no signs, leading zeroes except 0, fractions or exponents). Duplicate/unknown parameters
|
|
33
|
+
and querystrings over 256 bytes return 400.
|
|
34
|
+
Dataset order is key ascending; Records use canonical typed business-identifier order.
|
|
35
|
+
Links are application-relative; next/previous may be null. Separate pages are not a pinned
|
|
36
|
+
snapshot: check selected-version metadata when traversing pages.
|
|
37
|
+
|
|
38
|
+
Version metadata describes a half-open effective period. `effective_from` is inclusive;
|
|
39
|
+
`effective_to` is the exclusive effective date of the next non-cancelled version, including
|
|
40
|
+
a Scheduled successor, and is null when no such successor exists. Cancelling a Scheduled
|
|
41
|
+
version therefore restores the preceding version's open end.
|
|
42
|
+
`/api/v1/datasets/{dataset_key}/versions` lists every non-cancelled publication in
|
|
43
|
+
effective-date and version-number order, including Scheduled versions. It uses offset/limit
|
|
44
|
+
pagination and does not accept version selectors.
|
|
45
|
+
|
|
46
|
+
`/api/v1/datasets/{dataset_key}/records/history` returns one row per unchanged visible
|
|
47
|
+
Record state. `valid_from` is inclusive and `valid_to` exclusive; an open end is null.
|
|
48
|
+
Optional `valid_from`/`valid_to` query bounds select overlapping states but never clip their
|
|
49
|
+
real boundaries. Consecutive identical states are merged. A removed Record's period ends at
|
|
50
|
+
the removing version without a deletion row; Cancelled versions never split a period.
|
|
51
|
+
|
|
52
|
+
Record values are canonical, keyed by Field key: String and Boolean are native JSON;
|
|
53
|
+
Integer, Decimal (`number`) and Float are JSON numbers. Use an exact JSON number parser
|
|
54
|
+
for large integers and decimals. Date, Time and DateTime are canonical strings;
|
|
55
|
+
Timestamp is UTC with `Z`. Missing values are null. No locale/display formatting applies.
|
|
56
|
+
Identifiers are opaque business identifiers, never internal Record UUIDs. Single and
|
|
57
|
+
composite identifiers share the same contract: URL encode the **entire returned identifier**;
|
|
58
|
+
do not reconstruct it from display values. Encoding is reversible, not encryption.
|
|
59
|
+
|
|
60
|
+
The hierarchy endpoint returns one complete published snapshot at
|
|
61
|
+
`/api/v1/datasets/{dataset_key}/hierarchy`. Its flat `nodes` contain stable node IDs,
|
|
62
|
+
`parent_id`, names, canonical values and a `record_identifier` for leaves; `records`
|
|
63
|
+
contains the corresponding leaf records. Intermediate branches are not records. The
|
|
64
|
+
snapshot is not paginated so it can be reconstructed independently. Hierarchy selection
|
|
65
|
+
uses the same version/effective-date, authorization, error, ETag and cache rules as the
|
|
66
|
+
other published-data endpoints.
|
|
67
|
+
|
|
68
|
+
For mappings, `/api/v1/datasets/{dataset_key}/lookup?source=1001` looks up one source
|
|
69
|
+
value, for example `1001 → AMS-SALES`. This is a targeted lookup, not general filtering.
|
|
70
|
+
The value is parsed using the selected version's `source_identifier` Field datatype.
|
|
71
|
+
Invalid values return 400; unknown values and non-mapping datasets return 404. Unmapped
|
|
72
|
+
source values return 200 with the Record and null target values. The response is the same
|
|
73
|
+
RecordDetail as `/records/{identifier}`, with the same version selectors and caching rules.
|
|
74
|
+
Field metadata includes `mapping_role`: `source_identifier`, `source_context`, or
|
|
75
|
+
`mapping_target`; it is null outside mappings. Version metadata includes `source` with
|
|
76
|
+
`dataset_key` and `version` for mappings, otherwise null. The source key and version are
|
|
77
|
+
visible to anyone with export access to the mapping; source dataset access is not required.
|
|
78
|
+
|
|
79
|
+
Every successful data response supplies a strong ETag and publication-based Last-Modified.
|
|
80
|
+
Send If-None-Match to revalidate; matching tags (including weak/list matches and `*`)
|
|
81
|
+
return 304 only after authentication, authorization and existence checks. ETags also track
|
|
82
|
+
current Dataset metadata and the selected page. If-None-Match takes precedence over
|
|
83
|
+
If-Modified-Since. Date-only validation is conservative and may return 200 even when
|
|
84
|
+
Last-Modified is unchanged. Dataset lists use the page's latest publication time, or Unix
|
|
85
|
+
epoch for an empty page. Private caches must revalidate every use; shared caching is forbidden.
|
|
86
|
+
|
|
87
|
+
**Excluded:** Concepts, Cancelled versions, publication-time queries, search/filtering/sorting,
|
|
88
|
+
writes, import/export, reverse mapping lookup and batch lookup. The hierarchy endpoint is read-only
|
|
89
|
+
and does not expose concept data, internal IDs as record identifiers, cross-dataset references
|
|
90
|
+
or aggregations.
|
|
91
|
+
""".strip()
|
|
92
|
+
|
|
93
|
+
CONDITIONAL_PARAMETERS = [
|
|
94
|
+
{
|
|
95
|
+
"name": "If-None-Match",
|
|
96
|
+
"in": "header",
|
|
97
|
+
"required": False,
|
|
98
|
+
"schema": {"type": "string"},
|
|
99
|
+
"description": "Previous ETag, list of tags or *. Authoritative over If-Modified-Since.",
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
"name": "If-Modified-Since",
|
|
103
|
+
"in": "header",
|
|
104
|
+
"required": False,
|
|
105
|
+
"schema": {"type": "string"},
|
|
106
|
+
"description": "Optional HTTP date. Conservative secondary validator; prefer ETags.",
|
|
107
|
+
},
|
|
108
|
+
]
|
|
109
|
+
|
|
110
|
+
MAPPING_LOOKUP_EXAMPLE = {
|
|
111
|
+
"data": {
|
|
112
|
+
"identifier": "AAAABWkxMDAx",
|
|
113
|
+
"values": {"code": 1001, "target": "AMS-SALES"},
|
|
114
|
+
},
|
|
115
|
+
"version": {
|
|
116
|
+
"number": 1,
|
|
117
|
+
"published_at": "2026-10-27T12:00:00Z",
|
|
118
|
+
"effective_from": "2026-10-27",
|
|
119
|
+
"effective_to": "2027-01-01",
|
|
120
|
+
"source": {"dataset_key": "sap-cost-centres", "version": 1},
|
|
121
|
+
},
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
RESPONSE_HEADERS = {
|
|
125
|
+
"ETag": {"schema": {"type": "string"}, "description": "Strong representation validator."},
|
|
126
|
+
"Last-Modified": {
|
|
127
|
+
"schema": {"type": "string"},
|
|
128
|
+
"description": "Selected publication time as HTTP date (page maximum; epoch if empty).",
|
|
129
|
+
},
|
|
130
|
+
"Cache-Control": {
|
|
131
|
+
"schema": {"type": "string"},
|
|
132
|
+
"description": "private, no-cache, max-age=0, must-revalidate",
|
|
133
|
+
},
|
|
134
|
+
"Vary": {"schema": {"type": "string"}, "description": "Authorization, Accept-Encoding"},
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def publish_documentation(app, api):
|
|
139
|
+
"""Register only the two public documentation endpoints, before the Flask mount."""
|
|
140
|
+
html = files("refrncr").joinpath("templates/pages/api/docs.html").read_text()
|
|
141
|
+
headers = {
|
|
142
|
+
**SAFE_HEADERS,
|
|
143
|
+
"Content-Security-Policy": (
|
|
144
|
+
"default-src 'none'; script-src 'self'; style-src 'self'; "
|
|
145
|
+
"img-src 'self' data:; font-src 'self'; connect-src 'self'; "
|
|
146
|
+
"base-uri 'none'; form-action 'none'; frame-ancestors 'none'"
|
|
147
|
+
),
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@app.get(
|
|
151
|
+
"/api/openapi.json",
|
|
152
|
+
response_class=CanonicalJSONResponse,
|
|
153
|
+
summary="Read the public OpenAPI document",
|
|
154
|
+
description="Generated contract only; no Dataset, Record, user or credential data.",
|
|
155
|
+
tags=["Documentation"],
|
|
156
|
+
)
|
|
157
|
+
def openapi_document():
|
|
158
|
+
try:
|
|
159
|
+
return CanonicalJSONResponse(app.openapi(), headers=SAFE_HEADERS)
|
|
160
|
+
except Exception: # noqa: BLE001 - the public schema endpoint must fail closed.
|
|
161
|
+
return CanonicalJSONResponse(
|
|
162
|
+
{"error": "service_unavailable"}, status_code=503, headers=SAFE_HEADERS
|
|
163
|
+
)
|
|
164
|
+
|
|
165
|
+
@app.get(
|
|
166
|
+
"/api/docs",
|
|
167
|
+
response_class=HTMLResponse,
|
|
168
|
+
summary="Open the public Swagger UI",
|
|
169
|
+
description="Interactive documentation; raw OpenAPI JSON is the accessible alternative.",
|
|
170
|
+
tags=["Documentation"],
|
|
171
|
+
)
|
|
172
|
+
def swagger_ui():
|
|
173
|
+
return HTMLResponse(html, headers=headers)
|
|
174
|
+
|
|
175
|
+
def schema():
|
|
176
|
+
if app.openapi_schema is None:
|
|
177
|
+
document = deepcopy(api.openapi())
|
|
178
|
+
# A mounted app's paths are relative. Publish the actual public paths, without
|
|
179
|
+
# deriving servers from untrusted Host/forwarded headers or request state.
|
|
180
|
+
document["paths"] = {"/api/v1" + p: item for p, item in document["paths"].items()}
|
|
181
|
+
docs = get_openapi(title=api.title, version=api.version, routes=app.routes)
|
|
182
|
+
document["paths"].update(docs["paths"])
|
|
183
|
+
document.pop("servers", None)
|
|
184
|
+
app.openapi_schema = document
|
|
185
|
+
return app.openapi_schema
|
|
186
|
+
|
|
187
|
+
app.openapi = schema
|
refrncr/api/http.py
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"""Safe JSON and HTTP conditional retrieval, separate from domain reads."""
|
|
2
|
+
|
|
3
|
+
import hashlib
|
|
4
|
+
import json
|
|
5
|
+
import re
|
|
6
|
+
from datetime import UTC, datetime
|
|
7
|
+
from decimal import Decimal
|
|
8
|
+
from email.utils import format_datetime, parsedate_to_datetime
|
|
9
|
+
|
|
10
|
+
from pydantic import BaseModel
|
|
11
|
+
from starlette.responses import JSONResponse
|
|
12
|
+
|
|
13
|
+
from refrncr.clock import SYSTEM_CLOCK, Clock
|
|
14
|
+
from refrncr.datatypes import get_datatype
|
|
15
|
+
|
|
16
|
+
PRIVATE = "private, no-cache, max-age=0, must-revalidate"
|
|
17
|
+
SAFE_HEADERS = {
|
|
18
|
+
"Cache-Control": "private, no-store",
|
|
19
|
+
"Vary": "Authorization, Accept-Encoding",
|
|
20
|
+
"Referrer-Policy": "no-referrer",
|
|
21
|
+
"X-Content-Type-Options": "nosniff",
|
|
22
|
+
"X-Frame-Options": "DENY",
|
|
23
|
+
"Content-Security-Policy": "default-src 'none'; frame-ancestors 'none'",
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def json_bytes(value):
|
|
28
|
+
"""Exact Decimal JSON number tokens; all other escaping uses the stdlib encoder."""
|
|
29
|
+
if isinstance(value, BaseModel):
|
|
30
|
+
value = value.model_dump(mode="python")
|
|
31
|
+
if isinstance(value, Decimal):
|
|
32
|
+
return get_datatype("number").text(value).encode("ascii")
|
|
33
|
+
if isinstance(value, dict):
|
|
34
|
+
return (
|
|
35
|
+
b"{" + b",".join(json_bytes(k) + b":" + json_bytes(v) for k, v in value.items()) + b"}"
|
|
36
|
+
)
|
|
37
|
+
if isinstance(value, tuple | list):
|
|
38
|
+
return b"[" + b",".join(json_bytes(v) for v in value) + b"]"
|
|
39
|
+
return json.dumps(value, ensure_ascii=False, allow_nan=False, separators=(",", ":")).encode(
|
|
40
|
+
"utf-8"
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class CanonicalJSONResponse(JSONResponse):
|
|
45
|
+
media_type = "application/json"
|
|
46
|
+
|
|
47
|
+
def render(self, content):
|
|
48
|
+
return json_bytes(content)
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
class ConditionalRead:
|
|
52
|
+
def __init__(
|
|
53
|
+
self,
|
|
54
|
+
request,
|
|
55
|
+
*,
|
|
56
|
+
actor_id,
|
|
57
|
+
kind,
|
|
58
|
+
key,
|
|
59
|
+
identifier,
|
|
60
|
+
page,
|
|
61
|
+
effective_date,
|
|
62
|
+
version_number,
|
|
63
|
+
valid_from=None,
|
|
64
|
+
valid_to=None,
|
|
65
|
+
clock: Clock = SYSTEM_CLOCK,
|
|
66
|
+
):
|
|
67
|
+
self.request = request
|
|
68
|
+
self.clock = clock
|
|
69
|
+
# The additive metadata changes response bytes; pre-metadata ETags must revalidate.
|
|
70
|
+
self.selection = (
|
|
71
|
+
"refrncr-json-v1-mapping-metadata",
|
|
72
|
+
actor_id,
|
|
73
|
+
kind,
|
|
74
|
+
key,
|
|
75
|
+
identifier,
|
|
76
|
+
page.offset,
|
|
77
|
+
page.limit,
|
|
78
|
+
effective_date.isoformat() if effective_date is not None else None,
|
|
79
|
+
version_number,
|
|
80
|
+
valid_from.isoformat() if valid_from is not None else None,
|
|
81
|
+
valid_to.isoformat() if valid_to is not None else None,
|
|
82
|
+
)
|
|
83
|
+
self.headers = {}
|
|
84
|
+
|
|
85
|
+
def __call__(self, result):
|
|
86
|
+
publications = result.publications
|
|
87
|
+
signature = [
|
|
88
|
+
(
|
|
89
|
+
p.key,
|
|
90
|
+
p.name,
|
|
91
|
+
p.description,
|
|
92
|
+
p.icon,
|
|
93
|
+
p.kind,
|
|
94
|
+
p.version.id,
|
|
95
|
+
p.version.number,
|
|
96
|
+
p.version.published_at.isoformat(),
|
|
97
|
+
p.version.effective_date.isoformat(),
|
|
98
|
+
p.valid_until.isoformat() if p.valid_until else None,
|
|
99
|
+
(p.source.dataset_key, p.source.version) if p.source else None,
|
|
100
|
+
)
|
|
101
|
+
+ ((p.status,) if p.status is not None else ())
|
|
102
|
+
for p in publications
|
|
103
|
+
]
|
|
104
|
+
etag = (
|
|
105
|
+
'"'
|
|
106
|
+
+ hashlib.sha256(json_bytes((self.selection, result.total, signature))).hexdigest()
|
|
107
|
+
+ '"'
|
|
108
|
+
)
|
|
109
|
+
modified = max(
|
|
110
|
+
(p.version.published_at for p in publications),
|
|
111
|
+
default=datetime(1970, 1, 1, tzinfo=UTC),
|
|
112
|
+
)
|
|
113
|
+
self.headers = {
|
|
114
|
+
"ETag": etag,
|
|
115
|
+
"Last-Modified": format_datetime(modified.replace(microsecond=0), usegmt=True),
|
|
116
|
+
"Cache-Control": PRIVATE,
|
|
117
|
+
}
|
|
118
|
+
values = self.request.headers.getlist("if-none-match")
|
|
119
|
+
if values:
|
|
120
|
+
raw = ",".join(values)
|
|
121
|
+
if len(raw) > 8192:
|
|
122
|
+
return False
|
|
123
|
+
if raw.strip() == "*":
|
|
124
|
+
return True
|
|
125
|
+
# A malformed list is ignored in full; commas inside opaque tags are legal.
|
|
126
|
+
if (
|
|
127
|
+
re.fullmatch(
|
|
128
|
+
r'\s*(?:W/)?"[\x21\x23-\x7e\x80-\xff]*"(?:\s*,\s*(?:W/)?"[\x21\x23-\x7e\x80-\xff]*")*\s*',
|
|
129
|
+
raw,
|
|
130
|
+
)
|
|
131
|
+
is None
|
|
132
|
+
):
|
|
133
|
+
return False
|
|
134
|
+
return etag in re.findall(r'(?:W/)?("[\x21\x23-\x7e\x80-\xff]*?")', raw)
|
|
135
|
+
values = self.request.headers.getlist("if-modified-since")
|
|
136
|
+
if len(values) != 1 or len(values[0]) > 128:
|
|
137
|
+
return False
|
|
138
|
+
try:
|
|
139
|
+
since = parsedate_to_datetime(values[0])
|
|
140
|
+
except (TypeError, ValueError, OverflowError):
|
|
141
|
+
return False
|
|
142
|
+
if since.tzinfo is None:
|
|
143
|
+
return False
|
|
144
|
+
# Collection deletion/page membership and independently mutable metadata cannot
|
|
145
|
+
# be proven unchanged by a publication date. ETags cover both exactly.
|
|
146
|
+
if self.selection[2] in {"datasets", "versions", "history"} or any(
|
|
147
|
+
p.metadata_updated_at > since
|
|
148
|
+
or datetime.combine(p.version.effective_date, datetime.min.time(), UTC) > since
|
|
149
|
+
for p in publications
|
|
150
|
+
):
|
|
151
|
+
return False
|
|
152
|
+
# Compare actual precision: same-second publications must never produce a false 304.
|
|
153
|
+
return modified <= since <= self.clock.now()
|