mirror of https://github.com/buster-so/buster.git
fixing public access for metric_files/data
This commit is contained in:
parent
e508feb877
commit
32705b3048
|
@ -38,17 +38,6 @@ export async function getMetricDataHandler(
|
||||||
versionNumber?: number,
|
versionNumber?: number,
|
||||||
reportFileId?: string
|
reportFileId?: string
|
||||||
): Promise<MetricDataResponse> {
|
): Promise<MetricDataResponse> {
|
||||||
// Get user's organization
|
|
||||||
const userOrg = await getUserOrganizationId(user.id);
|
|
||||||
|
|
||||||
if (!userOrg) {
|
|
||||||
throw new HTTPException(403, {
|
|
||||||
message: 'You must be part of an organization to access metric data',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
const { organizationId } = userOrg;
|
|
||||||
|
|
||||||
// Retrieve metric definition from database with data source info
|
// Retrieve metric definition from database with data source info
|
||||||
const metric = await getMetricWithDataSource({ metricId, versionNumber });
|
const metric = await getMetricWithDataSource({ metricId, versionNumber });
|
||||||
|
|
||||||
|
@ -58,13 +47,6 @@ export async function getMetricDataHandler(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Verify metric belongs to user's organization
|
|
||||||
if (metric.organizationId !== organizationId) {
|
|
||||||
throw new HTTPException(403, {
|
|
||||||
message: 'You do not have permission to view this metric',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check if user has permission to view this metric file
|
// Check if user has permission to view this metric file
|
||||||
// hasAssetPermission internally handles:
|
// hasAssetPermission internally handles:
|
||||||
// 1. Direct permissions
|
// 1. Direct permissions
|
||||||
|
@ -76,7 +58,7 @@ export async function getMetricDataHandler(
|
||||||
assetId: metricId,
|
assetId: metricId,
|
||||||
assetType: 'metric_file',
|
assetType: 'metric_file',
|
||||||
requiredRole: 'can_view',
|
requiredRole: 'can_view',
|
||||||
organizationId,
|
organizationId: metric.organizationId,
|
||||||
workspaceSharing: metric.workspaceSharing ?? 'none',
|
workspaceSharing: metric.workspaceSharing ?? 'none',
|
||||||
publiclyAccessible: metric.publiclyAccessible,
|
publiclyAccessible: metric.publiclyAccessible,
|
||||||
publicExpiryDate: metric.publicExpiryDate ?? undefined,
|
publicExpiryDate: metric.publicExpiryDate ?? undefined,
|
||||||
|
@ -98,13 +80,13 @@ export async function getMetricDataHandler(
|
||||||
console.info('Checking R2 cache for metric data', {
|
console.info('Checking R2 cache for metric data', {
|
||||||
metricId,
|
metricId,
|
||||||
reportFileId,
|
reportFileId,
|
||||||
organizationId,
|
organizationId: metric.organizationId,
|
||||||
version: resolvedVersion,
|
version: resolvedVersion,
|
||||||
});
|
});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const cachedData = await getCachedMetricData(
|
const cachedData = await getCachedMetricData(
|
||||||
organizationId,
|
metric.organizationId,
|
||||||
metricId,
|
metricId,
|
||||||
reportFileId,
|
reportFileId,
|
||||||
resolvedVersion
|
resolvedVersion
|
||||||
|
@ -184,22 +166,26 @@ export async function getMetricDataHandler(
|
||||||
console.info('Writing metric data to cache', {
|
console.info('Writing metric data to cache', {
|
||||||
metricId,
|
metricId,
|
||||||
reportFileId,
|
reportFileId,
|
||||||
organizationId,
|
organizationId: metric.organizationId,
|
||||||
version: resolvedVersion,
|
version: resolvedVersion,
|
||||||
rowCount: trimmedData.length,
|
rowCount: trimmedData.length,
|
||||||
});
|
});
|
||||||
|
|
||||||
// Fire and forget - don't wait for cache write
|
// Fire and forget - don't wait for cache write
|
||||||
setCachedMetricData(organizationId, metricId, reportFileId, response, resolvedVersion).catch(
|
setCachedMetricData(
|
||||||
(error) => {
|
metric.organizationId,
|
||||||
console.error('Failed to cache metric data', {
|
metricId,
|
||||||
metricId,
|
reportFileId,
|
||||||
reportFileId,
|
response,
|
||||||
version: resolvedVersion,
|
resolvedVersion
|
||||||
error: error instanceof Error ? error.message : 'Unknown error',
|
).catch((error) => {
|
||||||
});
|
console.error('Failed to cache metric data', {
|
||||||
}
|
metricId,
|
||||||
);
|
reportFileId,
|
||||||
|
version: resolvedVersion,
|
||||||
|
error: error instanceof Error ? error.message : 'Unknown error',
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
|
|
|
@ -48,11 +48,9 @@ export async function checkPermission(check: AssetPermissionCheck): Promise<Asse
|
||||||
} = check;
|
} = check;
|
||||||
|
|
||||||
// Check cache first (only for single role checks)
|
// Check cache first (only for single role checks)
|
||||||
if (!Array.isArray(requiredRole)) {
|
const cached = getCachedPermission(userId, assetId, assetType, requiredRole);
|
||||||
const cached = getCachedPermission(userId, assetId, assetType, requiredRole);
|
if (cached !== undefined) {
|
||||||
if (cached !== undefined) {
|
return cached;
|
||||||
return cached;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get user's organization memberships
|
// Get user's organization memberships
|
||||||
|
@ -112,6 +110,8 @@ export async function checkPermission(check: AssetPermissionCheck): Promise<Asse
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.info('publiclyAccessible', publiclyAccessible);
|
||||||
|
|
||||||
if (publiclyAccessible) {
|
if (publiclyAccessible) {
|
||||||
const hasPublicAccessCheck = hasPublicAccess(
|
const hasPublicAccessCheck = hasPublicAccess(
|
||||||
publiclyAccessible,
|
publiclyAccessible,
|
||||||
|
|
Loading…
Reference in New Issue