Skip to content

Alerts secondary feature detail fetch 404s: companion table has no view config - #565

Merged
conservationtimothy merged 3 commits into
mainfrom
fix/secondary-record-permission-config
Aug 4, 2026
Merged

Alerts secondary feature detail fetch 404s: companion table has no view config#565
conservationtimothy merged 3 commits into
mainfrom
fix/secondary-record-permission-config

Conversation

@conservationtimothy

@conservationtimothy conservationtimothy commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

Goal

Stop the alerts sidebar from 404ing when you click a secondary-dataset point (for example mapeo_data). Closes #564

Screenshots

Screenshot 2026-07-31 at 16 20 11 Screenshot 2026-07-31 at 16 20 01

What I changed and why

  • Fixed full-row lookups for secondary points failing because /api/<secondary_table>/<id> tried to resolve view config for the secondary table itself, which is never configured as its own view
  • Client now sends the alerts view context (permission_table + view_type) alongside secondary record requests
  • Server uses the alerts view's permissions, verifies the secondary table belongs to that view, then loads the row from the secondary table
  • Batch /records calls follow the same pattern

How I convinced myself this is right

The map already had the secondary points; only the follow-up detail request failed, so the data was fine and the permission lookup was wrong. Using the parent alerts view matches how the page is opened. Checking that the secondary table is actually that view’s secondary stops someone from pointing permission_table at a public view to read an unrelated table. Same-table fetches still only send view_type. Tests cover both the own-table and secondary-table query shapes.

What I'm not doing here

  • Changing how the alerts map loads secondary GeoJSON
  • Turning secondary tables into their own views
  • Updating other APIs (export, data) the same way

LLM use disclosure

Cursor Grok 4.5 with me driving

@conservationtimothy conservationtimothy changed the title Authorize secondary record fetches via the parent view config Alerts secondary feature detail fetch 404s: companion table has no view config Jul 31, 2026
Comment thread server/database/dbOperations.ts Outdated
Comment on lines +617 to +640
* Same-table reads use `dataTable` (+ optional `viewType`). Cross-table companion
* reads (e.g. alerts secondary dataset) pass `permissionTable` = the parent view's
* primary dataset plus `viewType`; `dataTable` must be that view's primary or
* secondary table.
*
* @param {string} dataTable - Warehouse table being read.
* @param {{ viewType?: ViewType; permissionTable?: string | null }} [options] - Auth scope.
* @returns {Promise<ViewConfig>} View config for permission checks.
*/
export const fetchTableConfigForDataAccess = async (
dataTable: string,
options: {
viewType?: ViewType;
permissionTable?: string | null;
} = {},
): Promise<ViewConfig> => {
const normalizedDataTable = normalizeTableName(dataTable);
const permissionTable = options.permissionTable?.trim()
? normalizeTableName(options.permissionTable)
: null;

if (!permissionTable) {
return fetchTableConfig(normalizedDataTable, options.viewType);
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I find "permission table" to be an unclear term for what you are trying to implement across this PR.

What if you called it isSecondaryTable. That would make this block so much clearer, plus what comes next e.g. about fetching primaryTable and secondaryTable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I am going to replace permissionTable with primaryDataset, since we need the primary dataset and view type to find and validate the configured secondary dataset.

Comment thread composables/useRecordCache.ts Outdated
Comment on lines +76 to +77
// Same-table view reads send view_type; companion reads send permission_table +
// view_type so the parent alerts/map view authorizes the secondary table.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I have read this three times and I don't understand what this is saying at all, and there is semantic overload going on here.

  • What is a "same-table view read"?
  • What is a "companion read"? (Is this redundant with "secondary table"?)
  • Here is a good example of what i meant in my other comment that the term "permission table" really does not clarify anything.
  • "so the parent alerts/map view authorizes the secondary table" -- I have no idea what this means. Views don't have "parents" and they don't authorize tables.

Can you make a strong effort to improve the readability of the code AND comments throughout this entire PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, absolutely

Comment thread composables/useViewType.ts Outdated
Comment on lines +27 to +31
type RecordFetchQuery = {
view_type?: ViewType;
primary_dataset?: string;
};

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Remember that we store types in types/index.ts.

@conservationtimothy
conservationtimothy merged commit a74cc3e into main Aug 4, 2026
3 checks passed
@conservationtimothy
conservationtimothy deleted the fix/secondary-record-permission-config branch August 4, 2026 06:31
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.

Alerts secondary feature detail fetch 404s: companion table has no view config

2 participants