Implement command to deactivate user from admin channel
Use `leave_room` in `leave_all_rooms` WIP: Add command to delete a list of users also implements a flag to prevent the user from being removed from their joined rooms. Report user deactivation failure reason Don't send leave events by default when mass deactivating user accounts Don't stop leaving rooms if an error was encountered WIP: Rename command, make flags consistent, don't deactivate admin accounts. Accounts should be deactivated as fast as possible and removing users from joined groups is completed afterwards. Fix admin safety logic, improve command output Continue leaving rooms if a room_id is invalid Ignore errors from leave_room Add notice to the list-local-users command Output form list-local-users can be used directly without modification with the deactivate-all command Only get mutex lock for admin room when sending message
This commit is contained in:
parent
2ecbcdda42
commit
f6183e457d
3 changed files with 156 additions and 60 deletions
|
@ -4,7 +4,7 @@ use super::{DEVICE_ID_LENGTH, SESSION_ID_LENGTH, TOKEN_LENGTH};
|
|||
use crate::{
|
||||
database::{admin::make_user_admin, DatabaseGuard},
|
||||
pdu::PduBuilder,
|
||||
utils, Error, Result, Ruma,
|
||||
utils, Database, Error, Result, Ruma,
|
||||
};
|
||||
use ruma::{
|
||||
api::client::{
|
||||
|
@ -398,55 +398,8 @@ pub async fn deactivate_route(
|
|||
return Err(Error::BadRequest(ErrorKind::NotJson, "Not json."));
|
||||
}
|
||||
|
||||
// Leave all joined rooms and reject all invitations
|
||||
// TODO: work over federation invites
|
||||
let all_rooms = db
|
||||
.rooms
|
||||
.rooms_joined(sender_user)
|
||||
.chain(
|
||||
db.rooms
|
||||
.rooms_invited(sender_user)
|
||||
.map(|t| t.map(|(r, _)| r)),
|
||||
)
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
for room_id in all_rooms {
|
||||
let room_id = room_id?;
|
||||
let event = RoomMemberEventContent {
|
||||
membership: MembershipState::Leave,
|
||||
displayname: None,
|
||||
avatar_url: None,
|
||||
is_direct: None,
|
||||
third_party_invite: None,
|
||||
blurhash: None,
|
||||
reason: None,
|
||||
join_authorized_via_users_server: None,
|
||||
};
|
||||
|
||||
let mutex_state = Arc::clone(
|
||||
db.globals
|
||||
.roomid_mutex_state
|
||||
.write()
|
||||
.unwrap()
|
||||
.entry(room_id.clone())
|
||||
.or_default(),
|
||||
);
|
||||
let state_lock = mutex_state.lock().await;
|
||||
|
||||
db.rooms.build_and_append_pdu(
|
||||
PduBuilder {
|
||||
event_type: RoomEventType::RoomMember,
|
||||
content: to_raw_value(&event).expect("event is valid, we just created it"),
|
||||
unsigned: None,
|
||||
state_key: Some(sender_user.to_string()),
|
||||
redacts: None,
|
||||
},
|
||||
sender_user,
|
||||
&room_id,
|
||||
&db,
|
||||
&state_lock,
|
||||
)?;
|
||||
}
|
||||
// Make the user leave all rooms before deactivation
|
||||
db.rooms.leave_all_rooms(&sender_user, &db).await?;
|
||||
|
||||
// Remove devices and mark account as deactivated
|
||||
db.users.deactivate_account(sender_user)?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue