web: Fix issue where default user path is not preferred.

This commit is contained in:
Teffen Ellis
2026-05-08 01:47:50 +02:00
parent b4c7dea4e8
commit 92700a2fa6
3 changed files with 40 additions and 37 deletions

View File

@@ -7,6 +7,7 @@ import "#components/ak-radio-input";
import "#components/ak-switch-input";
import { DEFAULT_CONFIG } from "#common/api/config";
import { DefaultUIConfig } from "#common/ui/config";
import { ModelForm } from "#elements/forms/ModelForm";
import { RadioOption } from "#elements/forms/Radio";
@@ -58,8 +59,8 @@ export class UserForm extends ModelForm<User, number> {
@property({ attribute: false })
public targetRole: Role | null = null;
@property({ type: String, attribute: "default-path" })
public defaultPath: string = "users";
@property({ type: String, attribute: "default-path", useDefault: true })
public defaultPath: string = DefaultUIConfig.defaults.userPath;
@property({ attribute: false })
public userType: UserTypeEnum | null = null;

View File

@@ -91,15 +91,15 @@ export class UserListPage extends WithLicenseSummary(
public override searchPlaceholder = msg("Search by username, email, etc...");
public override searchLabel = msg("User Search");
public pageTitle = msg("Users");
public pageDescription = "";
public pageIcon = "pf-icon pf-icon-user";
public override pageTitle = msg("Users");
public override pageDescription = "";
public override pageIcon = "pf-icon pf-icon-user";
@property({ type: String })
public order = "-last_login";
@property({ type: String })
public activePath: string;
@property({ type: String, useDefault: true })
public activePath: string = DefaultUIConfig.defaults.userPath;
@state()
protected hideDeactivated = getURLParam<boolean>("hideDeactivated", false);
@@ -107,27 +107,23 @@ export class UserListPage extends WithLicenseSummary(
@state()
protected userPaths: UserPath | null = null;
constructor() {
super();
const defaultPath = DefaultUIConfig.defaults.userPath;
this.activePath = getURLParam<string>("path", defaultPath);
if (this.uiConfig.defaults.userPath !== defaultPath) {
this.activePath = this.uiConfig.defaults.userPath;
}
}
protected canImpersonate = false;
public override connectedCallback(): void {
super.connectedCallback();
this.canImpersonate = this.can(CapabilitiesEnum.CanImpersonate);
const initialDefaultUserPath = DefaultUIConfig.defaults.userPath;
const brandDefaultUserPath = this.uiConfig.defaults.userPath;
this.activePath = getURLParam<string>(
"path",
brandDefaultUserPath || initialDefaultUserPath,
);
}
async apiEndpoint(): Promise<PaginatedResponse<User>> {
protected override async apiEndpoint(): Promise<PaginatedResponse<User>> {
const users = await this.#api.coreUsersList({
...(await this.defaultEndpointConfig()),
pathStartswith: this.activePath,
@@ -142,6 +138,18 @@ export class UserListPage extends WithLicenseSummary(
return users;
}
protected buildExportParams = async (): Promise<CoreUsersExportCreateRequest> => {
return {
...(await this.defaultEndpointConfig()),
pathStartswith: this.activePath,
isActive: this.hideDeactivated ? true : undefined,
};
};
protected createExport = (params: CoreUsersExportCreateRequest) => {
return this.#api.coreUsersExportCreate(params);
};
protected override rowLabel(item: User): string {
if (item.name) {
return msg(str`${item.username} (${item.name})`);
@@ -159,6 +167,8 @@ export class UserListPage extends WithLicenseSummary(
[msg("Actions"), null, msg("Row Actions")],
];
//#region Renderering
protected override renderToolbarSelected(): TemplateResult {
const disabled = this.selectedElements.length < 1;
const { currentUser, originalUser } = this;
@@ -249,7 +259,7 @@ export class UserListPage extends WithLicenseSummary(
</div>`;
}
protected row(item: User) {
protected override row(item: User): SlottedTemplateResult[] {
const { currentUser } = this;
const showImpersonation = this.canImpersonate && currentUser && item.pk !== currentUser.pk;
@@ -294,7 +304,7 @@ export class UserListPage extends WithLicenseSummary(
];
}
renderExpanded(item: User): TemplateResult {
protected override renderExpanded(item: User): SlottedTemplateResult {
return html`<dl class="pf-c-description-list pf-m-horizontal">
<div class="pf-c-description-list__group">
<dt class="pf-c-description-list__term">
@@ -335,18 +345,6 @@ export class UserListPage extends WithLicenseSummary(
</dl>`;
}
protected buildExportParams = async () => {
return {
...(await this.defaultEndpointConfig()),
pathStartswith: this.activePath,
isActive: this.hideDeactivated ? true : undefined,
};
};
protected createExport = (params: CoreUsersExportCreateRequest) => {
return this.#api.coreUsersExportCreate(params);
};
protected renderObjectCreate(): SlottedTemplateResult {
const { activePath } = this;
@@ -370,7 +368,7 @@ export class UserListPage extends WithLicenseSummary(
});
}
protected renderSidebarBefore(): TemplateResult {
protected renderSidebarBefore(): SlottedTemplateResult {
return html`<aside aria-labelledby="sidebar-left-panel-header" class="pf-c-sidebar__panel">
<div class="pf-c-card tree">
<div
@@ -394,6 +392,8 @@ export class UserListPage extends WithLicenseSummary(
</div>
</aside>`;
}
//#endregion
}
declare global {

View File

@@ -6,6 +6,8 @@ import "#elements/wizard/FormWizardPage";
import "#elements/wizard/TypeCreateWizardPage";
import "#elements/wizard/Wizard";
import { DefaultUIConfig } from "#common/ui/config";
import { LitPropertyRecord, SlottedTemplateResult } from "#elements/types";
import { CreateWizard } from "#elements/wizard/CreateWizard";
import { TypeCreateWizardPageLayouts } from "#elements/wizard/TypeCreateWizardPage";
@@ -115,8 +117,8 @@ export class AKUserWizard extends CreateWizard {
/**
* Default path to assign to new users created via the wizard.
*/
@property({ type: String, attribute: "default-path" })
public defaultPath: string = "users";
@property({ type: String, attribute: "default-path", useDefault: true })
public defaultPath: string = DefaultUIConfig.defaults.userPath;
protected apiEndpoint(): Promise<TypeCreate[]> {
return Promise.resolve(DEFAULT_USER_TYPES);