mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-19 08:01:25 +00:00
33 lines
917 B
Rust
33 lines
917 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 windmill_common::{
|
|
error::{self, Error},
|
|
users::SUPERADMIN_SECRET_EMAIL,
|
|
DB,
|
|
};
|
|
|
|
pub async fn require_super_admin(db: &DB, 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(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(())
|
|
}
|
|
}
|