Can create new accounts
This commit is contained in:
parent
132482c47d
commit
84e1c57dc9
@ -141,10 +141,10 @@ impl FromRequest for AuthExtractor {
|
||||
|
||||
// Check for authorization
|
||||
let uri = req.uri().to_string();
|
||||
let authorized = (uri.starts_with("/api/accounts/") && token.right_account)
|
||||
|| (uri.starts_with("/api/movements/") && token.right_movement)
|
||||
|| (uri.starts_with("/api/inbox/") && token.right_inbox)
|
||||
|| (uri.starts_with("/api/attachments/") && token.right_attachment)
|
||||
let authorized = (uri.starts_with("/api/account") && token.right_account)
|
||||
|| (uri.starts_with("/api/movement") && token.right_movement)
|
||||
|| (uri.starts_with("/api/inbox") && token.right_inbox)
|
||||
|| (uri.starts_with("/api/attachment") && token.right_attachment)
|
||||
|| (uri.starts_with("/api/auth/") && token.right_auth);
|
||||
|
||||
if !authorized {
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -20,6 +20,19 @@ export function AccountsRoute(): React.ReactElement {
|
||||
|
||||
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) => {
|
||||
try {
|
||||
await AccountApi.SetDefaultAccount(account);
|
||||
@ -125,12 +138,12 @@ export function AccountsRoute(): React.ReactElement {
|
||||
actions={
|
||||
<span>
|
||||
<Tooltip title="Create a new account">
|
||||
<IconButton onClick={undefined}>
|
||||
<IconButton onClick={createAccount}>
|
||||
<AddIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
<Tooltip title="Refresh accounts list">
|
||||
<IconButton onClick={undefined}>
|
||||
<IconButton onClick={() => accounts.reload()}>
|
||||
<RefreshIcon />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
|
Loading…
x
Reference in New Issue
Block a user