mirror of
https://github.com/ViViDboarder/bitwarden_rs_ldap.git
synced 2024-11-21 18:56:27 +00:00
Update to not query invites, but instead use new _Status field
This commit is contained in:
parent
c42bb99536
commit
c06d23b836
@ -9,26 +9,23 @@ use std::time::{Duration, Instant};
|
||||
|
||||
const COOKIE_LIFESPAN: Duration = Duration::from_secs(20 * 60);
|
||||
|
||||
fn true_val() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Deserialize)]
|
||||
pub struct User {
|
||||
#[serde(rename = "Email")]
|
||||
email: String,
|
||||
#[serde(rename = "_Enabled")]
|
||||
#[serde(default = "true_val")]
|
||||
enabled: bool,
|
||||
#[serde(rename = "_Status")]
|
||||
status: i32,
|
||||
}
|
||||
|
||||
impl User {
|
||||
pub fn get_email(&self) -> String {
|
||||
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()?;
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -41,14 +41,14 @@ fn invite_users(
|
||||
|
||||
/// 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>> {
|
||||
let all_users = client.users_and_invites()?;
|
||||
let all_users = client.users()?;
|
||||
let mut user_emails = HashSet::with_capacity(all_users.len());
|
||||
for user in all_users {
|
||||
user_emails.insert(user.get_email());
|
||||
if user.is_enabled() {
|
||||
println!("Existing user or invite found with email: {}", user.get_email());
|
||||
} else {
|
||||
if user.is_disabled() {
|
||||
println!("Existing disabled user found with email: {}", user.get_email());
|
||||
} else {
|
||||
println!("Existing user or invite found with email: {}", user.get_email());
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user