Skip to content

Commit

Permalink
Merge pull request #1005 from geo-engine/limit-1
Browse files Browse the repository at this point in the history
limit 1
  • Loading branch information
michaelmattig authored Jan 8, 2025
2 parents 071ba4e + ced9afa commit ef526ad
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 20 deletions.
57 changes: 45 additions & 12 deletions services/src/pro/datasets/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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?;

Expand Down Expand Up @@ -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?;

Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -841,6 +849,7 @@ mod tests {
pro::{
contexts::ProPostgresContext,
ge_context,
permissions::PermissionDb,
users::{UserAuth, UserSession},
},
};
Expand Down Expand Up @@ -900,7 +909,31 @@ mod tests {
.is_empty());
}

async fn add_single_dataset(db: &ProPostgresDb<NoTls>, session: &UserSession) {
#[ge_context::test]
async fn it_loads_own_datasets(app_ctx: ProPostgresContext<NoTls>) {
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<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>> =
db_a.meta_data(&DataId::from(dataset_id)).await.unwrap();
}

async fn add_single_dataset(
db: &ProPostgresDb<NoTls>,
session: &UserSession,
) -> DatasetIdAndName {
let loading_info = OgrSourceDataset {
file_name: PathBuf::from("test.csv"),
layer_name: "test.csv".to_owned(),
Expand Down Expand Up @@ -971,6 +1004,6 @@ mod tests {
meta_data,
)
.await
.unwrap();
.unwrap()
}
}
13 changes: 5 additions & 8 deletions services/src/util/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RwLock<Config>> = OnceLock::new();
static SETTINGS: LazyLock<RwLock<Config>> = LazyLock::new(init_settings);

// TODO: change to `LazyLock' once stable
fn init_settings() -> RwLock<Config> {
let mut settings = Config::builder();

Expand All @@ -35,10 +34,10 @@ fn init_settings() -> RwLock<Config> {

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(
Expand Down Expand Up @@ -82,7 +81,6 @@ where
T: Into<config::Value>,
{
let mut settings = SETTINGS
.get_or_init(init_settings)
.write()
.map_err(|_error| error::Error::ConfigLockFailed)?;

Expand All @@ -100,7 +98,6 @@ where
T: Deserialize<'a>,
{
SETTINGS
.get_or_init(init_settings)
.read()
.map_err(|_error| error::Error::ConfigLockFailed)?
.get::<T>(key)
Expand Down

0 comments on commit ef526ad

Please sign in to comment.