From 964164cfd7aa9ed9e9553306e260c028af29a53b Mon Sep 17 00:00:00 2001 From: Christian Beilschmidt Date: Mon, 30 Dec 2024 14:27:07 +0100 Subject: [PATCH 1/2] limit 1 --- services/src/pro/datasets/postgres.rs | 28 +++++++++++++++++---------- services/src/util/config.rs | 13 +++++-------- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/services/src/pro/datasets/postgres.rs b/services/src/pro/datasets/postgres.rs index 376645122..7ab99dc1a 100644 --- a/services/src/pro/datasets/postgres.rs +++ b/services/src/pro/datasets/postgres.rs @@ -221,7 +221,9 @@ where user_permitted_datasets p JOIN datasets d ON(p.dataset_id = d.id) WHERE - p.user_id = $1 AND d.id = $2", + p.user_id = $1 AND d.id = $2 + LIMIT + 1", ) .await?; @@ -249,7 +251,9 @@ where user_permitted_datasets p JOIN datasets d ON(p.dataset_id = d.id) WHERE - p.user_id = $1 AND d.id = $2", + p.user_id = $1 AND d.id = $2 + LIMIT + 1", ) .await?; @@ -386,13 +390,15 @@ where let stmt = tx .prepare( " - SELECT - d.meta_data - FROM - user_permitted_datasets p JOIN datasets d - ON (p.dataset_id = d.id) - WHERE - d.id = $1 AND p.user_id = $2", + SELECT + d.meta_data + FROM + user_permitted_datasets p JOIN datasets d + ON (p.dataset_id = d.id) + WHERE + d.id = $1 AND p.user_id = $2 + LIMIT + 1", ) .await .map_err(|e| geoengine_operators::error::Error::MetaData { @@ -476,7 +482,9 @@ where user_permitted_datasets p JOIN datasets d ON (p.dataset_id = d.id) WHERE - d.id = $1 AND p.user_id = $2", + d.id = $1 AND p.user_id = $2 + LIMIT + 1", ) .await .map_err(|e| geoengine_operators::error::Error::MetaData { diff --git a/services/src/util/config.rs b/services/src/util/config.rs index 9cf370b33..4225689bb 100644 --- a/services/src/util/config.rs +++ b/services/src/util/config.rs @@ -9,12 +9,11 @@ use snafu::ResultExt; use std::collections::{HashMap, HashSet}; use std::net::SocketAddr; use std::path::PathBuf; -use std::sync::{OnceLock, RwLock}; +use std::sync::{LazyLock, RwLock}; use url::Url; -static SETTINGS: OnceLock> = OnceLock::new(); +static SETTINGS: LazyLock> = LazyLock::new(init_settings); -// TODO: change to `LazyLock' once stable fn init_settings() -> RwLock { let mut settings = Config::builder(); @@ -35,10 +34,10 @@ fn init_settings() -> RwLock { settings = settings.add_source(files); - // Override config with environment variables that start with `GEOENGINE_`, - // e.g. `GEOENGINE_WEB__EXTERNAL_ADDRESS=https://path.to.geoengine.io` + // Override config with environment variables that start with `GEOENGINE__`, + // e.g. `GEOENGINE__LOGGING__LOG_SPEC=debug` // Note: Since variables contain underscores, we need to use something different - // for seperating groups, for instance double underscores `__` + // for separating groups, for instance double underscores `__` settings = settings.add_source(Environment::with_prefix("geoengine").separator("__")); RwLock::new( @@ -82,7 +81,6 @@ where T: Into, { let mut settings = SETTINGS - .get_or_init(init_settings) .write() .map_err(|_error| error::Error::ConfigLockFailed)?; @@ -100,7 +98,6 @@ where T: Deserialize<'a>, { SETTINGS - .get_or_init(init_settings) .read() .map_err(|_error| error::Error::ConfigLockFailed)? .get::(key) From ced9afa0a766c2d302cc92c7b5ec5a98a6328b0f Mon Sep 17 00:00:00 2001 From: Christian Beilschmidt Date: Tue, 31 Dec 2024 09:40:27 +0100 Subject: [PATCH 2/2] test to ensure limit 1 fix --- services/src/pro/datasets/postgres.rs | 29 +++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/services/src/pro/datasets/postgres.rs b/services/src/pro/datasets/postgres.rs index 7ab99dc1a..2711891c5 100644 --- a/services/src/pro/datasets/postgres.rs +++ b/services/src/pro/datasets/postgres.rs @@ -849,6 +849,7 @@ mod tests { pro::{ contexts::ProPostgresContext, ge_context, + permissions::PermissionDb, users::{UserAuth, UserSession}, }, }; @@ -908,7 +909,31 @@ mod tests { .is_empty()); } - async fn add_single_dataset(db: &ProPostgresDb, session: &UserSession) { + #[ge_context::test] + async fn it_loads_own_datasets(app_ctx: ProPostgresContext) { + let session_a = app_ctx.create_anonymous_session().await.unwrap(); + + let db_a = app_ctx.session_context(session_a.clone()).db(); + + let DatasetIdAndName { + id: dataset_id, + name: _, + } = add_single_dataset(&db_a, &session_a).await; + + // we are already owner, but we give the permission again to test the permission check + db_a.add_permission(session_a.user.id.into(), dataset_id, Permission::Read) + .await + .unwrap(); + + db_a.load_loading_info(&dataset_id).await.unwrap(); + let _: Box> = + db_a.meta_data(&DataId::from(dataset_id)).await.unwrap(); + } + + async fn add_single_dataset( + db: &ProPostgresDb, + session: &UserSession, + ) -> DatasetIdAndName { let loading_info = OgrSourceDataset { file_name: PathBuf::from("test.csv"), layer_name: "test.csv".to_owned(), @@ -979,6 +1004,6 @@ mod tests { meta_data, ) .await - .unwrap(); + .unwrap() } }