fix: list routes answer for permitted orgs only; org lists go through the hooks
This commit is contained in:
+6
-4
@@ -1,4 +1,5 @@
|
||||
import type { Pool } from 'pg';
|
||||
import { permittedOrgs } from './permissions.js';
|
||||
|
||||
/**
|
||||
* Wraps a query selecting the visible orgs (id, name, parent_id, metadata) and
|
||||
@@ -26,10 +27,11 @@ export function withOrgPaths(visSql: string): string {
|
||||
* the path start at the topmost org they can read, never above it.
|
||||
*/
|
||||
export async function readableOrgPaths(db: Pool, userId: string, view: string): Promise<Map<string, string[]>> {
|
||||
const { rows: candidates } = await db.query<{ id: string }>(
|
||||
`SELECT id FROM morbac.orgs WHERE morbac.is_allowed($1::UUID, id, 'read', $2)`, [userId, view]);
|
||||
const readable = await permittedOrgs(db, userId, candidates.map((c) => c.id), 'read', view);
|
||||
const { rows } = await db.query<{ id: string; path: string[] }>(
|
||||
withOrgPaths(
|
||||
`SELECT id, name, parent_id, NULL::jsonb AS metadata
|
||||
FROM morbac.orgs WHERE morbac.is_allowed($1::UUID, id, 'read', $2)`),
|
||||
[userId, view]);
|
||||
withOrgPaths('SELECT id, name, parent_id, NULL::jsonb AS metadata FROM morbac.orgs WHERE id = ANY($1::UUID[])'),
|
||||
[readable]);
|
||||
return new Map(rows.map((r) => [r.id, r.path]));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user