web: migrate user token list to web
This commit is contained in:
parent
854d94056e
commit
264c678eaa
|
@ -24,9 +24,7 @@
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
<section slot="page-2" data-tab-title="{% trans 'Tokens' %}" class="pf-c-page__main-section pf-m-no-padding-mobile">
|
<section slot="page-2" data-tab-title="{% trans 'Tokens' %}" class="pf-c-page__main-section pf-m-no-padding-mobile">
|
||||||
<ak-site-shell url="{% url 'authentik_core:user-tokens' %}">
|
<ak-token-user-list></ak-token-user-list>
|
||||||
<div slot="body"></div>
|
|
||||||
</ak-site-shell>
|
|
||||||
</section>
|
</section>
|
||||||
{% user_stages as user_stages_loc %}
|
{% user_stages as user_stages_loc %}
|
||||||
{% for stage, stage_link in user_stages_loc.items %}
|
{% for stage, stage_link in user_stages_loc.items %}
|
||||||
|
|
|
@ -8,7 +8,6 @@ urlpatterns = [
|
||||||
# User views
|
# User views
|
||||||
path("-/user/", user.UserSettingsView.as_view(), name="user-settings"),
|
path("-/user/", user.UserSettingsView.as_view(), name="user-settings"),
|
||||||
path("-/user/details/", user.UserDetailsView.as_view(), name="user-details"),
|
path("-/user/details/", user.UserDetailsView.as_view(), name="user-details"),
|
||||||
path("-/user/tokens/", user.TokenListView.as_view(), name="user-tokens"),
|
|
||||||
path(
|
path(
|
||||||
"-/user/tokens/create/",
|
"-/user/tokens/create/",
|
||||||
user.TokenCreateView.as_view(),
|
user.TokenCreateView.as_view(),
|
||||||
|
|
|
@ -6,20 +6,15 @@ from django.contrib.auth.mixins import (
|
||||||
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
PermissionRequiredMixin as DjangoPermissionRequiredMixin,
|
||||||
)
|
)
|
||||||
from django.contrib.messages.views import SuccessMessageMixin
|
from django.contrib.messages.views import SuccessMessageMixin
|
||||||
from django.db.models.query import QuerySet
|
|
||||||
from django.http.response import HttpResponse
|
from django.http.response import HttpResponse
|
||||||
from django.urls import reverse_lazy
|
from django.urls import reverse_lazy
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _
|
||||||
from django.views.generic import ListView, UpdateView
|
from django.views.generic import UpdateView
|
||||||
from django.views.generic.base import TemplateView
|
from django.views.generic.base import TemplateView
|
||||||
from guardian.mixins import PermissionListMixin, PermissionRequiredMixin
|
from guardian.mixins import PermissionRequiredMixin
|
||||||
from guardian.shortcuts import get_objects_for_user
|
from guardian.shortcuts import get_objects_for_user
|
||||||
|
|
||||||
from authentik.admin.views.utils import (
|
from authentik.admin.views.utils import DeleteMessageView
|
||||||
DeleteMessageView,
|
|
||||||
SearchListMixin,
|
|
||||||
UserPaginateListMixin,
|
|
||||||
)
|
|
||||||
from authentik.core.forms.token import UserTokenForm
|
from authentik.core.forms.token import UserTokenForm
|
||||||
from authentik.core.forms.users import UserDetailForm
|
from authentik.core.forms.users import UserDetailForm
|
||||||
from authentik.core.models import Token, TokenIntents
|
from authentik.core.models import Token, TokenIntents
|
||||||
|
@ -54,30 +49,6 @@ class UserDetailsView(SuccessMessageMixin, LoginRequiredMixin, UpdateView):
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
|
||||||
class TokenListView(
|
|
||||||
LoginRequiredMixin,
|
|
||||||
PermissionListMixin,
|
|
||||||
UserPaginateListMixin,
|
|
||||||
SearchListMixin,
|
|
||||||
ListView,
|
|
||||||
):
|
|
||||||
"""Show list of all tokens"""
|
|
||||||
|
|
||||||
model = Token
|
|
||||||
ordering = "expires"
|
|
||||||
permission_required = "authentik_core.view_token"
|
|
||||||
|
|
||||||
template_name = "user/token_list.html"
|
|
||||||
search_fields = [
|
|
||||||
"identifier",
|
|
||||||
"intent",
|
|
||||||
"description",
|
|
||||||
]
|
|
||||||
|
|
||||||
def get_queryset(self) -> QuerySet:
|
|
||||||
return super().get_queryset().filter(intent=TokenIntents.INTENT_API)
|
|
||||||
|
|
||||||
|
|
||||||
class TokenCreateView(
|
class TokenCreateView(
|
||||||
SuccessMessageMixin,
|
SuccessMessageMixin,
|
||||||
LoginRequiredMixin,
|
LoginRequiredMixin,
|
||||||
|
|
|
@ -34,6 +34,10 @@ export class Token {
|
||||||
return `/administration/tokens/${rest}`;
|
return `/administration/tokens/${rest}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static userUrl(rest: string): string {
|
||||||
|
return `/-/user/tokens/${rest}`;
|
||||||
|
}
|
||||||
|
|
||||||
static getKey(identifier: string): Promise<string> {
|
static getKey(identifier: string): Promise<string> {
|
||||||
return DefaultClient.fetch<{ key: string }>(["core", "tokens", identifier, "view_key"]).then(
|
return DefaultClient.fetch<{ key: string }>(["core", "tokens", identifier, "view_key"]).then(
|
||||||
(r) => r.key
|
(r) => r.key
|
||||||
|
|
|
@ -29,6 +29,7 @@ import "./pages/admin-overview/AdminOverviewPage";
|
||||||
import "./pages/admin-overview/TopApplicationsTable";
|
import "./pages/admin-overview/TopApplicationsTable";
|
||||||
import "./pages/applications/ApplicationListPage";
|
import "./pages/applications/ApplicationListPage";
|
||||||
import "./pages/applications/ApplicationViewPage";
|
import "./pages/applications/ApplicationViewPage";
|
||||||
|
import "./pages/tokens/UserTokenList";
|
||||||
import "./pages/LibraryPage";
|
import "./pages/LibraryPage";
|
||||||
|
|
||||||
import "./elements/stages/authenticator_webauthn/WebAuthnRegister";
|
import "./elements/stages/authenticator_webauthn/WebAuthnRegister";
|
||||||
|
|
|
@ -52,7 +52,7 @@ export class TokenListPage extends TablePage<Token> {
|
||||||
html`${item.expiring ? "Yes" : "No"}`,
|
html`${item.expiring ? "Yes" : "No"}`,
|
||||||
html`${item.expiring ? new Date(item.expires * 1000).toLocaleString() : "-"}`,
|
html`${item.expiring ? new Date(item.expires * 1000).toLocaleString() : "-"}`,
|
||||||
html`
|
html`
|
||||||
<ak-modal-button href="${Token.adminUrl(`${item.pk}/delete/`)}">
|
<ak-modal-button href="${Token.adminUrl(`${item.identifier}/delete/`)}">
|
||||||
<ak-spinner-button slot="trigger" class="pf-m-danger">
|
<ak-spinner-button slot="trigger" class="pf-m-danger">
|
||||||
${gettext("Delete")}
|
${gettext("Delete")}
|
||||||
</ak-spinner-button>
|
</ak-spinner-button>
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
import { gettext } from "django";
|
||||||
|
import { customElement, html, property, TemplateResult } from "lit-element";
|
||||||
|
import { AKResponse } from "../../api/Client";
|
||||||
|
import { TablePage } from "../../elements/table/TablePage";
|
||||||
|
|
||||||
|
import "../../elements/buttons/ModalButton";
|
||||||
|
import "../../elements/buttons/Dropdown";
|
||||||
|
import "../../elements/buttons/TokenCopyButton";
|
||||||
|
import { Table, TableColumn } from "../../elements/table/Table";
|
||||||
|
import { Token } from "../../api/Tokens";
|
||||||
|
|
||||||
|
@customElement("ak-token-user-list")
|
||||||
|
export class UserTokenList extends Table<Token> {
|
||||||
|
searchEnabled(): boolean {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@property()
|
||||||
|
order = "expires";
|
||||||
|
|
||||||
|
apiEndpoint(page: number): Promise<AKResponse<Token>> {
|
||||||
|
return Token.list({
|
||||||
|
ordering: this.order,
|
||||||
|
page: page,
|
||||||
|
search: this.search || "",
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
columns(): TableColumn[] {
|
||||||
|
return [
|
||||||
|
new TableColumn("Identifier", "identifier"),
|
||||||
|
new TableColumn("User", "user"),
|
||||||
|
new TableColumn("Expires?", "expiring"),
|
||||||
|
new TableColumn("Expiry date", "expires"),
|
||||||
|
new TableColumn(""),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
row(item: Token): TemplateResult[] {
|
||||||
|
return [
|
||||||
|
html`${item.identifier}`,
|
||||||
|
html`${item.user.username}`,
|
||||||
|
html`${item.expiring ? "Yes" : "No"}`,
|
||||||
|
html`${item.expiring ? new Date(item.expires * 1000).toLocaleString() : "-"}`,
|
||||||
|
html`
|
||||||
|
<ak-modal-button href="${Token.userUrl(`${item.identifier}/update/`)}">
|
||||||
|
<ak-spinner-button slot="trigger" class="pf-m-secondary">
|
||||||
|
${gettext("Edit")}
|
||||||
|
</ak-spinner-button>
|
||||||
|
<div slot="modal"></div>
|
||||||
|
</ak-modal-button>
|
||||||
|
<ak-modal-button href="${Token.userUrl(`${item.identifier}/delete/`)}">
|
||||||
|
<ak-spinner-button slot="trigger" class="pf-m-danger">
|
||||||
|
${gettext("Delete")}
|
||||||
|
</ak-spinner-button>
|
||||||
|
<div slot="modal"></div>
|
||||||
|
</ak-modal-button>
|
||||||
|
<ak-token-copy-button identifier="${item.identifier}">
|
||||||
|
${gettext("Copy Key")}
|
||||||
|
</ak-token-copy-button>
|
||||||
|
`,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Reference in New Issue