Load the list of roles in memory

This commit is contained in:
Pierre HUBERT 2021-05-14 18:51:57 +02:00
parent 5334fd9430
commit 69c68f43cb
4 changed files with 57 additions and 22 deletions

View File

@ -1,21 +1,21 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" /> <link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" /> <meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" /> <meta name="theme-color" content="#000000" />
<meta <meta
name="description" name="description"
content="Comunic moderation & administration" content="Comunic moderation & administration"
/> />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" /> <link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!-- <!--
manifest.json provides metadata used when your web app is installed on a manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
--> -->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> <link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!-- <!--
Notice the use of %PUBLIC_URL% in the tags above. Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build. It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML. Only files inside the `public` folder can be referenced from the HTML.
@ -24,12 +24,18 @@
work correctly both with client-side routing and a non-root public URL. work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`. Learn how to configure a non-root public URL by running `npm run build`.
--> -->
<title>Comunic Console</title> <title>Comunic Console</title>
</head>
<body> <style>
<noscript>You need to enable JavaScript to run this app.</noscript> body {
<div id="root"></div> background-color: #212121;
<!-- }
</style>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template. This HTML file is a template.
If you open it directly in the browser, you will see an empty page. If you open it directly in the browser, you will see an empty page.
@ -38,6 +44,5 @@
To begin the development, run `npm start` or `yarn start`. To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`. To create a production bundle, use `npm run build` or `yarn build`.
--> --></body>
</body>
</html> </html>

View File

@ -133,7 +133,7 @@ export class AdminKeyHelper {
* @param adminID The id of the target administrator * @param adminID The id of the target administrator
*/ */
static async GetAdminKeys(adminID: number): Promise<AdminAccountKey[]> { static async GetAdminKeys(adminID: number): Promise<AdminAccountKey[]> {
return await serverRequest("keys/keys", { return await serverRequest("keys/list", {
id: adminID, id: adminID,
}); });
} }

View File

@ -0,0 +1,26 @@
/**
* Admin roles helper
*
* @author Pierre Hubert
*/
import { serverRequest } from "./APIHelper";
export interface AdminRole {
id: string;
name: string;
description: string;
}
let RolesList: AdminRole[] = [];
export class AdminRolesHelper {
/**
* Load the list of roles.
*
* @throws In case of failure
*/
static async LoadRolesList() {
RolesList = await serverRequest("roles/list");
}
}

View File

@ -6,6 +6,7 @@
import React from "react"; import React from "react";
import { AccountHelper } from "../../helpers/AccountHelper"; import { AccountHelper } from "../../helpers/AccountHelper";
import { AdminRolesHelper } from "../../helpers/AdminRolesHelper";
import { LoginRoute } from "../routes/LoginRoute"; import { LoginRoute } from "../routes/LoginRoute";
import { MainRoute } from "../routes/MainRoute"; import { MainRoute } from "../routes/MainRoute";
import { AsyncWidget } from "./AsyncWidget"; import { AsyncWidget } from "./AsyncWidget";
@ -31,6 +32,9 @@ export class InitWidget extends React.Component<{}, InitWidgetState> {
if (AccountHelper.hasAccessToken) { if (AccountHelper.hasAccessToken) {
await AccountHelper.refreshCurrentAccountInfo(); await AccountHelper.refreshCurrentAccountInfo();
await AdminRolesHelper.LoadRolesList();
this.setState({ signedIn: true }); this.setState({ signedIn: true });
} }
} }