Update to not query invites, but instead use new _Status field

This commit is contained in:
ViViDboarder 2019-04-12 16:40:50 -07:00
parent c42bb99536
commit c06d23b836
2 changed files with 10 additions and 27 deletions

View File

@ -9,26 +9,23 @@ use std::time::{Duration, Instant};
const COOKIE_LIFESPAN: Duration = Duration::from_secs(20 * 60); const COOKIE_LIFESPAN: Duration = Duration::from_secs(20 * 60);
fn true_val() -> bool {
true
}
#[derive(Debug)] #[derive(Debug)]
#[derive(Deserialize)] #[derive(Deserialize)]
pub struct User { pub struct User {
#[serde(rename = "Email")] #[serde(rename = "Email")]
email: String, email: String,
#[serde(rename = "_Enabled")] #[serde(rename = "_Status")]
#[serde(default = "true_val")] status: i32,
enabled: bool,
} }
impl User { impl User {
pub fn get_email(&self) -> String { pub fn get_email(&self) -> String {
self.email.clone() self.email.clone()
} }
pub fn is_enabled(&self) -> bool {
self.enabled pub fn is_disabled(&self) -> bool {
// HACK: Magic number
self.status != 2
} }
} }
@ -158,18 +155,4 @@ impl Client {
let all_users: Vec<User> = self.get("/users").json()?; let all_users: Vec<User> = self.get("/users").json()?;
Ok(all_users) Ok(all_users)
} }
/// Get all invited users
pub fn invites(&mut self) -> Result<Vec<User>, Box<Error>> {
let all_invites: Vec<User> = self.get("/invites").json()?;
Ok(all_invites)
}
/// Get all users and invites
pub fn users_and_invites(&mut self) -> Result<Vec<User>, Box<Error>> {
let mut all_users = self.users()?;
let mut invites = self.invites()?;
all_users.append(&mut invites);
Ok(all_users)
}
} }

View File

@ -41,14 +41,14 @@ fn invite_users(
/// Creates set of email addresses for users that already exist in Bitwarden /// Creates set of email addresses for users that already exist in Bitwarden
fn get_existing_users(client: &mut bw_admin::Client) -> Result<HashSet<String>, Box<Error>> { fn get_existing_users(client: &mut bw_admin::Client) -> Result<HashSet<String>, Box<Error>> {
let all_users = client.users_and_invites()?; let all_users = client.users()?;
let mut user_emails = HashSet::with_capacity(all_users.len()); let mut user_emails = HashSet::with_capacity(all_users.len());
for user in all_users { for user in all_users {
user_emails.insert(user.get_email()); user_emails.insert(user.get_email());
if user.is_enabled() { if user.is_disabled() {
println!("Existing user or invite found with email: {}", user.get_email());
} else {
println!("Existing disabled user found with email: {}", user.get_email()); println!("Existing disabled user found with email: {}", user.get_email());
} else {
println!("Existing user or invite found with email: {}", user.get_email());
} }
} }