* DRAFT chore(backend): upgrade sqlx to ^0.7 related to: * https://github.com/windmill-labs/windmill/pull/1858 * https://github.com/launchbadge/sqlx/issues/1163#issuecomment-1627685514 * (vol. 2) in 0.7, `Transaction` can no longer implement `Executor` directly ref:afb6b1066e/examples/postgres/transaction/src/main.rs (L14-L17)notice that I'm temporarly using my custom patch16e4c9a8f3it's related to https://github.com/launchbadge/sqlx/issues/2611 * post git rebase chores * use upstream fix from 0.7.1 * fix compile --------- Co-authored-by: Ruben Fiszel <ruben@windmill.dev> Co-authored-by: Ruben Fiszel <ruben@rubenfiszel.com>
36 lines
993 B
Rust
36 lines
993 B
Rust
/*
|
|
* Author: Ruben Fiszel
|
|
* Copyright: Windmill Labs, Inc 2022
|
|
* This file and its contents are licensed under the AGPLv3 License.
|
|
* Please see the included NOTICE for copyright information and
|
|
* LICENSE-AGPL for a copy of the license.
|
|
*/
|
|
|
|
use sqlx::{Postgres, Transaction};
|
|
use windmill_common::{
|
|
error::{self, Error},
|
|
users::SUPERADMIN_SECRET_EMAIL,
|
|
};
|
|
|
|
pub async fn require_super_admin<'c>(
|
|
db: &mut Transaction<'c, Postgres>,
|
|
email: &str,
|
|
) -> error::Result<()> {
|
|
if email == SUPERADMIN_SECRET_EMAIL {
|
|
return Ok(());
|
|
}
|
|
let is_admin = sqlx::query_scalar!("SELECT super_admin FROM password WHERE email = $1", email)
|
|
.fetch_optional(&mut **db)
|
|
.await
|
|
.map_err(|e| Error::InternalErr(format!("fetching super admin: {e}")))?
|
|
.unwrap_or(false);
|
|
|
|
if !is_admin {
|
|
Err(Error::NotAuthorized(
|
|
"This endpoint require caller to be a super admin".to_owned(),
|
|
))
|
|
} else {
|
|
Ok(())
|
|
}
|
|
}
|