rename iter_locals to get_local_users; make get_local_users skip on parse errors; remove deprecated function count_local_users

merge-requests/254/head
Torsten Flammiger 2 years ago
parent 8d51359668
commit fb19114bd9

@ -95,14 +95,11 @@ impl Admin {
match event {
AdminCommand::ListLocalUsers => {
// collect local users only
let users = guard.users.iter_locals();
let users = guard.users.get_local_users();
let mut msg: String = format!("Found {} local user account(s):\n", users.len());
msg += &users.join("\n");
// send number of local users as plain text:
// TODO: send as Markdown
send_message(RoomMessageEventContent::text_plain(&msg), guard, &state_lock);
}
AdminCommand::RegisterAppservice(yaml) => {

@ -84,16 +84,6 @@ impl Users {
Ok(self.userid_password.iter().count())
}
/// The method is DEPRECATED and was replaced by iter_locals()
///
/// This method will only count those local user accounts with
/// a password thus returning only real accounts on this instance.
#[tracing::instrument(skip(self))]
pub fn count_local_users(&self) -> Result<usize> {
let n = self.userid_password.iter().filter(|(_, bytes)| bytes.len() > 0).count();
Ok(n)
}
/// Find out which user an access token belongs to.
#[tracing::instrument(skip(self, token))]
@ -134,13 +124,19 @@ impl Users {
})
}
/// Returns a vector of local usernames
/// Returns a list of local usernames, that is, a parseable username
/// with a password of length greater then zero bytes.
/// If utils::string_from_bytes returns an error that username will be skipped
/// and the function will log the error
#[tracing::instrument(skip(self))]
pub fn iter_locals(&self) -> Vec<String> {
pub fn get_local_users(&self) -> Vec<String> {
self.userid_password.iter().filter(|(_, pw)| pw.len() > 0).map(|(username, _)| {
match utils::string_from_bytes(&username) {
Ok(s) => s,
Err(e) => e.to_string()
Err(e) => {
Error::bad_database(format!("Failed to parse username: {}", e.to_string()));
None
}
}
}).collect::<Vec<String>>()
}

Loading…
Cancel
Save