Can create new accounts

This commit is contained in:
Pierre HUBERT 2025-04-09 19:24:59 +02:00
parent 132482c47d
commit 84e1c57dc9
3 changed files with 32 additions and 6 deletions

View File

@ -141,10 +141,10 @@ impl FromRequest for AuthExtractor {
// Check for authorization // Check for authorization
let uri = req.uri().to_string(); let uri = req.uri().to_string();
let authorized = (uri.starts_with("/api/accounts/") && token.right_account) let authorized = (uri.starts_with("/api/account") && token.right_account)
|| (uri.starts_with("/api/movements/") && token.right_movement) || (uri.starts_with("/api/movement") && token.right_movement)
|| (uri.starts_with("/api/inbox/") && token.right_inbox) || (uri.starts_with("/api/inbox") && token.right_inbox)
|| (uri.starts_with("/api/attachments/") && token.right_attachment) || (uri.starts_with("/api/attachment") && token.right_attachment)
|| (uri.starts_with("/api/auth/") && token.right_auth); || (uri.starts_with("/api/auth/") && token.right_auth);
if !authorized { if !authorized {

View File

@ -50,6 +50,19 @@ export class AccountApi {
}); });
} }
/**
* Create a new account
*/
static async Create(name: string): Promise<void> {
await APIClient.exec({
uri: `/account`,
method: "POST",
jsonData: {
name,
},
});
}
/** /**
* Update account * Update account
*/ */

View File

@ -20,6 +20,19 @@ export function AccountsRoute(): React.ReactElement {
const list = accounts.list.list; const list = accounts.list.list;
const createAccount = async () => {
try {
await AccountApi.Create(`New account #${list.length + 1}`);
snackbar("New account successfully created!");
await accounts.reload();
} catch (e) {
console.error("Failed to create new account!", e);
alert(`Failed to create new account! ${e}`);
}
};
const setDefaultAccount = async (account: Account) => { const setDefaultAccount = async (account: Account) => {
try { try {
await AccountApi.SetDefaultAccount(account); await AccountApi.SetDefaultAccount(account);
@ -125,12 +138,12 @@ export function AccountsRoute(): React.ReactElement {
actions={ actions={
<span> <span>
<Tooltip title="Create a new account"> <Tooltip title="Create a new account">
<IconButton onClick={undefined}> <IconButton onClick={createAccount}>
<AddIcon /> <AddIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>
<Tooltip title="Refresh accounts list"> <Tooltip title="Refresh accounts list">
<IconButton onClick={undefined}> <IconButton onClick={() => accounts.reload()}>
<RefreshIcon /> <RefreshIcon />
</IconButton> </IconButton>
</Tooltip> </Tooltip>