Add support for statistics routes
This commit is contained in:
		@@ -17,6 +17,7 @@ pub struct CreateTokenBody {
 | 
			
		||||
    right_inbox: bool,
 | 
			
		||||
    right_file: bool,
 | 
			
		||||
    right_auth: bool,
 | 
			
		||||
    right_stats: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(serde::Serialize)]
 | 
			
		||||
@@ -61,6 +62,7 @@ pub async fn create(auth: AuthExtractor, req: web::Json<CreateTokenBody>) -> Htt
 | 
			
		||||
        right_inbox: req.right_inbox,
 | 
			
		||||
        right_file: req.right_file,
 | 
			
		||||
        right_auth: req.right_auth,
 | 
			
		||||
        right_stats: req.right_stats,
 | 
			
		||||
    })
 | 
			
		||||
    .await?;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -145,7 +145,8 @@ impl FromRequest for AuthExtractor {
 | 
			
		||||
                    || (uri.starts_with("/api/movement") && token.right_movement)
 | 
			
		||||
                    || (uri.starts_with("/api/inbox") && token.right_inbox)
 | 
			
		||||
                    || (uri.starts_with("/api/file") && token.right_file)
 | 
			
		||||
                    || (uri.starts_with("/api/auth/") && token.right_auth);
 | 
			
		||||
                    || (uri.starts_with("/api/auth/") && token.right_auth)
 | 
			
		||||
                    || (uri.starts_with("/api/stats") && token.right_stats);
 | 
			
		||||
 | 
			
		||||
                if !authorized {
 | 
			
		||||
                    return Err(actix_web::error::ErrorBadRequest(
 | 
			
		||||
 
 | 
			
		||||
@@ -34,6 +34,7 @@ pub struct Token {
 | 
			
		||||
    pub right_inbox: bool,
 | 
			
		||||
    pub right_file: bool,
 | 
			
		||||
    pub right_auth: bool,
 | 
			
		||||
    pub right_stats: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
impl Token {
 | 
			
		||||
@@ -78,4 +79,5 @@ pub struct NewToken<'a> {
 | 
			
		||||
    pub right_inbox: bool,
 | 
			
		||||
    pub right_file: bool,
 | 
			
		||||
    pub right_auth: bool,
 | 
			
		||||
    pub right_stats: bool,
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -75,6 +75,7 @@ diesel::table! {
 | 
			
		||||
        right_inbox -> Bool,
 | 
			
		||||
        right_file -> Bool,
 | 
			
		||||
        right_auth -> Bool,
 | 
			
		||||
        right_stats -> Bool,
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,6 +19,7 @@ pub struct NewTokenInfo {
 | 
			
		||||
    pub right_inbox: bool,
 | 
			
		||||
    pub right_file: bool,
 | 
			
		||||
    pub right_auth: bool,
 | 
			
		||||
    pub right_stats: bool,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
/// Create a new token
 | 
			
		||||
@@ -39,6 +40,7 @@ pub async fn create(new_token: NewTokenInfo) -> anyhow::Result<Token> {
 | 
			
		||||
        right_movement: new_token.right_movement,
 | 
			
		||||
        right_inbox: new_token.right_inbox,
 | 
			
		||||
        right_file: new_token.right_file,
 | 
			
		||||
        right_stats: new_token.right_stats,
 | 
			
		||||
    };
 | 
			
		||||
 | 
			
		||||
    let res = diesel::insert_into(tokens::table)
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user