enterprise: add up-to-date license status (#11042)

Signed-off-by: Jens Langhammer <jens@goauthentik.io>
This commit is contained in:
Jens L.
2024-08-23 14:05:19 +02:00
committed by GitHub
parent b301048a27
commit 41fbb6dbd7
4 changed files with 127 additions and 9 deletions

View File

@ -30,7 +30,7 @@ export class EnterpriseLicenseForm extends ModelForm<License, string> {
async load(): Promise<void> {
this.installID = (
await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseGetInstallIdRetrieve()
await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseInstallIdRetrieve()
).installId;
}

View File

@ -14,7 +14,7 @@ import { TablePage } from "@goauthentik/elements/table/TablePage";
import "@patternfly/elements/pf-tooltip/pf-tooltip.js";
import { msg, str } from "@lit/localize";
import { CSSResult, TemplateResult, css, html } from "lit";
import { CSSResult, TemplateResult, css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators.js";
import PFBanner from "@patternfly/patternfly/components/Banner/banner.css";
@ -22,7 +22,9 @@ import PFButton from "@patternfly/patternfly/components/Button/button.css";
import PFCard from "@patternfly/patternfly/components/Card/card.css";
import PFDescriptionList from "@patternfly/patternfly/components/DescriptionList/description-list.css";
import PFFormControl from "@patternfly/patternfly/components/FormControl/form-control.css";
import PFProgress from "@patternfly/patternfly/components/Progress/progress.css";
import PFGrid from "@patternfly/patternfly/layouts/Grid/grid.css";
import PFSplit from "@patternfly/patternfly/layouts/Split/split.css";
import {
EnterpriseApi,
@ -70,6 +72,8 @@ export class EnterpriseLicenseListPage extends TablePage<License> {
PFBanner,
PFFormControl,
PFButton,
PFProgress,
PFSplit,
PFCard,
css`
.pf-m-no-padding-bottom {
@ -84,9 +88,11 @@ export class EnterpriseLicenseListPage extends TablePage<License> {
async apiEndpoint(): Promise<PaginatedResponse<License>> {
this.forecast = await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseForecastRetrieve();
this.summary = await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseSummaryRetrieve();
this.summary = await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseSummaryRetrieve({
cached: false,
});
this.installID = (
await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseGetInstallIdRetrieve()
await new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseInstallIdRetrieve()
).installId;
return new EnterpriseApi(DEFAULT_CONFIG).enterpriseLicenseList(
await this.defaultEndpointConfig(),
@ -191,9 +197,104 @@ export class EnterpriseLicenseListPage extends TablePage<License> {
</ak-aggregate-card>
</div>
</section>
<section class="pf-c-page__main-section pf-m-no-padding-bottom">
${this.renderCurrentSummary()}
</section>
`;
}
renderSummaryBadge() {
switch (this.summary?.status) {
case LicenseSummaryStatusEnum.Expired:
return html`<ak-label color=${PFColor.Red}>${msg("Expired")}</ak-label>`;
case LicenseSummaryStatusEnum.ExpirySoon:
return html`<ak-label color=${PFColor.Orange}>${msg("Expiring soon")}</ak-label>`;
case LicenseSummaryStatusEnum.Unlicensed:
return html`<ak-label color=${PFColor.Grey}>${msg("Unlicensed")}</ak-label>`;
case LicenseSummaryStatusEnum.ReadOnly:
return html`<ak-label color=${PFColor.Red}>${msg("Read Only")}</ak-label>`;
case LicenseSummaryStatusEnum.Valid:
return html`<ak-label color=${PFColor.Green}>${msg("Valid")}</ak-label>`;
default:
return nothing;
}
}
renderCurrentSummary() {
if (!this.forecast || !this.summary) {
return html`${msg("Loading")}`;
}
const internalUserPercentage =
this.summary.internalUsers > 0
? Math.ceil(this.forecast.internalUsers / (this.summary.internalUsers / 100))
: 0;
const externalUserPercentage =
this.summary.externalUsers > 0
? Math.ceil(this.forecast.externalUsers / (this.summary.externalUsers / 100))
: 0;
return html`<div class="pf-c-card">
<div class="pf-c-card__title">${msg("Current license status")}</div>
<div class="pf-c-card__body pf-l-split pf-m-gutter">
<dl class="pf-l-split__item pf-c-description-list pf-m-horizontal">
<div class="pf-c-description-list__group">
<dt class="pf-c-description-list__term">
<span class="pf-c-description-list__text"
>${msg("Overall license status")}</span
>
</dt>
<dd class="pf-c-description-list__description">
<div class="pf-c-description-list__text">
${this.renderSummaryBadge()}
</div>
</dd>
</div>
</dl>
<div class="pf-l-split__item pf-m-fill">
<div class="pf-c-progress">
<div class="pf-c-progress__description">${msg("Internal user usage")}</div>
<div class="pf-c-progress__status" aria-hidden="true">
<span class="pf-c-progress__measure"
>${msg(str`${internalUserPercentage}%`)}</span
>
</div>
<div
class="pf-c-progress__bar"
role="progressbar"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="${internalUserPercentage}"
>
<div
class="pf-c-progress__indicator"
style="width:${internalUserPercentage}%;"
></div>
</div>
</div>
<div class="pf-c-progress">
<div class="pf-c-progress__description">${msg("External user usage")}</div>
<div class="pf-c-progress__status" aria-hidden="true">
<span class="pf-c-progress__measure"
>${msg(str`${externalUserPercentage}%`)}</span
>
</div>
<div
class="pf-c-progress__bar"
role="progressbar"
aria-valuemin="0"
aria-valuemax="100"
aria-valuenow="${externalUserPercentage}"
>
<div
class="pf-c-progress__indicator"
style="width:${externalUserPercentage}%;"
></div>
</div>
</div>
</div>
</div>
</div>`;
}
row(item: License): TemplateResult[] {
let color = PFColor.Green;
if (item.expiry) {