
This commit adds HTMLTagNameElementMap entries to every web component in the front end. Activating and associating the HTMLTagNamElementMap with its class has enabled [LitAnalyzer](https://github.com/runem/lit-analyzer/tree/master/packages/lit-analyzer) to reveal a *lot* of basic problems within the UI, the most popular of which is "missing import." We usually get away with it because the object being imported was already registered with the browser elsewhere, but it still surprises me that we haven't gotten any complaints over things like: ``` ./src/flow/stages/base.ts Missing import for <ak-form-static> 96: <ak-form-static no-missing-import ``` Given how early and fundamental that seems to be in our code, I'd have expected to hear _something_ about it. I have not enabled most of the possible checks because, well, there are just a ton of warnings when I do. I'd like to get in and fix those. Aside from this, I have also _removed_ `customElement` declarations from anything declared as an `abstract class`. It makes no sense to try and instantiate something that cannot, by definition, be instantiated. If the class is capable of running on its own, it's not abstract, it just needs to be overridden in child classes. Before removing the declaration I did check to make sure no other piece of code was even *trying* to instantiate it, and so far I have detected no failures. Those elements were: - elements/forms/Form.ts - element-/wizard/WizardFormPage.ts The one that blows my mind, though, is this: ``` src/elements/forms/ProxyForm.ts 6-@customElement("ak-proxy-form") 7:export abstract class ProxyForm extends Form<unknown> { ``` Which, despite being `abstract`, is somehow instantiable? ``` src/admin/outposts/ServiceConnectionListPage.ts: <ak-proxy-form src/admin/providers/ProviderListPage.ts: <ak-proxy-form src/admin/sources/SourceWizard.ts: <ak-proxy-form src/admin/sources/SourceListPage.ts: <ak-proxy-form src/admin/providers/ProviderWizard.ts: <ak-proxy-form type=${type.component}></ak-proxy-form> src/admin/stages/StageListPage.ts: <ak-proxy-form ``` I've made a note to investigate. I've started a new folder where all of my one-off tools for *how* a certain PR was run. It has a README describing what it's for, and the first tool, `add-htmlelementtagnamemaps-to-everything`, is its first entry. That tool is also documented internally. ``` Gilbert & Sullivan I've got a little list, I've got a little list, Of all the code that would never be missed, The duplicate code of cute-and-paste, The weak abstractions that lead to waste, The embedded templates-- you get the gist, There ain't none of 'em that will ever be missed, And that's why I've got them on my list! ```
114 lines
3.9 KiB
TypeScript
114 lines
3.9 KiB
TypeScript
import { DEFAULT_CONFIG } from "@goauthentik/common/api/config";
|
|
import { uiConfig } from "@goauthentik/common/ui/config";
|
|
import { getRelativeTime } from "@goauthentik/common/utils";
|
|
import "@goauthentik/elements/buttons/ModalButton";
|
|
import "@goauthentik/elements/buttons/SpinnerButton";
|
|
import "@goauthentik/elements/forms/DeleteBulkForm";
|
|
import "@goauthentik/elements/forms/ModalForm";
|
|
import "@goauthentik/elements/rbac/ObjectPermissionModal";
|
|
import { PaginatedResponse } from "@goauthentik/elements/table/Table";
|
|
import { TableColumn } from "@goauthentik/elements/table/Table";
|
|
import { TablePage } from "@goauthentik/elements/table/TablePage";
|
|
import getUnicodeFlagIcon from "country-flag-icons/unicode";
|
|
|
|
import { msg } from "@lit/localize";
|
|
import { TemplateResult, html } from "lit";
|
|
import { customElement, property } from "lit/decorators.js";
|
|
|
|
import {
|
|
PoliciesApi,
|
|
RbacPermissionsAssignedByUsersListModelEnum,
|
|
Reputation,
|
|
} from "@goauthentik/api";
|
|
|
|
@customElement("ak-policy-reputation-list")
|
|
export class ReputationListPage extends TablePage<Reputation> {
|
|
searchEnabled(): boolean {
|
|
return true;
|
|
}
|
|
pageTitle(): string {
|
|
return msg("Reputation scores");
|
|
}
|
|
pageDescription(): string {
|
|
return msg(
|
|
"Reputation for IP and user identifiers. Scores are decreased for each failed login and increased for each successful login.",
|
|
);
|
|
}
|
|
pageIcon(): string {
|
|
return "fa fa-ban";
|
|
}
|
|
|
|
@property()
|
|
order = "identifier";
|
|
|
|
checkbox = true;
|
|
clearOnRefresh = true;
|
|
|
|
async apiEndpoint(page: number): Promise<PaginatedResponse<Reputation>> {
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationScoresList({
|
|
ordering: this.order,
|
|
page: page,
|
|
pageSize: (await uiConfig()).pagination.perPage,
|
|
search: this.search || "",
|
|
});
|
|
}
|
|
|
|
columns(): TableColumn[] {
|
|
return [
|
|
new TableColumn(msg("Identifier"), "identifier"),
|
|
new TableColumn(msg("IP"), "ip"),
|
|
new TableColumn(msg("Score"), "score"),
|
|
new TableColumn(msg("Updated"), "updated"),
|
|
new TableColumn(msg("Actions")),
|
|
];
|
|
}
|
|
|
|
renderToolbarSelected(): TemplateResult {
|
|
const disabled = this.selectedElements.length < 1;
|
|
return html`<ak-forms-delete-bulk
|
|
objectLabel=${msg("Reputation")}
|
|
.objects=${this.selectedElements}
|
|
.usedBy=${(item: Reputation) => {
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationScoresUsedByList({
|
|
reputationUuid: item.pk || "",
|
|
});
|
|
}}
|
|
.delete=${(item: Reputation) => {
|
|
return new PoliciesApi(DEFAULT_CONFIG).policiesReputationScoresDestroy({
|
|
reputationUuid: item.pk || "",
|
|
});
|
|
}}
|
|
>
|
|
<button ?disabled=${disabled} slot="trigger" class="pf-c-button pf-m-danger">
|
|
${msg("Delete")}
|
|
</button>
|
|
</ak-forms-delete-bulk>`;
|
|
}
|
|
|
|
row(item: Reputation): TemplateResult[] {
|
|
return [
|
|
html`${item.identifier}`,
|
|
html`${item.ipGeoData?.country
|
|
? html` ${getUnicodeFlagIcon(item.ipGeoData.country)} `
|
|
: html``}
|
|
${item.ip}`,
|
|
html`${item.score}`,
|
|
html`<div>${getRelativeTime(item.updated)}</div>
|
|
<small>${item.updated.toLocaleString()}</small>`,
|
|
html`
|
|
<ak-rbac-object-permission-modal
|
|
model=${RbacPermissionsAssignedByUsersListModelEnum.PoliciesReputationReputationpolicy}
|
|
objectPk=${item.pk || ""}
|
|
>
|
|
</ak-rbac-object-permission-modal>
|
|
`,
|
|
];
|
|
}
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
"ak-policy-reputation-list": ReputationListPage;
|
|
}
|
|
}
|