Skip to content

Commit 49e1838

Browse files
ksfikasclaude
andcommitted
The API documentation link of a data service is a choice on the form (on by default)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
1 parent 5dc0ae6 commit 49e1838

4 files changed

Lines changed: 16 additions & 5 deletions

File tree

‎providerharvest_service/ckan_load.py‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ def remove(target: CkanTarget, client: ckan_client.CKANActionClient) -> bool:
392392
DEFAULT_KEYS = ("tags", "access_rights", "license", "themes", "legislation", "hvd_categories", "contact_name", "contact_email", "publisher_name",
393393
"publisher_email", "publisher_identifier", "publisher_type", "documentation", "landing_page", "rights")
394394
META_DEFAULTS = {
395-
"title": "", "description": "", "endpoint_description": "", "public": False, "tags": ["API"], "access_rights": "PUBLIC", "license": "CC_BY_4_0", "format": "JSON", "themes": [],
395+
"title": "", "description": "", "endpoint_description": "", "public": False, "include_docs": True, "tags": ["API"], "access_rights": "PUBLIC", "license": "CC_BY_4_0", "format": "JSON", "themes": [],
396396
"legislation": [ckan_vocab.LEGISLATION[0][0]], "hvd_categories": [], "contact_name": "", "contact_email": "", "publisher_name": "", "publisher_email": "",
397397
"publisher_identifier": "", "publisher_type": "NationalAuthority", "documentation": [], "landing_page": [], "rights": "",
398398
}
@@ -411,6 +411,7 @@ def normalise_meta(raw: dict) -> dict:
411411
"""The details of a data service, checked and cleaned. Raises ``CkanLoadError`` with a sentence for the person."""
412412
meta = dict(META_DEFAULTS)
413413
meta.update({k: v for k, v in (raw or {}).items() if k in META_DEFAULTS})
414+
meta["include_docs"] = meta["include_docs"] is not False and str(meta["include_docs"]).lower() not in ("0", "false", "no")
414415
meta["public"] = meta["public"] is True or str(meta["public"]).lower() in ("1", "true", "public") # (only when it is made: an existing entry keeps its own)
415416
meta["title"] = str(meta["title"] or "").strip()
416417
if not meta["title"]:
@@ -565,7 +566,7 @@ def _push_service(target: CkanTarget, source: ProviderSource, pipeline: Transfor
565566
from providerharvest_service import api_docs # (late: it reads the same tables)
566567

567568
docs_url = (base_url if base_url is not None else public_base_url()) + api_docs.docs_path(source, pipeline)
568-
if docs_url not in payload["documentation"]: # the loader's own API documentation of the endpoint always goes with the service
569+
if meta.get("include_docs", True) and docs_url not in payload["documentation"]: # the loader's own API documentation of the endpoint goes with the service, unless left out
569570
payload["documentation"] = list(payload["documentation"]) + [docs_url]
570571
try:
571572
if target.resource_id:

‎providerharvest_service/templates/load/ckan.html‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,8 @@ <h3 style="font-size:0.95rem; margin:1.1rem 0 0;">Publisher</h3>
199199
<div class="svc-only">
200200
<label for="svc_documentation">Documentation (links, one per line; the loader's own API documentation of the address is added for you)</label>
201201
<textarea id="svc_documentation" name="svc_documentation" rows="2">{{ meta.documentation|join("\n") }}</textarea>
202-
<p class="muted" style="margin:0.2rem 0 0.6rem;">Added automatically: <a href="{{ docs_url }}" target="_blank" rel="noopener"><code>{{ docs_url }}</code></a> -- the API documentation of the public address (it exists once the address is public, which saving adds).</p>
202+
<input type="hidden" name="svc_docs_sent" value="1">
203+
<label class="check" style="margin:0.3rem 0 0.6rem;"><input type="checkbox" name="svc_docs" value="1"{% if meta.include_docs %} checked{% endif %}> Also list the loader's API documentation of the public address: <a href="{{ docs_url }}" target="_blank" rel="noopener"><code>{{ docs_url }}</code></a></label>
203204
<label for="svc_landing_page">Landing page (links, one per line)</label>
204205
<textarea id="svc_landing_page" name="svc_landing_page" rows="2">{{ meta.landing_page|join("\n") }}</textarea>
205206
<label for="svc_rights">Rights statement</label>

‎providerharvest_service/ui_ckan.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ def _meta_from_form(form) -> dict:
102102
if licence == "__other__":
103103
licence = str(form.get("svc_license_other") or "").strip()
104104
return {
105-
"public": str(form.get("svc_public") or "") == "public", "title": form.get("svc_title"), "description": form.get("svc_description"), "endpoint_description": form.get("svc_endpoint_description"),
105+
"public": str(form.get("svc_public") or "") == "public", "include_docs": "svc_docs_sent" not in form or str(form.get("svc_docs") or "") == "1", "title": form.get("svc_title"), "description": form.get("svc_description"), "endpoint_description": form.get("svc_endpoint_description"),
106106
"license": licence, "access_rights": form.get("svc_access_rights"), "themes": many("svc_themes"),
107107
"legislation": many("svc_legislation") + _lines(form.get("svc_legislation_other")), "hvd_categories": many("svc_hvd"),
108108
"contact_name": form.get("svc_contact_name"), "contact_email": form.get("svc_contact_email"), "publisher_name": form.get("svc_publisher_name"),

‎tests/test_ckan_service_ui.py‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,13 @@ def test_a_data_service_can_be_created_public_and_a_later_push_leaves_its_visibi
268268

269269
def test_the_form_shows_the_documentation_link_that_will_be_added(client, registry, ckan):
270270
page = client.get(_page(registry)).text
271-
assert "Added automatically:" in page and BASE + "/api-docs/opencar-data" in page
271+
assert 'name="svc_docs"' in page and BASE + "/api-docs/opencar-data" in page and "checked" in page.split('name="svc_docs"')[1][:40]
272+
273+
274+
def test_the_documentation_link_can_be_left_out_and_the_choice_is_kept(client, registry, ckan):
275+
_service(client, registry, svc_docs_sent="1") # (the box is not ticked: a browser sends nothing for it)
276+
assert ckan.packages["svc1"]["documentation"] == ["https://docs.example.gr/a", "https://docs.example.gr/b"]
277+
page = client.get(_page(registry)).text
278+
assert "checked" not in page.split('name="svc_docs"')[1][:40]
279+
_service(client, registry, svc_docs_sent="1", svc_docs="1")
280+
assert BASE + "/api-docs/opencar-data" in ckan.packages["svc1"]["documentation"]

0 commit comments

Comments
 (0)