diff --git a/crates/cli/src/commands/manage.rs b/crates/cli/src/commands/manage.rs index 0690324b6..4f604b8b4 100644 --- a/crates/cli/src/commands/manage.rs +++ b/crates/cli/src/commands/manage.rs @@ -25,7 +25,7 @@ use mas_storage::{ oauth2::OAuth2SessionFilter, queue::{ DeactivateUserJob, ProvisionUserJob, QueueJobRepositoryExt as _, ReactivateUserJob, - SyncDevicesJob, + SendRoomInviteEmailsJob, SyncDevicesJob, }, user::{ BrowserSessionFilter, UserEmailRepository, UserFilter, UserPasswordRepository, @@ -230,6 +230,16 @@ enum Subcommand { #[clap(long)] ignore_password_complexity: bool, }, + + /// Send a room invite email to a list of addresses + SendRoomInvites { + /// The room to invite the recipients to + room_id: String, + + /// The addresses to invite + #[arg(required = true)] + emails: Vec, + }, } impl Options { @@ -569,6 +579,29 @@ impl Options { Ok(ExitCode::SUCCESS) } + SC::SendRoomInvites { room_id, emails } => { + let _span = info_span!( + "cli.manage.send_room_invites", + room.id = room_id, + recipients.count = emails.len(), + ) + .entered(); + let database_config = DatabaseConfig::extract_or_default(figment) + .map_err(anyhow::Error::from_boxed)?; + let mut conn = database_connection_from_config(&database_config).await?; + let txn = conn.begin().await?; + let mut repo = PgRepository::from_conn(txn); + + let job = SendRoomInviteEmailsJob::new(room_id, emails); + repo.queue_job().schedule_job(&mut rng, &clock, job).await?; + + repo.into_inner().commit().await?; + + info!("Scheduled the room invite emails. A worker must be running to send them."); + + Ok(ExitCode::SUCCESS) + } + SC::KillSessions { username, dry_run } => { let _span = info_span!("cli.manage.kill_sessions", user.username = username).entered(); diff --git a/docs/reference/cli/manage.md b/docs/reference/cli/manage.md index 0117a9638..85cc6756c 100644 --- a/docs/reference/cli/manage.md +++ b/docs/reference/cli/manage.md @@ -151,3 +151,16 @@ Options: $ mas-cli manage register-user $ mas-cli manage register-user --yes ``` + +## `manage send-room-invites` + +Send a room invite email to a list of addresses. This schedules the job; a +worker must be running to actually send the emails. + +Arguments: +- ``: The room to invite the recipients to. +- `...`: The addresses to invite. At least one is required. + +``` +$ mas-cli manage send-room-invites '!room:example.com' alice@example.com bob@example.com +```