Skip to content

better context in retire endpoints and unretire option - #180

Merged
pooleycodes merged 8 commits into
mainfrom
2620-transform-page---improve-retire-endpoint-section
Jul 29, 2026
Merged

better context in retire endpoints and unretire option#180
pooleycodes merged 8 commits into
mainfrom
2620-transform-page---improve-retire-endpoint-section

Conversation

@pooleycodes

@pooleycodes pooleycodes commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Improves the Retire endpoints section on the check-transform page and adds an unretire option, to make it easier to manage org/datasets that have multiple active endpoints (e.g. BFL / DC data).

  • Existing endpoints are now shown as a table — endpoint URL, entry date, latest status, latest log entry date — ordered by entry-date descending, instead of a bare checkbox list.
  • Each checkbox represents the desired retired state: ticking an active endpoint retires it; unticking a currently-retired endpoint unretires it (retired rows render pre-checked). The diff is computed server-side and persisted on RequestMeta
  • The endpoint being added (when it's already in the endpoint CSV) is shown disabled and cannot be retired/unretired, with server-side protection so a crafted POST can't change it either.

Ships together with the downstream config change digital-land/config#2851, which adds unretire_endpoints handling to bin/add_data.py (clears end-date in endpoint.csv / source.csv, the inverse of retire).

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

  1. Add data for an organisation/dataset that already has one or more existing endpoints (ideally a mix of active and already-retired). - Plymouth BFL is a good one
  2. On the check-transform page, confirm the Retire endpoints table shows endpoint URL, entry date, latest status and latest log entry date, ordered newest-first.
  3. Confirm already-retired endpoints are pre-checked and tagged "Currently retired"; confirm the endpoint being added is disabled and tagged "Endpoint being added".
  4. Tick an active endpoint (retire) and untick a retired one (unretire), continue to preview, and confirm the retire/unretire summaries reflect your selections.

Added/updated tests?

  • Yes
  • No, and this is why: please replace this line with details on why tests
    have not been included
  • I need help with writing tests

[optional] Are there any post deployment tasks we need to perform?

No - config PR already in

[optional] Are there any dependencies on other PRs or Work?

No

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • Added support for “endpoint unretire” alongside “endpoint retire” across the preview and confirmation steps, including a new unretire summary section.
    • Updated the check-transform UI to present retire/unretire options using an enriched endpoints table with clear “current” and “retired” states.
  • Bug Fixes
    • Improved check-transform enrichment with accurate current/retired protection, latest log status, and consistent sorting.
  • Documentation
    • Updated check-transform and architecture docs to reflect unretire behaviour.
  • Tests
    • Added/updated unit and integration tests to cover unretire handling and new endpoint information helpers.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: b7325550-6eed-45e9-9add-2855c2961ca6

📥 Commits

Reviewing files that changed from the base of the PR and between 4b76a60 and 832dc34.

📒 Files selected for processing (3)
  • application/blueprints/datamanager/services/endpoint.py
  • docs/datamanager/add-data.md
  • docs/datamanager/architecture.md
💤 Files with no reviewable changes (1)
  • application/blueprints/datamanager/services/endpoint.py

Walkthrough

The datamanager now enriches endpoint selections with metadata and log status, supports retire and unretire selections, persists both lists, displays an unretire preview, and passes unretire endpoints to the asynchronous workflow.

Changes

Endpoint lifecycle management

Layer / File(s) Summary
Endpoint metadata and selection UI
application/blueprints/datamanager/services/endpoint.py, application/blueprints/datamanager/controllers/transform.py, application/templates/datamanager/check-transform.html, tests/unit/blueprints/datamanager/..., tests/acceptance/blueprints/datamanager/...
Endpoint metadata and log summaries now populate entry dates, retirement state, current-endpoint state, and latest status in the selection table.
Retire and unretire selection persistence
application/blueprints/datamanager/router.py, application/db/models.py, migrations/versions/..., tests/integration/blueprints/datamanager/test_datamanager_integration.py
The transform POST handler derives retire and unretire changes, excludes the current endpoint, and stores both lists in RequestMeta using the new database column.
Preview and workflow dispatch
application/blueprints/datamanager/controllers/preview.py, application/blueprints/datamanager/services/github.py, application/templates/datamanager/entities_preview.html, docs/datamanager/...
Preview renders retire and unretire summaries, while the workflow payload includes the comma-separated unretire_endpoints value. Documentation describes the persisted selections and downstream workflow hand-off.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Operator
  participant TransformForm
  participant DatamanagerRouter
  participant RequestMeta
  participant PreviewController
  participant GithubWorkflow
  Operator->>TransformForm: select retire or unretire endpoints
  TransformForm->>DatamanagerRouter: submit endpoint selections
  DatamanagerRouter->>RequestMeta: persist endpoint lists
  PreviewController->>RequestMeta: load endpoint lists
  PreviewController->>GithubWorkflow: dispatch retire and unretire endpoints
Loading

Possibly related PRs

Suggested reviewers: gibahjoe

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.05% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise and accurately reflects the main change: added context for retire endpoints and an unretire option.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2620-transform-page---improve-retire-endpoint-section

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 28, 2026

Copy link
Copy Markdown

📝 Documentation reminder

This PR changes 318 lines of code (threshold 100) but does not update anything in docs/. If this change affects behaviour, please update the relevant docs (e.g. docs/datamanager/).

This is a non-blocking reminder — it will not prevent merging.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 6

🧹 Nitpick comments (1)
application/blueprints/datamanager/controllers/transform.py (1)

446-447: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Sequential remote calls for endpoint info and log summary.

get_endpoint_info_for_hashes and get_endpoint_log_summary_for_hashes are independent lookups run back-to-back on every check-transform render. The log-summary function's own docstring warns the log table query is slow, so serialising these two round-trips adds avoidable latency to a page load.

Consider running them concurrently (e.g. concurrent.futures.ThreadPoolExecutor) to overlap the two HTTP calls.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@application/blueprints/datamanager/controllers/transform.py` around lines 446
- 447, Update the check-transform rendering flow around
get_endpoint_info_for_hashes and get_endpoint_log_summary_for_hashes to execute
these independent lookups concurrently, using the project’s established
concurrency approach such as concurrent.futures.ThreadPoolExecutor. Collect both
results before continuing, and preserve the existing endpoint_data and log_data
behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@application/blueprints/datamanager/router.py`:
- Around line 258-292: The POST handler must stop and return an error when
_current_endpoint_hash(request_id) cannot resolve the request, rather than
filtering and persisting retirement changes. Check the helper result immediately
after calling _current_endpoint_hash, distinguish the None failure case, and
return the handler’s established error response before calculating to_retire or
to_unretire.
- Around line 253-268: The endpoint change calculations around
_current_endpoint_hash must use server-side endpoint hashes and retirement state
as the source of truth, rather than trusting presented_endpoints or
currently_retired from the request. Resolve the allowed endpoint set and
currently retired hashes for request_id, intersect submitted retire_endpoints
with allowed hashes, and compute to_retire and to_unretire only from that
validated state before persistence or workflow forwarding.

In `@application/blueprints/datamanager/services/endpoint.py`:
- Around line 60-71: Validate every value in hashes as a locally verified
SHA-256 hexadecimal digest before constructing hash_list in the endpoint query
flow. Reject or safely handle any invalid value before it reaches the SQL
interpolation, while preserving the existing query behavior for valid hashes and
removing the injection risk identified in the hash_list construction.

In `@application/blueprints/datamanager/services/github.py`:
- Line 281: Update the endpoints_to_unretire parameter and its matching list
parameter to use an explicit nullable type, such as list[str] | None, while
retaining the existing None default and behavior.

In `@tests/integration/blueprints/datamanager/test_datamanager_integration.py`:
- Around line 1132-1137: Add ("presented_endpoints", current_hash) to the test
case’s expected entries alongside the existing presented_endpoints values,
ensuring current_hash is included in the intersection and the current-endpoint
protection filter is genuinely exercised.

In `@tests/unit/blueprints/datamanager/controllers/test_transform.py`:
- Around line 211-217: Update both patch targets from
get_endpoint_urls_for_hashes to get_endpoint_info_for_hashes:
tests/unit/blueprints/datamanager/controllers/test_transform.py lines 211-217
and tests/acceptance/blueprints/datamanager/test_flagged_resources.py lines
440-452. Keep the existing mocked return values and test behavior unchanged.

---

Nitpick comments:
In `@application/blueprints/datamanager/controllers/transform.py`:
- Around line 446-447: Update the check-transform rendering flow around
get_endpoint_info_for_hashes and get_endpoint_log_summary_for_hashes to execute
these independent lookups concurrently, using the project’s established
concurrency approach such as concurrent.futures.ThreadPoolExecutor. Collect both
results before continuing, and preserve the existing endpoint_data and log_data
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: ab1fc2ba-4c33-4800-89af-77856236e53f

📥 Commits

Reviewing files that changed from the base of the PR and between 92507b4 and 54205a4.

📒 Files selected for processing (13)
  • application/blueprints/datamanager/controllers/preview.py
  • application/blueprints/datamanager/controllers/transform.py
  • application/blueprints/datamanager/router.py
  • application/blueprints/datamanager/services/endpoint.py
  • application/blueprints/datamanager/services/github.py
  • application/db/models.py
  • application/templates/datamanager/check-transform.html
  • application/templates/datamanager/entities_preview.html
  • migrations/versions/b8c9d0e1f2a3_add_request_meta_endpoints_to_unretire.py
  • tests/acceptance/blueprints/datamanager/test_flagged_resources.py
  • tests/integration/blueprints/datamanager/test_datamanager_integration.py
  • tests/unit/blueprints/datamanager/controllers/test_transform.py
  • tests/unit/blueprints/datamanager/services/test_endpoint.py

Comment thread application/blueprints/datamanager/router.py Outdated
Comment thread application/blueprints/datamanager/router.py
Comment thread application/blueprints/datamanager/services/endpoint.py Outdated
Comment thread application/blueprints/datamanager/services/github.py Outdated
Comment thread tests/unit/blueprints/datamanager/controllers/test_transform.py
@pooleycodes
pooleycodes marked this pull request as ready for review July 29, 2026 13:12
@gibahjoe

Copy link
Copy Markdown
Contributor

📝 Documentation reminder

This PR changes 318 lines of code (threshold 100) but does not update anything in docs/. If this change affects behaviour, please update the relevant docs (e.g. docs/datamanager/).

This is a non-blocking reminder — it will not prevent merging.

No documentation update or its not needed?

@gibahjoe gibahjoe left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@pooleycodes
pooleycodes merged commit 20df4c5 into main Jul 29, 2026
4 checks passed
@pooleycodes
pooleycodes deleted the 2620-transform-page---improve-retire-endpoint-section branch July 29, 2026 15:11
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.

Transform page - improve retire endpoint section

2 participants