Feat/re prioritize field (STIT-494) - #174
Conversation
CD summary
|
| service | url | fqdn |
|---|---|---|
| api | open | pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| entity-linkage | open | pr-174-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| frontend | https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net | |
| stitch-llm | open | pr-174-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
Database (1)
| db_name | postgres_host | postgres_port | postgres_db |
|---|---|---|---|
| pr_174 | stitch-dev.postgres.database.azure.com |
5432 |
pr_174 |
Jobs (2)
| job | image | postgres_db | api_url | auth_mode |
|---|---|---|---|---|
| db-migrations | ghcr.io/rmi/stitch-api:pr-174@sha256:9ee1c1a54eb6d503458a65e8d316e7adfeebd0604b65204dd5f474041e108110 |
pr_174 |
||
| seed | ghcr.io/rmi/stitch-seed:pr-174@sha256:8feea43e61e9dec4048aaca03e8b6e3d2d7862d7b664e131747e07c6d90c0984 |
https://pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io/api/v1 |
stitch-client-bearer-token |
Images (4)
| build_time | commit_time | git_sha | image | image_digest |
|---|---|---|---|---|
| 2026-07-20T15:00:49Z | 2026-07-20T15:00:31Z | 2862088 | ghcr.io/rmi/stitch-api:pr-174 |
ghcr.io/rmi/stitch-api:pr-174@sha256:9ee1c1a54eb6d503458a65e8d316e7adfeebd0604b65204dd5f474041e108110 |
| 2026-07-20T15:00:49Z | 2026-07-20T15:00:31Z | 2862088 | ghcr.io/rmi/stitch-entity-linkage:pr-174 |
ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:c71bd03fa9a113f70d269b440fdc98619955ae2789a01fd21595dd617365608a |
| 2026-07-20T15:00:51Z | 2026-07-20T15:00:31Z | 2862088 | ghcr.io/rmi/stitch-seed:pr-174 |
ghcr.io/rmi/stitch-seed:pr-174@sha256:8feea43e61e9dec4048aaca03e8b6e3d2d7862d7b664e131747e07c6d90c0984 |
| 2026-07-20T15:00:54Z | 2026-07-20T15:00:31Z | 2862088 | ghcr.io/rmi/stitch-stitch-llm:pr-174 |
ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:f4e98e8a6352452a5d38b67437d3ac9e16182c70641d4cbd5295f8bb63e1ae2c |
There was a problem hiding this comment.
Pull request overview
This PR introduces per-field, per-source-record source-priority overrides (“curation”) so a curator can reorder which source wins for a specific field on a specific resource, and exposes that capability through a new API endpoint and a frontend edit/reorder UI.
Changes:
- Backend: implement tiered, per-field override ranking (curated tier above default tier) and add a PUT endpoint to persist ordered source PKs for a field.
- Frontend: add permission-gated “Edit/Save” UI to reorder source rows and call the new endpoint; add curated-row badging.
- Data/model: re-key the override table to
(resource_id, source_pk, colname)with audit columns; update shared view models/tests accordingly.
Reviewed changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| packages/stitch-ogsi/src/stitch/ogsi/model/init.py | Updates OGFieldSourceValueView contract: priority is now rank position; adds is_override. |
| deployments/stitch-frontend/src/queries/api.js | Adds updateFieldSourcePriority client call for the new PUT endpoint. |
| deployments/stitch-frontend/src/hooks/usePermissions.js | New hook to cache /auth/me claims and expose permission checks. |
| deployments/stitch-frontend/src/components/ResourceFieldCard.test.jsx | Expands tests for permission-gated edit controls, reorder/save behavior, and curated badges. |
| deployments/stitch-frontend/src/components/ResourceFieldCard.jsx | Adds reorder UI/logic, permission gating, save flow, and “curated” labeling. |
| deployments/api/tests/routers/test_route_permissions.py | Adds route-permission coverage for the new PUT endpoint. |
| deployments/api/tests/db/test_resource_actions.py | Adds integration coverage for set/reorder behavior, validation, tiering, and new-source-after-curation behavior. |
| deployments/api/src/stitch/api/routers/oil_gas_fields.py | Adds PUT /{id}/fields/{field}/sources/priority endpoint with permission enforcement and error mapping. |
| deployments/api/src/stitch/api/entities.py | Adds SetFieldPriorityRequest request model (ordered_source_pks). |
| deployments/api/src/stitch/api/db/queries.py | Refactors ranking to tiered ordering and adds field_source_candidates sharing ranking logic with coalescing. |
| deployments/api/src/stitch/api/db/og_field_resource_actions.py | Implements set_field_source_priority write path and updates field-source read path to use shared ranked SQL. |
| deployments/api/src/stitch/api/db/model/resource.py | Removes per-resource priority override usage from source listing helper (now default-priority only). |
| deployments/api/src/stitch/api/db/model/og_field_resource_source_priority.py | Re-keys override table to per-field, per-record; adds audit mixins and colname constraint; adds create() helper. |
| deployments/api/alembic/versions/a3f5c2e9b1d4_per_field_source_record_priority.py | Migration dropping/recreating override table with new PK columns, constraints, and audit fields. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
CD summary
|
| service | url | fqdn |
|---|---|---|
| api | open | pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| entity-linkage | open | pr-174-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| frontend | https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net | |
| stitch-llm | open | pr-174-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
Database (1)
| db_name | postgres_host | postgres_port | postgres_db |
|---|---|---|---|
| pr_174 | stitch-dev.postgres.database.azure.com |
5432 |
pr_174 |
Jobs (1)
| job | image | postgres_db |
|---|---|---|
| db-migrations | ghcr.io/rmi/stitch-api:pr-174@sha256:7910c4ab6a39b01187cd9c1a4dadbc49bbfba49520deb258d422491cbba9de56 |
pr_174 |
Images (4)
| build_time | commit_time | git_sha | image | image_digest |
|---|---|---|---|---|
| 2026-07-21T15:25:56Z | 2026-07-21T15:25:34Z | d402290 | ghcr.io/rmi/stitch-api:pr-174 |
ghcr.io/rmi/stitch-api:pr-174@sha256:7910c4ab6a39b01187cd9c1a4dadbc49bbfba49520deb258d422491cbba9de56 |
| 2026-07-21T15:25:52Z | 2026-07-21T15:25:34Z | d402290 | ghcr.io/rmi/stitch-entity-linkage:pr-174 |
ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:1e34571998729ab877f601f3425ae79959d2da8ccbecdd4e0ebeb553df18b329 |
| 2026-07-21T15:25:53Z | 2026-07-21T15:25:34Z | d402290 | ghcr.io/rmi/stitch-seed:pr-174 |
ghcr.io/rmi/stitch-seed:pr-174@sha256:2365a948ff908f7d3848e24c4089d131e9ad9c0043c447bc5a1ed6e53ebd8963 |
| 2026-07-21T15:25:53Z | 2026-07-21T15:25:34Z | d402290 | ghcr.io/rmi/stitch-stitch-llm:pr-174 |
ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:99a3786766e3e978f248cd3b1b9f46645c1d6dea33f4f3a04e443ebd537fe508 |
CD summary
|
| db_name | postgres_host | postgres_port | postgres_db |
|---|---|---|---|
| pr_174 | stitch-dev.postgres.database.azure.com |
5432 |
pr_174 |
Images (4)
| build_time | commit_time | git_sha | image | image_digest |
|---|---|---|---|---|
| 2026-07-30T12:54:12Z | 2026-07-30T12:53:49Z | 2fa0394 | ghcr.io/rmi/stitch-api:pr-174 |
ghcr.io/rmi/stitch-api:pr-174@sha256:902d8a7dc32e8d3358a97ec155dd26121408f6d214e246bc9c552290b5525523 |
| 2026-07-30T12:54:05Z | 2026-07-30T12:53:49Z | 2fa0394 | ghcr.io/rmi/stitch-entity-linkage:pr-174 |
ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:fee2d001adc5470e30a726440a0d6e73f2e0f345cac3660bab2cb850083c30d3 |
| 2026-07-30T12:54:08Z | 2026-07-30T12:53:49Z | 2fa0394 | ghcr.io/rmi/stitch-seed:pr-174 |
ghcr.io/rmi/stitch-seed:pr-174@sha256:068efbfec0bc564b34d02cecc7c1e5dcb75d5d2248b855e8feca740cf39475d2 |
| 2026-07-30T12:54:05Z | 2026-07-30T12:53:49Z | 2fa0394 | ghcr.io/rmi/stitch-stitch-llm:pr-174 |
ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:bdfc03f6919bd744db11da80bf130cb8aa90495204eb35a159094b60fcf52d60 |
CD summary
|
| service | url | fqdn |
|---|---|---|
| api | open | pr-174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| entity-linkage | open | pr-174-entity-linkage.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| frontend | https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net | |
| stitch-llm | open | pr-174-stitch-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
Database (1)
| db_name | postgres_host | postgres_port | postgres_db |
|---|---|---|---|
| pr_174 | stitch-dev.postgres.database.azure.com |
5432 |
pr_174 |
Jobs (1)
| job | image | postgres_db |
|---|---|---|
| db-migrations | ghcr.io/rmi/stitch-api:pr-174@sha256:53298f9a0f7125411c5ad7a1d8ac0e1e69162143f022010ec38323aefbc110f7 |
pr_174 |
Images (4)
| build_time | commit_time | git_sha | image | image_digest |
|---|---|---|---|---|
| 2026-07-30T13:13:05Z | 2026-07-30T13:12:49Z | 28f3cb0 | ghcr.io/rmi/stitch-api:pr-174 |
ghcr.io/rmi/stitch-api:pr-174@sha256:53298f9a0f7125411c5ad7a1d8ac0e1e69162143f022010ec38323aefbc110f7 |
| 2026-07-30T13:13:12Z | 2026-07-30T13:12:49Z | 28f3cb0 | ghcr.io/rmi/stitch-entity-linkage:pr-174 |
ghcr.io/rmi/stitch-entity-linkage:pr-174@sha256:0b96ee7f1d39419a8b0b57fa3810fce5ce169ced1d2c2a4556751cae5dff6d2f |
| 2026-07-30T13:13:07Z | 2026-07-30T13:12:49Z | 28f3cb0 | ghcr.io/rmi/stitch-seed:pr-174 |
ghcr.io/rmi/stitch-seed:pr-174@sha256:50521f32e46a2f76fa093dc32fd56e188e6bbe9c231c4bf0cff22698c3fc8f80 |
| 2026-07-30T13:13:05Z | 2026-07-30T13:12:49Z | 28f3cb0 | ghcr.io/rmi/stitch-stitch-llm:pr-174 |
ghcr.io/rmi/stitch-stitch-llm:pr-174@sha256:f3379fd76a21e78ac7c891a85ed28eb86f51af02f2c06f2e89d8001e5dab405f |
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 16 out of 16 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
deployments/api/src/stitch/api/db/og_field_resource_actions.py:252
set_field_source_priorityvalidates/reorders usinglicensed_sources, but then deletes all existing overrides for(resource_id, colname)regardless of licensing. Aresource:writeuser who is only licensed to a subset of sources could therefore unintentionally wipe curated ordering for sources they cannot see, affecting other users’ coalescing results. Consider scoping the delete/replace to the eligiblesource_pks derived fromfield_source_candidates(...)whenlicensed_sourcesis applied (or otherwise ensure the endpoint operates on a complete, non-licensed-filtered snapshot).
source_by_pk = {row.source_pk: row.source for row in rows}
await session.execute(
delete(OGFieldResourceSourcePriority).where(
OGFieldResourceSourcePriority.resource_id == id,
OGFieldResourceSourcePriority.colname == field,
)
)
mbarlow12
left a comment
There was a problem hiding this comment.
Big one is a sneaky potential for users with differing read permissions to overwrite priorities to all sources on a resource + attribute. See the second comment.
Other notes:
- do we need/want some kind of "reset to default" that deletes the rows from the overrides table?
- more integration tests for the endpoint? might be able to test the permissions bug explicitly
| user: CurrentUser, | ||
| claims: Claims, | ||
| id: int, | ||
| field: str, |
There was a problem hiding this comment.
NB: we could further constrain this to a Literal[...] that's maintained in stitch-ogsi.
| rows = ( | ||
| await session.execute(field_source_candidates(id, field, licensed_sources)) | ||
| ).all() |
There was a problem hiding this comment.
I think we need to pass all possible licensed_sources to this query. As it stands, if 2 users with resource:write permissions have different source:read:* permissions, they'll silently override the settings.
E.g.
- Curator A (all licenses) curates name as [ccr, rmi, wm, gem] → resource name is "CCR Name".
- Curator B, licensed for gem, rmi, & wm only, sees a three-row panel and sets priorities to
wm,rmi,gem(the result fromfield_source_candidateswill match the requested set) - Result: we call
deleteon resource_id + colname, soccrgets silently deleted.
We should either:
- loudly raise if a user tries to adjust source priorities where there are existing overrides for sources they can't read
- only change the priorities for the user's licensed sources, so in the above example, Curator B's request would only rearrange rmi, wm, and gem, resulting in the db storing [ccr, wm, rmi, gem]. Said another way, user's cannot change source priorities for sources they can't read.
| config, | ||
| resourceId, | ||
| fieldKey, | ||
| workingOrder, |
There was a problem hiding this comment.
Not big, but it's technically possible for workingOrder to become stale if sources somehow fetches & updates while the panel is open.
CD summary
|
| db_name | postgres_host | postgres_port | postgres_db |
|---|---|---|---|
| pr_0174 | stitch-dev.postgres.database.azure.com |
5432 |
pr_0174 |
Images (4)
| build_time | commit_time | git_sha | image | image_digest |
|---|---|---|---|---|
| 2026-08-05T14:23:28Z | 2026-08-05T14:23:07Z | 3dd166e | ghcr.io/rmi/stitch-api:pr-0174 |
ghcr.io/rmi/stitch-api:pr-0174@sha256:ec13a4c9c75cd5e24e01ac14397b7df4c8d3a39a6230fbbf01dba93d6c5ee6b6 |
| 2026-08-05T14:23:33Z | 2026-08-05T14:23:07Z | 3dd166e | ghcr.io/rmi/stitch-entity-linkage:pr-0174 |
ghcr.io/rmi/stitch-entity-linkage:pr-0174@sha256:781c86bbcd05f9e650706d4479042662e0df550aca9a691be2ca449ff7658063 |
| 2026-08-05T14:23:30Z | 2026-08-05T14:23:07Z | 3dd166e | ghcr.io/rmi/stitch-seed:pr-0174 |
ghcr.io/rmi/stitch-seed:pr-0174@sha256:477f142c3e52cdeb82803ad3323ae07ab4c7d9cd5b5e245b9edc4a0c3013d25c |
| 2026-08-05T14:23:26Z | 2026-08-05T14:23:07Z | 3dd166e | ghcr.io/rmi/stitch-stitch-llm:pr-0174 |
ghcr.io/rmi/stitch-stitch-llm:pr-0174@sha256:794f439adee32af4e53c9711f816f5d534cd4515a095c398b443cd04fc228584 |
CD summary
|
| service | url | fqdn |
|---|---|---|
| api | open | pr-0174-api.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| entity-linkage | open | pr-0174-el.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
| frontend | https://witty-mushroom-017a3dc1e-174.westus2.1.azurestaticapps.net | |
| stitch-llm | open | pr-0174-llm.purplegrass-c07d0a94.westus2.azurecontainerapps.io |
Database (1)
| db_name | postgres_host | postgres_port | postgres_db |
|---|---|---|---|
| pr_0174 | stitch-dev.postgres.database.azure.com |
5432 |
pr_0174 |
Jobs (1)
| job | image | postgres_db |
|---|---|---|
| db-migrations | ghcr.io/rmi/stitch-api:pr-0174@sha256:9b4e07ee0b452d8d6da9ccfdf79b1055a7f405528be3699a34dd88fca73179f6 |
pr_0174 |
Images (4)
| build_time | commit_time | git_sha | image | image_digest |
|---|---|---|---|---|
| 2026-08-05T16:49:37Z | 2026-08-05T16:49:17Z | 98bf28c | ghcr.io/rmi/stitch-api:pr-0174 |
ghcr.io/rmi/stitch-api:pr-0174@sha256:9b4e07ee0b452d8d6da9ccfdf79b1055a7f405528be3699a34dd88fca73179f6 |
| 2026-08-05T16:49:35Z | 2026-08-05T16:49:17Z | 98bf28c | ghcr.io/rmi/stitch-entity-linkage:pr-0174 |
ghcr.io/rmi/stitch-entity-linkage:pr-0174@sha256:042ab207da994910d57e539d0ad861b2bc5bd4b930fc01a6f6507363f9fd6480 |
| 2026-08-05T16:49:38Z | 2026-08-05T16:49:17Z | 98bf28c | ghcr.io/rmi/stitch-seed:pr-0174 |
ghcr.io/rmi/stitch-seed:pr-0174@sha256:16570036e3059cef0d8948180fc1eb57f7a077697bd53acda09f33f2ccaa5ea3 |
| 2026-08-05T16:49:33Z | 2026-08-05T16:49:17Z | 98bf28c | ghcr.io/rmi/stitch-stitch-llm:pr-0174 |
ghcr.io/rmi/stitch-stitch-llm:pr-0174@sha256:6d391d91c4cf88036ec01da2653868dc794782d082407fddf9c8b3c6c6811271 |
supersedes #164
Lets a
resource:writecurator reorder sources for each field in a resource, and persist in database (changing ordering for all users).Builds on sql-only coalescing logic (#170)
og_field_resource_source_prioritytable in DB to include field name (per field reordering rather than overall)PUT /oil-gas-fields/{id}/fields/{field}/sources/priority