Add support for statistics routes
This commit is contained in:
		@@ -22,7 +22,8 @@ CREATE TABLE tokens
 | 
			
		||||
    right_movement BOOLEAN      NOT NULL DEFAULT false,
 | 
			
		||||
    right_inbox    BOOLEAN      NOT NULL DEFAULT false,
 | 
			
		||||
    right_file     BOOLEAN      NOT NULL DEFAULT false,
 | 
			
		||||
    right_auth     BOOLEAN      NOT NULL DEFAULT false
 | 
			
		||||
    right_auth     BOOLEAN      NOT NULL DEFAULT false,
 | 
			
		||||
    right_stats    BOOLEAN      NOT NULL DEFAULT false
 | 
			
		||||
);
 | 
			
		||||
 | 
			
		||||
CREATE TABLE files
 | 
			
		||||
 
 | 
			
		||||
@@ -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)
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,7 @@ export interface Token {
 | 
			
		||||
  right_inbox: boolean;
 | 
			
		||||
  right_file: boolean;
 | 
			
		||||
  right_auth: boolean;
 | 
			
		||||
  right_stats: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export interface TokenWithSecret extends Token {
 | 
			
		||||
@@ -30,6 +31,7 @@ export interface NewToken {
 | 
			
		||||
  right_inbox: boolean;
 | 
			
		||||
  right_file: boolean;
 | 
			
		||||
  right_auth: boolean;
 | 
			
		||||
  right_stats: boolean;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
export class TokensApi {
 | 
			
		||||
 
 | 
			
		||||
@@ -36,6 +36,7 @@ export function CreateTokenDialog(p: {
 | 
			
		||||
    right_auth: false,
 | 
			
		||||
    right_inbox: false,
 | 
			
		||||
    right_movement: false,
 | 
			
		||||
    right_stats: false,
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  const clearForm = () => {
 | 
			
		||||
@@ -77,6 +78,7 @@ export function CreateTokenDialog(p: {
 | 
			
		||||
      right_file: true,
 | 
			
		||||
      right_auth: true,
 | 
			
		||||
      right_inbox: true,
 | 
			
		||||
      right_stats: false,
 | 
			
		||||
    });
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
@@ -202,6 +204,18 @@ export function CreateTokenDialog(p: {
 | 
			
		||||
            });
 | 
			
		||||
          }}
 | 
			
		||||
        />
 | 
			
		||||
        <br />
 | 
			
		||||
        <CheckboxInput
 | 
			
		||||
          editable
 | 
			
		||||
          label="Right: statistics routes"
 | 
			
		||||
          checked={newToken.right_stats}
 | 
			
		||||
          onValueChange={(v) => {
 | 
			
		||||
            setNewToken({
 | 
			
		||||
              ...newToken,
 | 
			
		||||
              right_stats: v,
 | 
			
		||||
            });
 | 
			
		||||
          }}
 | 
			
		||||
        />
 | 
			
		||||
      </DialogContent>
 | 
			
		||||
      <DialogActions>
 | 
			
		||||
        <Button onClick={cancel}>Cancel</Button>
 | 
			
		||||
 
 | 
			
		||||
@@ -191,6 +191,12 @@ function TokensRouteInner(p: {
 | 
			
		||||
      flex: 2,
 | 
			
		||||
      type: "boolean",
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      field: "right_stats",
 | 
			
		||||
      headerName: "Stats",
 | 
			
		||||
      flex: 2,
 | 
			
		||||
      type: "boolean",
 | 
			
		||||
    },
 | 
			
		||||
    {
 | 
			
		||||
      field: "actions",
 | 
			
		||||
      type: "actions",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user