fix
This commit is contained in:
@@ -54,8 +54,6 @@ pub struct AppConfig {
|
||||
pub quickwit_endpoint: Option<String>,
|
||||
#[serde(default)]
|
||||
pub quickwit_index: Option<String>,
|
||||
#[serde(default = "default_tenant_name")]
|
||||
pub default_tenant_name: String,
|
||||
#[serde(default = "default_worker_max_document_bytes")]
|
||||
pub worker_max_document_bytes: u64,
|
||||
#[serde(default)]
|
||||
@@ -171,10 +169,6 @@ fn default_aws_region() -> String {
|
||||
"us-east-1".to_string()
|
||||
}
|
||||
|
||||
fn default_tenant_name() -> String {
|
||||
"admin".to_string()
|
||||
}
|
||||
|
||||
fn default_worker_max_document_bytes() -> u64 {
|
||||
200 * 1024 * 1024
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use axum::{async_trait, extract::FromRequestParts, http::request::Parts};
|
||||
use diesel::{
|
||||
dsl::{exists, select},
|
||||
pg::PgConnection,
|
||||
@@ -14,7 +13,6 @@ use crate::{
|
||||
jobs::{enqueue_job, JOB_PROVISION_TENANT},
|
||||
models::{Tenant, TenantStatus},
|
||||
schema::tenants::dsl,
|
||||
state::AppState,
|
||||
};
|
||||
|
||||
pub struct TenantRepository;
|
||||
@@ -136,25 +134,6 @@ pub fn apply_tenant_guc(conn: &mut PgConnection, tenant_id: Uuid) -> AppResult<(
|
||||
.map_err(AppError::from)
|
||||
}
|
||||
|
||||
pub struct TenantContext {
|
||||
pub tenant: Tenant,
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
impl FromRequestParts<AppState> for TenantContext {
|
||||
type Rejection = AppError;
|
||||
|
||||
async fn from_request_parts(
|
||||
_parts: &mut Parts,
|
||||
state: &AppState,
|
||||
) -> Result<Self, Self::Rejection> {
|
||||
let tenant = state
|
||||
.tenants
|
||||
.get_by_name(&state.config.default_tenant_name)?;
|
||||
Ok(Self { tenant })
|
||||
}
|
||||
}
|
||||
|
||||
fn normalize_storage_root(raw: Option<&str>, tenant_id: Uuid) -> String {
|
||||
match raw.map(str::trim) {
|
||||
Some(root) if !root.is_empty() => {
|
||||
|
||||
@@ -33,6 +33,8 @@ const MIGRATIONS: EmbeddedMigrations = embed_migrations!("migrations");
|
||||
|
||||
static DB_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
|
||||
|
||||
const TEST_TENANT_NAME: &str = "test_tenant";
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[derive(Clone)]
|
||||
pub struct StoredObject {
|
||||
@@ -140,7 +142,6 @@ impl TestApp {
|
||||
s3_bucket: "test-bucket".to_string(),
|
||||
quickwit_endpoint: None,
|
||||
quickwit_index: None,
|
||||
default_tenant_name: "admin".to_string(),
|
||||
worker_max_document_bytes: 200 * 1024 * 1024,
|
||||
webauthn_rp_id: Some("localhost".to_string()),
|
||||
webauthn_origin: Some("http://localhost".to_string()),
|
||||
@@ -190,10 +191,11 @@ impl TestApp {
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub async fn storage_key_for(&self, key: &str) -> Result<String> {
|
||||
self.ensure_default_tenant().await?;
|
||||
let tenant = self
|
||||
.state
|
||||
.tenants
|
||||
.get_by_name(&self.state.config.default_tenant_name)
|
||||
.get_by_name(TEST_TENANT_NAME)
|
||||
.map_err(|err| anyhow!("default tenant not found: {:?}", err))?;
|
||||
let root = tenant
|
||||
.storage_root
|
||||
@@ -205,11 +207,7 @@ impl TestApp {
|
||||
pub async fn insert_user(&self, username: &str, password: &str, _role: &str) -> Result<Uuid> {
|
||||
let username = username.to_string();
|
||||
let password = password.to_string();
|
||||
let tenant_id = self
|
||||
.state
|
||||
.tenants
|
||||
.tenant_id_for_name(&self.state.config.default_tenant_name)
|
||||
.map_err(|err| anyhow!("default tenant not found: {:?}", err))?;
|
||||
let tenant_id = self.ensure_default_tenant().await?;
|
||||
self.with_conn(move |conn| {
|
||||
let password_hash = hash_password(&password)?;
|
||||
let user = NewUser {
|
||||
@@ -264,7 +262,7 @@ impl TestApp {
|
||||
}
|
||||
|
||||
async fn ensure_default_tenant(&self) -> Result<Uuid> {
|
||||
let name_value = self.state.config.default_tenant_name.clone();
|
||||
let name_value = TEST_TENANT_NAME.to_string();
|
||||
let quickwit_enabled = self.state.config.quickwit_endpoint.is_some();
|
||||
self.with_conn(move |conn| {
|
||||
use backend::schema::tenants::dsl as tenants_dsl;
|
||||
|
||||
Reference in New Issue
Block a user