Can use backup routes from API

This commit is contained in:
Pierre HUBERT 2025-05-02 15:31:29 +02:00
parent e159d3c963
commit c68ddffc5e
9 changed files with 32 additions and 2 deletions

View File

@ -23,7 +23,8 @@ CREATE TABLE tokens
right_inbox BOOLEAN NOT NULL DEFAULT false, right_inbox BOOLEAN NOT NULL DEFAULT false,
right_file 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 right_stats BOOLEAN NOT NULL DEFAULT false,
right_backup BOOLEAN NOT NULL DEFAULT false
); );
CREATE TABLE files CREATE TABLE files

View File

@ -18,6 +18,7 @@ pub struct CreateTokenBody {
right_file: bool, right_file: bool,
right_auth: bool, right_auth: bool,
right_stats: bool, right_stats: bool,
right_backup: bool,
} }
#[derive(serde::Serialize)] #[derive(serde::Serialize)]
@ -63,6 +64,7 @@ pub async fn create(auth: AuthExtractor, req: web::Json<CreateTokenBody>) -> Htt
right_file: req.right_file, right_file: req.right_file,
right_auth: req.right_auth, right_auth: req.right_auth,
right_stats: req.right_stats, right_stats: req.right_stats,
right_backup: req.right_backup,
}) })
.await?; .await?;

View File

@ -146,7 +146,8 @@ impl FromRequest for AuthExtractor {
|| (uri.starts_with("/api/inbox") && token.right_inbox) || (uri.starts_with("/api/inbox") && token.right_inbox)
|| (uri.starts_with("/api/file") && token.right_file) || (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); || (uri.starts_with("/api/stats") && token.right_stats)
|| (uri.starts_with("/api/backup") && token.right_backup);
if !authorized { if !authorized {
return Err(actix_web::error::ErrorBadRequest( return Err(actix_web::error::ErrorBadRequest(

View File

@ -35,6 +35,7 @@ pub struct Token {
pub right_file: bool, pub right_file: bool,
pub right_auth: bool, pub right_auth: bool,
pub right_stats: bool, pub right_stats: bool,
pub right_backup: bool,
} }
impl Token { impl Token {
@ -80,4 +81,5 @@ pub struct NewToken<'a> {
pub right_file: bool, pub right_file: bool,
pub right_auth: bool, pub right_auth: bool,
pub right_stats: bool, pub right_stats: bool,
pub right_backup: bool,
} }

View File

@ -76,6 +76,7 @@ diesel::table! {
right_file -> Bool, right_file -> Bool,
right_auth -> Bool, right_auth -> Bool,
right_stats -> Bool, right_stats -> Bool,
right_backup -> Bool,
} }
} }

View File

@ -20,6 +20,7 @@ pub struct NewTokenInfo {
pub right_file: bool, pub right_file: bool,
pub right_auth: bool, pub right_auth: bool,
pub right_stats: bool, pub right_stats: bool,
pub right_backup: bool,
} }
/// Create a new token /// Create a new token
@ -41,6 +42,7 @@ pub async fn create(new_token: NewTokenInfo) -> anyhow::Result<Token> {
right_inbox: new_token.right_inbox, right_inbox: new_token.right_inbox,
right_file: new_token.right_file, right_file: new_token.right_file,
right_stats: new_token.right_stats, right_stats: new_token.right_stats,
right_backup: new_token.right_backup,
}; };
let res = diesel::insert_into(tokens::table) let res = diesel::insert_into(tokens::table)

View File

@ -32,6 +32,7 @@ export interface NewToken {
right_file: boolean; right_file: boolean;
right_auth: boolean; right_auth: boolean;
right_stats: boolean; right_stats: boolean;
right_backup: boolean;
} }
export class TokensApi { export class TokensApi {

View File

@ -37,6 +37,7 @@ export function CreateTokenDialog(p: {
right_inbox: false, right_inbox: false,
right_movement: false, right_movement: false,
right_stats: false, right_stats: false,
right_backup: false,
}; };
const clearForm = () => { const clearForm = () => {
@ -79,6 +80,7 @@ export function CreateTokenDialog(p: {
right_auth: true, right_auth: true,
right_inbox: true, right_inbox: true,
right_stats: false, right_stats: false,
right_backup: false,
}); });
}; };
@ -216,6 +218,18 @@ export function CreateTokenDialog(p: {
}); });
}} }}
/> />
<br />
<CheckboxInput
editable
label="Right: backup routes"
checked={newToken.right_backup}
onValueChange={(v) => {
setNewToken({
...newToken,
right_backup: v,
});
}}
/>
</DialogContent> </DialogContent>
<DialogActions> <DialogActions>
<Button onClick={cancel}>Cancel</Button> <Button onClick={cancel}>Cancel</Button>

View File

@ -197,6 +197,12 @@ function TokensRouteInner(p: {
flex: 2, flex: 2,
type: "boolean", type: "boolean",
}, },
{
field: "right_backup",
headerName: "Backup",
flex: 2,
type: "boolean",
},
{ {
field: "actions", field: "actions",
type: "actions", type: "actions",