dialtone_axum 0.1.0

Dialtone Axum Back-end
Documentation
use dialtone_common::{authz::host::authz_on_host, rest::users::web_user::SystemRole};

use crate::{err_unauthorized, response::response_error::ResponseError, start_server::SharedState};

pub async fn authz_sysrole(
    state: &SharedState,
    role: &SystemRole,
    host_name: &str,
) -> Result<(), ResponseError> {
    let user_authz = &state.read().await.user_authz;
    if !authz_on_host(user_authz, role, host_name) {
        err_unauthorized!()
    } else {
        Ok(())
    }
}

pub async fn authz_contentadmin(state: &SharedState, host_name: &str) -> Result<(), ResponseError> {
    authz_sysrole(state, &SystemRole::ContentAdmin, host_name).await
}

pub async fn authz_actoradmin(state: &SharedState, host_name: &str) -> Result<(), ResponseError> {
    authz_sysrole(state, &SystemRole::ActorAdmin, host_name).await
}

pub async fn authz_useradmin(state: &SharedState, host_name: &str) -> Result<(), ResponseError> {
    authz_sysrole(state, &SystemRole::UserAdmin, host_name).await
}