Skip to content
This repository has been archived by the owner on Sep 10, 2024. It is now read-only.

Commit

Permalink
Kill all sessions when deactivating a user
Browse files Browse the repository at this point in the history
  • Loading branch information
sandhose committed Jul 16, 2024
1 parent 6fb4a1b commit 21ed451
Showing 1 changed file with 30 additions and 2 deletions.
32 changes: 30 additions & 2 deletions crates/tasks/src/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
use anyhow::Context;
use apalis_core::{context::JobContext, executor::TokioExecutor, monitor::Monitor};
use mas_storage::{
compat::CompatSessionFilter,
job::{DeactivateUserJob, JobWithSpanContext, ReactivateUserJob},
user::UserRepository,
oauth2::OAuth2SessionFilter,
user::{BrowserSessionFilter, UserRepository},
RepositoryAccess,
};
use tracing::info;
Expand Down Expand Up @@ -52,7 +54,33 @@ async fn deactivate_user(
.await
.context("Failed to lock user")?;

// TODO: delete the sessions & access tokens
// Kill all sessions for the user
let n = repo
.browser_session()
.finish_bulk(
&clock,
BrowserSessionFilter::new().for_user(&user).active_only(),
)
.await?;
info!(affected = n, "Killed all browser sessions for user");

let n = repo
.oauth2_session()
.finish_bulk(
&clock,
OAuth2SessionFilter::new().for_user(&user).active_only(),
)
.await?;
info!(affected = n, "Killed all OAuth 2.0 sessions for user");

let n = repo
.compat_session()
.finish_bulk(
&clock,
CompatSessionFilter::new().for_user(&user).active_only(),
)
.await?;
info!(affected = n, "Killed all compatibility sessions for user");

// Before calling back to the homeserver, commit the changes to the database, as
// we want the user to be locked out as soon as possible
Expand Down

0 comments on commit 21ed451

Please sign in to comment.