Skip to content

Commit ef526ad

Browse files
Merge pull request #1005 from geo-engine/limit-1
limit 1
2 parents 071ba4e + ced9afa commit ef526ad

File tree

2 files changed

+50
-20
lines changed

2 files changed

+50
-20
lines changed

services/src/pro/datasets/postgres.rs

Lines changed: 45 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,9 @@ where
221221
user_permitted_datasets p JOIN datasets d
222222
ON(p.dataset_id = d.id)
223223
WHERE
224-
p.user_id = $1 AND d.id = $2",
224+
p.user_id = $1 AND d.id = $2
225+
LIMIT
226+
1",
225227
)
226228
.await?;
227229

@@ -249,7 +251,9 @@ where
249251
user_permitted_datasets p JOIN datasets d
250252
ON(p.dataset_id = d.id)
251253
WHERE
252-
p.user_id = $1 AND d.id = $2",
254+
p.user_id = $1 AND d.id = $2
255+
LIMIT
256+
1",
253257
)
254258
.await?;
255259

@@ -386,13 +390,15 @@ where
386390
let stmt = tx
387391
.prepare(
388392
"
389-
SELECT
390-
d.meta_data
391-
FROM
392-
user_permitted_datasets p JOIN datasets d
393-
ON (p.dataset_id = d.id)
394-
WHERE
395-
d.id = $1 AND p.user_id = $2",
393+
SELECT
394+
d.meta_data
395+
FROM
396+
user_permitted_datasets p JOIN datasets d
397+
ON (p.dataset_id = d.id)
398+
WHERE
399+
d.id = $1 AND p.user_id = $2
400+
LIMIT
401+
1",
396402
)
397403
.await
398404
.map_err(|e| geoengine_operators::error::Error::MetaData {
@@ -476,7 +482,9 @@ where
476482
user_permitted_datasets p JOIN datasets d
477483
ON (p.dataset_id = d.id)
478484
WHERE
479-
d.id = $1 AND p.user_id = $2",
485+
d.id = $1 AND p.user_id = $2
486+
LIMIT
487+
1",
480488
)
481489
.await
482490
.map_err(|e| geoengine_operators::error::Error::MetaData {
@@ -841,6 +849,7 @@ mod tests {
841849
pro::{
842850
contexts::ProPostgresContext,
843851
ge_context,
852+
permissions::PermissionDb,
844853
users::{UserAuth, UserSession},
845854
},
846855
};
@@ -900,7 +909,31 @@ mod tests {
900909
.is_empty());
901910
}
902911

903-
async fn add_single_dataset(db: &ProPostgresDb<NoTls>, session: &UserSession) {
912+
#[ge_context::test]
913+
async fn it_loads_own_datasets(app_ctx: ProPostgresContext<NoTls>) {
914+
let session_a = app_ctx.create_anonymous_session().await.unwrap();
915+
916+
let db_a = app_ctx.session_context(session_a.clone()).db();
917+
918+
let DatasetIdAndName {
919+
id: dataset_id,
920+
name: _,
921+
} = add_single_dataset(&db_a, &session_a).await;
922+
923+
// we are already owner, but we give the permission again to test the permission check
924+
db_a.add_permission(session_a.user.id.into(), dataset_id, Permission::Read)
925+
.await
926+
.unwrap();
927+
928+
db_a.load_loading_info(&dataset_id).await.unwrap();
929+
let _: Box<dyn MetaData<OgrSourceDataset, VectorResultDescriptor, VectorQueryRectangle>> =
930+
db_a.meta_data(&DataId::from(dataset_id)).await.unwrap();
931+
}
932+
933+
async fn add_single_dataset(
934+
db: &ProPostgresDb<NoTls>,
935+
session: &UserSession,
936+
) -> DatasetIdAndName {
904937
let loading_info = OgrSourceDataset {
905938
file_name: PathBuf::from("test.csv"),
906939
layer_name: "test.csv".to_owned(),
@@ -971,6 +1004,6 @@ mod tests {
9711004
meta_data,
9721005
)
9731006
.await
974-
.unwrap();
1007+
.unwrap()
9751008
}
9761009
}

services/src/util/config.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,11 @@ use snafu::ResultExt;
99
use std::collections::{HashMap, HashSet};
1010
use std::net::SocketAddr;
1111
use std::path::PathBuf;
12-
use std::sync::{OnceLock, RwLock};
12+
use std::sync::{LazyLock, RwLock};
1313
use url::Url;
1414

15-
static SETTINGS: OnceLock<RwLock<Config>> = OnceLock::new();
15+
static SETTINGS: LazyLock<RwLock<Config>> = LazyLock::new(init_settings);
1616

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

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

3635
settings = settings.add_source(files);
3736

38-
// Override config with environment variables that start with `GEOENGINE_`,
39-
// e.g. `GEOENGINE_WEB__EXTERNAL_ADDRESS=https://path.to.geoengine.io`
37+
// Override config with environment variables that start with `GEOENGINE__`,
38+
// e.g. `GEOENGINE__LOGGING__LOG_SPEC=debug`
4039
// Note: Since variables contain underscores, we need to use something different
41-
// for seperating groups, for instance double underscores `__`
40+
// for separating groups, for instance double underscores `__`
4241
settings = settings.add_source(Environment::with_prefix("geoengine").separator("__"));
4342

4443
RwLock::new(
@@ -82,7 +81,6 @@ where
8281
T: Into<config::Value>,
8382
{
8483
let mut settings = SETTINGS
85-
.get_or_init(init_settings)
8684
.write()
8785
.map_err(|_error| error::Error::ConfigLockFailed)?;
8886

@@ -100,7 +98,6 @@ where
10098
T: Deserialize<'a>,
10199
{
102100
SETTINGS
103-
.get_or_init(init_settings)
104101
.read()
105102
.map_err(|_error| error::Error::ConfigLockFailed)?
106103
.get::<T>(key)

0 commit comments

Comments
 (0)