Add PolicyDelete page.
This commit is contained in:
parent
681f617988
commit
53e5765956
|
@ -22,6 +22,7 @@ import { NewTransitEnginePage } from "./pages/Secrets/NewEngines/NewTransitEngin
|
|||
import { NewTransitKeyPage } from "./pages/Secrets/Transit/NewTransitKey";
|
||||
import { Page } from "./types/Page";
|
||||
import { PoliciesHomePage } from "./pages/Policies/PoliciesHome";
|
||||
import { PolicyDeletePage } from "./pages/Policies/PolicyDelete";
|
||||
import { PolicyViewPage } from "./pages/Policies/PolicyView";
|
||||
import { PwGenPage } from "./pages/PwGen";
|
||||
import { SecretsHomePage } from "./pages/Secrets/SecretsHome";
|
||||
|
@ -58,6 +59,7 @@ export const allPages: pagesList = {
|
|||
|
||||
POLICIES_HOME: new PoliciesHomePage(),
|
||||
POLICY_VIEW: new PolicyViewPage(),
|
||||
POLICY_DELETE: new PolicyDeletePage(),
|
||||
|
||||
ACCESS_HOME: new AccessHomePage(),
|
||||
|
||||
|
|
21
src/api/sys/policies/deletePolicy.ts
Normal file
21
src/api/sys/policies/deletePolicy.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { appendAPIURL, getHeaders } from "../../apiUtils";
|
||||
|
||||
type OptionalErrors = { errors?: string[] };
|
||||
|
||||
export async function deletePolicy(name: string): Promise<void> {
|
||||
const request = new Request(appendAPIURL("/v1/sys/policies/acl/" + name), {
|
||||
method: "DELETE",
|
||||
headers: getHeaders(),
|
||||
});
|
||||
const response = await fetch(request);
|
||||
let data: OptionalErrors = {};
|
||||
try {
|
||||
data = (await response.json()) as OptionalErrors;
|
||||
} catch {
|
||||
// Do Nothing
|
||||
}
|
||||
|
||||
if ("errors" in data) {
|
||||
throw new Error(data.errors[0]);
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { appendAPIURL, getHeaders } from "../apiUtils";
|
||||
import { appendAPIURL, getHeaders } from "../../apiUtils";
|
||||
|
||||
export async function getPolicies(): Promise<string[]> {
|
||||
const request = new Request(appendAPIURL("/v1/sys/policies/acl?list=true"), {
|
|
@ -1,4 +1,4 @@
|
|||
import { appendAPIURL, getHeaders } from "../apiUtils";
|
||||
import { appendAPIURL, getHeaders } from "../../apiUtils";
|
||||
|
||||
export async function getPolicy(name: string): Promise<string> {
|
||||
const request = new Request(appendAPIURL("/v1/sys/policies/acl/" + name), {
|
|
@ -1,6 +1,6 @@
|
|||
import { Margin } from "../../elements/Margin";
|
||||
import { Page } from "../../types/Page";
|
||||
import { getPolicies } from "../../api/sys/getPolicies";
|
||||
import { getPolicies } from "../../api/sys/policies/getPolicies";
|
||||
import { notImplemented, prePageChecks } from "../../pageUtils";
|
||||
import { render } from "preact";
|
||||
import i18next from "i18next";
|
||||
|
|
42
src/pages/Policies/PolicyDelete.tsx
Normal file
42
src/pages/Policies/PolicyDelete.tsx
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { Page } from "../../types/Page";
|
||||
import { deletePolicy } from "../../api/sys/policies/deletePolicy";
|
||||
import { render } from "preact";
|
||||
import { setErrorText } from "../../pageUtils";
|
||||
import i18next from "i18next";
|
||||
|
||||
export class PolicyDeletePage extends Page {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
async goBack(): Promise<void> {
|
||||
await this.router.changePage("POLICY_VIEW");
|
||||
}
|
||||
async render(): Promise<void> {
|
||||
render(
|
||||
<div>
|
||||
<h5>{i18next.t("policy_delete_text")}</h5>
|
||||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
try {
|
||||
await deletePolicy(this.state.policyItem);
|
||||
await this.router.changePage("POLICIES_HOME");
|
||||
} catch (e: unknown) {
|
||||
const error = e as Error;
|
||||
setErrorText(error.message);
|
||||
}
|
||||
}}
|
||||
>
|
||||
{i18next.t("policy_delete_btn")}
|
||||
</button>
|
||||
</div>,
|
||||
this.router.pageContentElement,
|
||||
);
|
||||
}
|
||||
|
||||
get name(): string {
|
||||
return i18next.t("policy_delete_title", {
|
||||
policy: this.state.policyItem,
|
||||
});
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import { CodeBlock } from "../../elements/CodeBlock";
|
||||
import { Margin } from "../../elements/Margin";
|
||||
import { Page } from "../../types/Page";
|
||||
import { getPolicy } from "../../api/sys/getPolicy";
|
||||
import { getPolicy } from "../../api/sys/policies/getPolicy";
|
||||
import { notImplemented, prePageChecks } from "../../pageUtils";
|
||||
import { render } from "preact";
|
||||
import i18next from "i18next";
|
||||
|
@ -26,7 +26,12 @@ export class PolicyViewPage extends Page {
|
|||
{i18next.t("policy_view_edit_btn")}
|
||||
</button>
|
||||
{this.state.policyItem !== "default" && (
|
||||
<button class="uk-button uk-button-danger" onClick={notImplemented}>
|
||||
<button
|
||||
class="uk-button uk-button-danger"
|
||||
onClick={async () => {
|
||||
await this.router.changePage("POLICY_DELETE");
|
||||
}}
|
||||
>
|
||||
{i18next.t("policy_view_delete_btn")}
|
||||
</button>
|
||||
)}
|
||||
|
|
6
src/translations/en.js
vendored
6
src/translations/en.js
vendored
|
@ -297,4 +297,10 @@ module.exports = {
|
|||
policy_view_title: "Policy View ({{policy}})",
|
||||
policy_view_edit_btn: "Edit",
|
||||
policy_view_delete_btn: "Delete",
|
||||
|
||||
// Policy Delete
|
||||
policy_delete_title: "Delete Policy ({{policy}})",
|
||||
policy_delete_text:
|
||||
"Are you sure you want to delete this policy? It can't be reversed and there is a chance that all permissions will break.",
|
||||
policy_delete_btn: "Delete Policy",
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue