asset check for metric

This commit is contained in:
dal 2025-03-11 16:51:08 -06:00
parent 8c43ca0403
commit 878e36bbeb
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
2 changed files with 86 additions and 62 deletions

View File

@ -240,7 +240,9 @@ pub enum AssetType {
Thread,
Collection,
Chat,
#[serde(alias = "metric")]
MetricFile,
#[serde(alias = "dashboard")]
DashboardFile,
}

View File

@ -8,17 +8,17 @@ use std::sync::Arc;
use uuid::Uuid;
use axum::extract::Path;
use middleware::AuthenticatedUser;
use axum::http::StatusCode;
use middleware::AuthenticatedUser;
use crate::routes::rest::ApiResponse;
use crate::utils::user::user_info::get_user_organization_id;
use database::enums::{AssetPermissionRole, AssetType, UserOrganizationRole};
use database::pool::{get_pg_pool, PgPool};
use database::schema::{
asset_permissions, collections_to_assets, dashboards, teams_to_users, threads_deprecated,
threads_to_dashboards, users_to_organizations,
asset_permissions, collections_to_assets, dashboards, metric_files, teams_to_users,
threads_deprecated, threads_to_dashboards, users_to_organizations,
};
use crate::routes::rest::ApiResponse;
use crate::utils::user::user_info::get_user_organization_id;
pub async fn get_asset_access(
Path((asset_type, asset_id)): Path<(AssetType, uuid::Uuid)>,
@ -121,10 +121,32 @@ async fn get_asset_access_handler(
(thread_info, user_permission)
}
AssetType::MetricFile => {
let mut conn = pg_pool.get().await?;
let metric_info = metric_files::table
.select((
metric_files::id,
metric_files::publicly_accessible,
metric_files::public_expiry_date,
))
.filter(metric_files::id.eq(&asset_id))
.filter(metric_files::deleted_at.is_null())
.first::<(Uuid, bool, Option<DateTime<Utc>>)>(&mut conn)
.await?;
let metric_info = (
metric_info.0,
metric_info.1,
false,
metric_info.2,
);
(metric_info, Some(AssetPermissionRole::Owner))
}
_ => {
return Err(anyhow!("Public access is not supported for chats yet"));
}
};
let (id, public, password_required, public_expiry_date) = asset_info;