respect the config.api.METHOD config values
This commit is contained in:
parent
3c3ca2b87a
commit
1aa8a77b78
|
@ -16,4 +16,11 @@ fn check_api_enabled(state: &SharedState) -> Result<(), WithStatus<Json>> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn function_disabled_err() -> WithStatus<Json> {
|
||||||
|
warp::reply::with_status(
|
||||||
|
json(&ErrorMessage::new(Error::APIFunctionDisabled)),
|
||||||
|
StatusCode::SERVICE_UNAVAILABLE
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
pub mod get_all;
|
pub mod get_all;
|
|
@ -2,11 +2,15 @@ use warp::{reply::{Reply, json}, reject::Rejection, Filter};
|
||||||
|
|
||||||
use crate::web::{state::SharedState, rejection::HttpReject};
|
use crate::web::{state::SharedState, rejection::HttpReject};
|
||||||
|
|
||||||
use super::check_api_enabled;
|
use super::{check_api_enabled, function_disabled_err};
|
||||||
|
|
||||||
pub async fn get_all(state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
pub async fn get_all(state: SharedState) -> Result<Box<dyn Reply>, Rejection> {
|
||||||
if let Err(res) = check_api_enabled(&state) {
|
if let Err(res) = check_api_enabled(&state) {
|
||||||
return Ok(Box::new(res));
|
return Ok(Box::new(res))
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! state.config.api.get_all {
|
||||||
|
return Ok(Box::new(function_disabled_err()))
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(
|
Ok(
|
||||||
|
|
|
@ -3,6 +3,7 @@ use serde::{Serialize, Deserialize};
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
pub enum Error {
|
pub enum Error {
|
||||||
APIDisabled,
|
APIDisabled,
|
||||||
|
APIFunctionDisabled
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||||
|
@ -15,7 +16,8 @@ impl ErrorMessage {
|
||||||
pub fn new(error: Error) -> ErrorMessage {
|
pub fn new(error: Error) -> ErrorMessage {
|
||||||
ErrorMessage {
|
ErrorMessage {
|
||||||
details: match error {
|
details: match error {
|
||||||
Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into())
|
Error::APIDisabled => Some("API is disabled by the administrator. Please contact them for further details".into()),
|
||||||
|
Error::APIFunctionDisabled => Some("This API function is disabled by the administrator. Please contact them for further details.".into())
|
||||||
},
|
},
|
||||||
error,
|
error,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue