mirror of https://github.com/buster-so/buster.git
asset check for metric
This commit is contained in:
parent
8c43ca0403
commit
878e36bbeb
|
@ -240,7 +240,9 @@ pub enum AssetType {
|
||||||
Thread,
|
Thread,
|
||||||
Collection,
|
Collection,
|
||||||
Chat,
|
Chat,
|
||||||
|
#[serde(alias = "metric")]
|
||||||
MetricFile,
|
MetricFile,
|
||||||
|
#[serde(alias = "dashboard")]
|
||||||
DashboardFile,
|
DashboardFile,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,17 +8,17 @@ use std::sync::Arc;
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
use axum::extract::Path;
|
use axum::extract::Path;
|
||||||
use middleware::AuthenticatedUser;
|
|
||||||
use axum::http::StatusCode;
|
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::enums::{AssetPermissionRole, AssetType, UserOrganizationRole};
|
||||||
use database::pool::{get_pg_pool, PgPool};
|
use database::pool::{get_pg_pool, PgPool};
|
||||||
use database::schema::{
|
use database::schema::{
|
||||||
asset_permissions, collections_to_assets, dashboards, teams_to_users, threads_deprecated,
|
asset_permissions, collections_to_assets, dashboards, metric_files, teams_to_users,
|
||||||
threads_to_dashboards, users_to_organizations,
|
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(
|
pub async fn get_asset_access(
|
||||||
Path((asset_type, asset_id)): Path<(AssetType, uuid::Uuid)>,
|
Path((asset_type, asset_id)): Path<(AssetType, uuid::Uuid)>,
|
||||||
|
@ -121,10 +121,32 @@ async fn get_asset_access_handler(
|
||||||
|
|
||||||
(thread_info, user_permission)
|
(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"));
|
return Err(anyhow!("Public access is not supported for chats yet"));
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
let (id, public, password_required, public_expiry_date) = asset_info;
|
let (id, public, password_required, public_expiry_date) = asset_info;
|
||||||
|
|
Loading…
Reference in New Issue