adminroom: leave all rooms by default on manual deactivations
Signed-off-by: strawberry <strawberry@puppygock.gay>
This commit is contained in:
parent
f1d90e5df6
commit
65fbb80145
2 changed files with 18 additions and 14 deletions
|
@ -26,11 +26,11 @@ pub(crate) enum UserCommand {
|
||||||
|
|
||||||
/// - Deactivate a user
|
/// - Deactivate a user
|
||||||
///
|
///
|
||||||
/// User will not be removed from all rooms by default.
|
/// User will be removed from all rooms by default.
|
||||||
/// Use --leave-rooms to force the user to leave all rooms
|
/// Use --no-leave-rooms to not leave all rooms by default.
|
||||||
Deactivate {
|
Deactivate {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
leave_rooms: bool,
|
no_leave_rooms: bool,
|
||||||
user_id: String,
|
user_id: String,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -38,8 +38,10 @@ pub(crate) enum UserCommand {
|
||||||
///
|
///
|
||||||
/// Recommended to use in conjunction with list-local-users.
|
/// Recommended to use in conjunction with list-local-users.
|
||||||
///
|
///
|
||||||
/// Users will not be removed from joined rooms by default.
|
/// Users will be removed from joined rooms by default.
|
||||||
/// Can be overridden with --leave-rooms OR the --force flag.
|
///
|
||||||
|
/// Can be overridden with --no-leave-rooms.
|
||||||
|
///
|
||||||
/// Removing a mass amount of users from a room may cause a significant
|
/// Removing a mass amount of users from a room may cause a significant
|
||||||
/// amount of leave events. The time to leave rooms may depend significantly
|
/// amount of leave events. The time to leave rooms may depend significantly
|
||||||
/// on joined rooms and servers.
|
/// on joined rooms and servers.
|
||||||
|
@ -49,7 +51,7 @@ pub(crate) enum UserCommand {
|
||||||
DeactivateAll {
|
DeactivateAll {
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
/// Remove users from their joined rooms
|
/// Remove users from their joined rooms
|
||||||
leave_rooms: bool,
|
no_leave_rooms: bool,
|
||||||
#[arg(short, long)]
|
#[arg(short, long)]
|
||||||
/// Also deactivate admin accounts and will assume leave all rooms too
|
/// Also deactivate admin accounts and will assume leave all rooms too
|
||||||
force: bool,
|
force: bool,
|
||||||
|
@ -99,16 +101,16 @@ pub(crate) async fn process(command: UserCommand, body: Vec<&str>) -> Result<Roo
|
||||||
password,
|
password,
|
||||||
} => create(body, username, password).await?,
|
} => create(body, username, password).await?,
|
||||||
UserCommand::Deactivate {
|
UserCommand::Deactivate {
|
||||||
leave_rooms,
|
no_leave_rooms,
|
||||||
user_id,
|
user_id,
|
||||||
} => deactivate(body, leave_rooms, user_id).await?,
|
} => deactivate(body, no_leave_rooms, user_id).await?,
|
||||||
UserCommand::ResetPassword {
|
UserCommand::ResetPassword {
|
||||||
username,
|
username,
|
||||||
} => reset_password(body, username).await?,
|
} => reset_password(body, username).await?,
|
||||||
UserCommand::DeactivateAll {
|
UserCommand::DeactivateAll {
|
||||||
leave_rooms,
|
no_leave_rooms,
|
||||||
force,
|
force,
|
||||||
} => deactivate_all(body, leave_rooms, force).await?,
|
} => deactivate_all(body, no_leave_rooms, force).await?,
|
||||||
UserCommand::ListJoinedRooms {
|
UserCommand::ListJoinedRooms {
|
||||||
user_id,
|
user_id,
|
||||||
} => list_joined_rooms(body, user_id).await?,
|
} => list_joined_rooms(body, user_id).await?,
|
||||||
|
|
|
@ -128,7 +128,7 @@ pub(crate) async fn create(
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn deactivate(
|
pub(crate) async fn deactivate(
|
||||||
_body: Vec<&str>, leave_rooms: bool, user_id: String,
|
_body: Vec<&str>, no_leave_rooms: bool, user_id: String,
|
||||||
) -> Result<RoomMessageEventContent> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
// Validate user id
|
// Validate user id
|
||||||
let user_id = parse_local_user_id(&user_id)?;
|
let user_id = parse_local_user_id(&user_id)?;
|
||||||
|
@ -144,7 +144,7 @@ pub(crate) async fn deactivate(
|
||||||
|
|
||||||
services().users.deactivate_account(&user_id)?;
|
services().users.deactivate_account(&user_id)?;
|
||||||
|
|
||||||
if leave_rooms {
|
if !no_leave_rooms {
|
||||||
services()
|
services()
|
||||||
.admin
|
.admin
|
||||||
.send_message(RoomMessageEventContent::text_plain(format!(
|
.send_message(RoomMessageEventContent::text_plain(format!(
|
||||||
|
@ -185,7 +185,9 @@ pub(crate) async fn reset_password(_body: Vec<&str>, username: String) -> Result
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) async fn deactivate_all(body: Vec<&str>, leave_rooms: bool, force: bool) -> Result<RoomMessageEventContent> {
|
pub(crate) async fn deactivate_all(
|
||||||
|
body: Vec<&str>, no_leave_rooms: bool, force: bool,
|
||||||
|
) -> Result<RoomMessageEventContent> {
|
||||||
if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" {
|
if body.len() < 2 || !body[0].trim().starts_with("```") || body.last().unwrap_or(&"").trim() != "```" {
|
||||||
return Ok(RoomMessageEventContent::text_plain(
|
return Ok(RoomMessageEventContent::text_plain(
|
||||||
"Expected code block in command body. Add --help for details.",
|
"Expected code block in command body. Add --help for details.",
|
||||||
|
@ -245,7 +247,7 @@ pub(crate) async fn deactivate_all(body: Vec<&str>, leave_rooms: bool, force: bo
|
||||||
match services().users.deactivate_account(&user_id) {
|
match services().users.deactivate_account(&user_id) {
|
||||||
Ok(()) => {
|
Ok(()) => {
|
||||||
deactivation_count = deactivation_count.saturating_add(1);
|
deactivation_count = deactivation_count.saturating_add(1);
|
||||||
if leave_rooms || force {
|
if !no_leave_rooms {
|
||||||
info!("Forcing user {user_id} to leave all rooms apart of deactivate-all");
|
info!("Forcing user {user_id} to leave all rooms apart of deactivate-all");
|
||||||
leave_all_rooms(&user_id).await;
|
leave_all_rooms(&user_id).await;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue