Add caps checking on Home tiles.
This commit is contained in:
parent
b079d485db
commit
6fc11dfbe4
|
@ -4,11 +4,11 @@ import { removeDoubleSlash } from "../../utils";
|
||||||
export type CapabilitiesType = {
|
export type CapabilitiesType = {
|
||||||
[path: string]: string[];
|
[path: string]: string[];
|
||||||
capabilities?: string[];
|
capabilities?: string[];
|
||||||
}
|
};
|
||||||
|
|
||||||
export async function getCapabilitiesPath(path: string | string[]): Promise<CapabilitiesType> {
|
export async function getCapabilitiesPath(path: string | string[]): Promise<CapabilitiesType> {
|
||||||
if (!Array.isArray(path)) {
|
if (!Array.isArray(path)) {
|
||||||
path = [removeDoubleSlash(path)]
|
path = [removeDoubleSlash(path)];
|
||||||
} else {
|
} else {
|
||||||
path = path.map((s) => removeDoubleSlash(s));
|
path = path.map((s) => removeDoubleSlash(s));
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { Component, JSX } from "preact";
|
import { Component, JSX } from "preact";
|
||||||
|
|
||||||
export type TileParams = {
|
export type TileParams = {
|
||||||
condition?: boolean;
|
disabled?: boolean;
|
||||||
color?: string;
|
color?: string;
|
||||||
title: string;
|
title: string;
|
||||||
description: string;
|
description: string;
|
||||||
|
@ -12,25 +12,33 @@ export type TileParams = {
|
||||||
|
|
||||||
export class Tile extends Component<TileParams, unknown> {
|
export class Tile extends Component<TileParams, unknown> {
|
||||||
render(): JSX.Element {
|
render(): JSX.Element {
|
||||||
if (this.props.condition == false) return <></>;
|
const defaultColor = this.props.disabled == true ? "secondary" : "primary";
|
||||||
|
|
||||||
return (
|
const tileInner = (
|
||||||
<a class="uk-link-heading" onClick={this.props.onclick}>
|
<div class={"uk-padding-small uk-background-" + (this.props.color || defaultColor)}>
|
||||||
<div class={"uk-padding-small uk-background-" + (this.props.color || "primary")}>
|
<p class="uk-h4">
|
||||||
<p class="uk-h4">
|
{this.props.title}
|
||||||
{this.props.title}
|
{typeof this.props.icon == "string" && (
|
||||||
{typeof this.props.icon == "string" && (
|
<span
|
||||||
<span
|
class="uk-icon uk-margin-small-left"
|
||||||
class="uk-icon uk-margin-small-left"
|
uk-icon={`icon: ${this.props.icon}`}
|
||||||
uk-icon={`icon: ${this.props.icon}`}
|
role="img"
|
||||||
role="img"
|
aria-label={this.props.iconText}
|
||||||
aria-label={this.props.iconText}
|
></span>
|
||||||
></span>
|
)}
|
||||||
)}
|
</p>
|
||||||
</p>
|
<span class="uk-text-muted">{this.props.description}</span>
|
||||||
<span class="uk-text-muted">{this.props.description}</span>
|
</div>
|
||||||
</div>
|
|
||||||
</a>
|
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (this.props.disabled == true) {
|
||||||
|
return <p>{tileInner}</p>;
|
||||||
|
} else {
|
||||||
|
return (
|
||||||
|
<a class="uk-link-heading" onClick={this.props.onclick}>
|
||||||
|
{tileInner}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { Margin } from "../elements/Margin";
|
||||||
import { Page } from "../types/Page";
|
import { Page } from "../types/Page";
|
||||||
import { Tile } from "../elements/Tile";
|
import { Tile } from "../elements/Tile";
|
||||||
import { TokenInfo } from "../api/types/token";
|
import { TokenInfo } from "../api/types/token";
|
||||||
|
import { getCapabilitiesPath } from "../api/sys/getCapabilities";
|
||||||
import { lookupSelf } from "../api/sys/lookupSelf";
|
import { lookupSelf } from "../api/sys/lookupSelf";
|
||||||
import { prePageChecks, setErrorText } from "../pageUtils";
|
import { prePageChecks, setErrorText } from "../pageUtils";
|
||||||
import { render } from "preact";
|
import { render } from "preact";
|
||||||
|
@ -33,6 +34,10 @@ export class HomePage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const caps = await getCapabilitiesPath(["sys/auth", "sys/policies"]);
|
||||||
|
const authCaps = caps["sys/auth"];
|
||||||
|
const policiesCaps = caps["sys/auth"];
|
||||||
|
|
||||||
render(
|
render(
|
||||||
<div>
|
<div>
|
||||||
<ul id="textList" class="uk-nav">
|
<ul id="textList" class="uk-nav">
|
||||||
|
@ -70,6 +75,7 @@ export class HomePage extends Page {
|
||||||
title={i18next.t("home_access_title")}
|
title={i18next.t("home_access_title")}
|
||||||
description={i18next.t("home_access_description")}
|
description={i18next.t("home_access_description")}
|
||||||
icon="users"
|
icon="users"
|
||||||
|
disabled={!authCaps.includes("read")}
|
||||||
onclick={async () => {
|
onclick={async () => {
|
||||||
await this.router.changePage("ACCESS_HOME");
|
await this.router.changePage("ACCESS_HOME");
|
||||||
}}
|
}}
|
||||||
|
@ -78,6 +84,7 @@ export class HomePage extends Page {
|
||||||
title={i18next.t("home_policies_title")}
|
title={i18next.t("home_policies_title")}
|
||||||
description={i18next.t("home_policies_description")}
|
description={i18next.t("home_policies_description")}
|
||||||
icon="pencil"
|
icon="pencil"
|
||||||
|
disabled={!policiesCaps.includes("read")}
|
||||||
onclick={async () => {
|
onclick={async () => {
|
||||||
await this.router.changePage("POLICIES_HOME");
|
await this.router.changePage("POLICIES_HOME");
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -55,11 +55,9 @@ export class KeyValueSecretPage extends Page {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async render(): Promise<void> {
|
async render(): Promise<void> {
|
||||||
const caps = (await getCapabilities(
|
const caps = (
|
||||||
this.state.baseMount,
|
await getCapabilities(this.state.baseMount, this.state.secretPath, this.state.secretItem)
|
||||||
this.state.secretPath,
|
).capabilities;
|
||||||
this.state.secretItem,
|
|
||||||
)).capabilities;
|
|
||||||
|
|
||||||
const secretInfo = await getSecret(
|
const secretInfo = await getSecret(
|
||||||
this.state.baseMount,
|
this.state.baseMount,
|
||||||
|
|
Loading…
Reference in a new issue