-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
core: add bulk session revocation #18564
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cdmx-in
wants to merge
11
commits into
goauthentik:main
Choose a base branch
from
cdmx-in:revoke-user-sessions-ui
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+325
−41
Open
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
1e11947
feat: add bulk session revocation functionality for users
cdmx-in 908838e
Merge branch 'goauthentik:main' into revoke-user-sessions-ui
cdmx-in 64da5de
feat: add bulk delete functionality for authenticated sessions
cdmx-in df67f08
Update authentik/core/api/authenticated_sessions.py
cdmx-in e4de5fa
Update authentik/core/api/authenticated_sessions.py
cdmx-in 02b3bf5
Update authentik/core/api/authenticated_sessions.py
cdmx-in 86eb07d
feat: enhance bulk delete functionality for authenticated sessions
cdmx-in aa32ee6
feat: update bulk delete endpoint for authenticated sessions to use D…
cdmx-in 77df404
Merge branch 'goauthentik:main' into revoke-user-sessions-ui
cdmx-in 2882bb5
Update authentik/core/api/authenticated_sessions.py
cdmx-in 7000858
Merge branch 'goauthentik:main' into revoke-user-sessions-ui
cdmx-in File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,207 @@ | ||
| import "#elements/buttons/SpinnerButton/index"; | ||
|
|
||
| import { DEFAULT_CONFIG } from "#common/api/config"; | ||
| import { EVENT_REFRESH } from "#common/constants"; | ||
| import { MessageLevel } from "#common/messages"; | ||
|
|
||
| import { ModalButton } from "#elements/buttons/ModalButton"; | ||
| import { showMessage } from "#elements/messages/MessageContainer"; | ||
| import { PaginatedResponse, Table, TableColumn } from "#elements/table/Table"; | ||
| import { SlottedTemplateResult } from "#elements/types"; | ||
|
|
||
| import { CoreApi, User } from "@goauthentik/api"; | ||
|
|
||
| import { msg, str } from "@lit/localize"; | ||
| import { html, nothing, TemplateResult } from "lit"; | ||
| import { customElement, property, state } from "lit/decorators.js"; | ||
|
|
||
| type UserMetadata = { key: string; value: string }[]; | ||
|
|
||
| @customElement("ak-user-bulk-revoke-sessions-table") | ||
| export class UserBulkRevokeSessionsTable extends Table<User> { | ||
| paginated = false; | ||
|
|
||
| @property({ attribute: false }) | ||
| objects: User[] = []; | ||
|
|
||
| @property({ attribute: false }) | ||
| metadata!: (item: User) => UserMetadata; | ||
|
|
||
| @state() | ||
| sessionCounts: Map<number, number> = new Map(); | ||
|
|
||
| async apiEndpoint(): Promise<PaginatedResponse<User>> { | ||
| // Fetch session counts for each user | ||
| for (const user of this.objects) { | ||
| try { | ||
| const sessions = await new CoreApi(DEFAULT_CONFIG).coreAuthenticatedSessionsList({ | ||
| userUsername: user.username, | ||
| }); | ||
| this.sessionCounts.set(user.pk, sessions.pagination.count); | ||
| } catch { | ||
| this.sessionCounts.set(user.pk, 0); | ||
| } | ||
| } | ||
| this.requestUpdate(); | ||
|
|
||
| return Promise.resolve({ | ||
| pagination: { | ||
| count: this.objects.length, | ||
| current: 1, | ||
| totalPages: 1, | ||
| startIndex: 1, | ||
| endIndex: this.objects.length, | ||
| next: 0, | ||
| previous: 0, | ||
| }, | ||
| results: this.objects, | ||
| }); | ||
| } | ||
|
|
||
| protected override rowLabel(item: User): string | null { | ||
| return item.username || null; | ||
| } | ||
|
|
||
| protected get columns(): TableColumn[] { | ||
| return [[msg("Username")], [msg("Name")], [msg("Active Sessions")]]; | ||
| } | ||
|
|
||
| row(item: User): SlottedTemplateResult[] { | ||
| const sessionCount = this.sessionCounts.get(item.pk); | ||
| return [ | ||
| html`${item.username}`, | ||
| html`${item.name || msg("No name set")}`, | ||
| html`${sessionCount !== undefined ? sessionCount : html`<ak-spinner size="sm"></ak-spinner>`}`, | ||
| ]; | ||
| } | ||
|
|
||
| renderToolbarContainer(): SlottedTemplateResult { | ||
| return nothing; | ||
| } | ||
| } | ||
|
|
||
| @customElement("ak-user-bulk-revoke-sessions") | ||
| export class UserBulkRevokeSessionsForm extends ModalButton { | ||
| @property({ attribute: false }) | ||
| users: User[] = []; | ||
|
|
||
| @state() | ||
| isRevoking = false; | ||
|
|
||
| @state() | ||
| revokedCount = 0; | ||
|
|
||
| async confirm(): Promise<void> { | ||
| this.isRevoking = true; | ||
| this.revokedCount = 0; | ||
|
|
||
| try { | ||
| for (const user of this.users) { | ||
| // Get all sessions for this user | ||
| const sessions = await new CoreApi(DEFAULT_CONFIG).coreAuthenticatedSessionsList({ | ||
| userUsername: user.username, | ||
| pageSize: 1000, // Get all sessions | ||
| }); | ||
|
|
||
| // Delete each session | ||
| for (const session of sessions.results) { | ||
| if (session.uuid) { | ||
| await new CoreApi(DEFAULT_CONFIG).coreAuthenticatedSessionsDestroy({ | ||
| uuid: session.uuid, | ||
| }); | ||
| this.revokedCount++; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| this.onSuccess(); | ||
| this.dispatchEvent( | ||
| new CustomEvent(EVENT_REFRESH, { | ||
| bubbles: true, | ||
| composed: true, | ||
| }), | ||
| ); | ||
| this.open = false; | ||
| } catch (e) { | ||
| this.onError(e as Error); | ||
| throw e; | ||
| } finally { | ||
| this.isRevoking = false; | ||
| } | ||
| } | ||
|
|
||
| onSuccess(): void { | ||
| showMessage({ | ||
| message: msg( | ||
| str`Successfully revoked ${this.revokedCount} session(s) for ${this.users.length} user(s)`, | ||
| ), | ||
| level: MessageLevel.success, | ||
| }); | ||
| } | ||
|
|
||
| onError(e: Error): void { | ||
| showMessage({ | ||
| message: msg(str`Failed to revoke sessions: ${e.toString()}`), | ||
| level: MessageLevel.error, | ||
| }); | ||
| } | ||
|
|
||
| renderModalInner(): TemplateResult { | ||
| return html`<section class="pf-c-modal-box__header pf-c-page__main-section pf-m-light"> | ||
| <div class="pf-c-content"> | ||
| <h1 class="pf-c-title pf-m-2xl">${msg("Revoke Sessions")}</h1> | ||
| </div> | ||
| </section> | ||
| <section class="pf-c-modal-box__body pf-m-light"> | ||
| <form class="pf-c-form pf-m-horizontal"> | ||
| <p class="pf-c-title"> | ||
| ${msg( | ||
| str`Are you sure you want to revoke all sessions for ${this.users.length} user(s)?`, | ||
| )} | ||
| </p> | ||
| <p> | ||
| ${msg( | ||
| "This will force the selected users to re-authenticate on all their devices.", | ||
| )} | ||
| </p> | ||
| </form> | ||
| </section> | ||
| <section class="pf-c-modal-box__body pf-m-light"> | ||
| <ak-user-bulk-revoke-sessions-table | ||
| .objects=${this.users} | ||
| .metadata=${(item: User) => { | ||
| return [ | ||
| { key: msg("Username"), value: item.username }, | ||
| { key: msg("Name"), value: item.name || "" }, | ||
| ]; | ||
| }} | ||
| > | ||
| </ak-user-bulk-revoke-sessions-table> | ||
| </section> | ||
| <footer class="pf-c-modal-box__footer"> | ||
| <ak-spinner-button | ||
| .callAction=${() => { | ||
| return this.confirm(); | ||
| }} | ||
| class="pf-m-warning" | ||
| > | ||
| ${msg("Revoke Sessions")} </ak-spinner-button | ||
| > | ||
| <ak-spinner-button | ||
| .callAction=${async () => { | ||
| this.open = false; | ||
| }} | ||
| class="pf-m-secondary" | ||
| > | ||
| ${msg("Cancel")} | ||
| </ak-spinner-button> | ||
| </footer>`; | ||
| } | ||
| } | ||
|
|
||
| declare global { | ||
| interface HTMLElementTagNameMap { | ||
| "ak-user-bulk-revoke-sessions-table": UserBulkRevokeSessionsTable; | ||
| "ak-user-bulk-revoke-sessions": UserBulkRevokeSessionsForm; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.