web/admin: add basic session management UI
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
		
							
								
								
									
										60
									
								
								web/src/elements/user/SessionList.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										60
									
								
								web/src/elements/user/SessionList.ts
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,60 @@
 | 
			
		||||
import { t } from "@lingui/macro";
 | 
			
		||||
import { customElement, html, property, TemplateResult } from "lit-element";
 | 
			
		||||
import { AKResponse } from "../../api/Client";
 | 
			
		||||
import { Table, TableColumn } from "../table/Table";
 | 
			
		||||
 | 
			
		||||
import "../forms/DeleteForm";
 | 
			
		||||
import { PAGE_SIZE } from "../../constants";
 | 
			
		||||
import { CoreApi, AuthenticatedSession } from "authentik-api";
 | 
			
		||||
import { DEFAULT_CONFIG } from "../../api/Config";
 | 
			
		||||
 | 
			
		||||
@customElement("ak-user-session-list")
 | 
			
		||||
export class AuthenticatedSessionList extends Table<AuthenticatedSession> {
 | 
			
		||||
 | 
			
		||||
    @property()
 | 
			
		||||
    targetUser!: string;
 | 
			
		||||
 | 
			
		||||
    apiEndpoint(page: number): Promise<AKResponse<AuthenticatedSession>> {
 | 
			
		||||
        return new CoreApi(DEFAULT_CONFIG).coreAuthenticatedSessionsList({
 | 
			
		||||
            userUsername: this.targetUser,
 | 
			
		||||
            ordering: this.order,
 | 
			
		||||
            page: page,
 | 
			
		||||
            pageSize: PAGE_SIZE,
 | 
			
		||||
        });
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    order = "-expires";
 | 
			
		||||
 | 
			
		||||
    columns(): TableColumn[] {
 | 
			
		||||
        return [
 | 
			
		||||
            new TableColumn(t`Last IP`, "last_ip"),
 | 
			
		||||
            new TableColumn(t`Browser`, "user_agent"),
 | 
			
		||||
            new TableColumn(t`Device`, "user_agent"),
 | 
			
		||||
            new TableColumn(t`Expires`, "expires"),
 | 
			
		||||
            new TableColumn(""),
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    row(item: AuthenticatedSession): TemplateResult[] {
 | 
			
		||||
        return [
 | 
			
		||||
            html`${item.lastIp}`,
 | 
			
		||||
            html`${item.userAgent.userAgent?.family}`,
 | 
			
		||||
            html`${item.userAgent.os?.family}`,
 | 
			
		||||
            html`${item.expires?.toLocaleString()}`,
 | 
			
		||||
            html`
 | 
			
		||||
            <ak-forms-delete
 | 
			
		||||
                .obj=${item}
 | 
			
		||||
                objectLabel=${t`Session`}
 | 
			
		||||
                .delete=${() => {
 | 
			
		||||
                    return new CoreApi(DEFAULT_CONFIG).coreAuthenticatedSessionsDestroy({
 | 
			
		||||
                        uuid: item.uuid || "",
 | 
			
		||||
                    });
 | 
			
		||||
                }}>
 | 
			
		||||
                <button slot="trigger" class="pf-c-button pf-m-danger">
 | 
			
		||||
                    ${t`Delete Session`}
 | 
			
		||||
                </button>
 | 
			
		||||
            </ak-forms-delete>`,
 | 
			
		||||
        ];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -16,7 +16,7 @@ export class UserConsentList extends Table<UserConsent> {
 | 
			
		||||
    apiEndpoint(page: number): Promise<AKResponse<UserConsent>> {
 | 
			
		||||
        return new CoreApi(DEFAULT_CONFIG).coreUserConsentList({
 | 
			
		||||
            user: this.userId,
 | 
			
		||||
            ordering: "expires",
 | 
			
		||||
            ordering: this.order,
 | 
			
		||||
            page: page,
 | 
			
		||||
            pageSize: PAGE_SIZE,
 | 
			
		||||
        });
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user