migration-tool: Import users' avatars

This commit is contained in:
Valentin Tolmer 2022-08-09 09:43:55 +02:00 committed by nitnelave
parent 686bdc0cb1
commit 2ca083541e
4 changed files with 20 additions and 18 deletions

1
Cargo.lock generated
View File

@ -2278,6 +2278,7 @@ name = "migration-tool"
version = "0.3.0-alpha.1"
dependencies = [
"anyhow",
"base64",
"graphql_client 0.11.0",
"ldap3",
"lldap_auth",

View File

@ -6,6 +6,7 @@ authors = ["Valentin Tolmer <valentin@tolmer.fr>"]
[dependencies]
anyhow = "*"
base64 = "0.13"
rand = "0.8"
requestty = "0.4.1"
serde = "1"

View File

@ -184,14 +184,23 @@ impl TryFrom<ResultEntry> for User {
.or_else(|| get_optional_attribute("name"))
.or_else(|| get_optional_attribute("displayName"));
let first_name = get_optional_attribute("givenName");
let avatar = entry
.attrs
.get("jpegPhoto")
.map(|v| v.iter().map(|s| s.as_bytes().to_vec()).collect::<Vec<_>>())
.or_else(|| entry.bin_attrs.get("jpegPhoto").map(Clone::clone))
.and_then(|v| v.into_iter().next().filter(|s| !s.is_empty()));
let password =
get_optional_attribute("userPassword").or_else(|| get_optional_attribute("password"));
Ok(User::new(
crate::lldap::CreateUserInput {
id,
email,
display_name,
first_name,
last_name,
avatar: avatar.map(base64::encode),
},
password,
entry.dn,
))

View File

@ -70,23 +70,12 @@ pub struct User {
impl User {
// https://github.com/graphql-rust/graphql-client/issues/386
pub fn new(
id: String,
email: String,
display_name: Option<String>,
first_name: Option<String>,
last_name: Option<String>,
user_input: create_user::CreateUserInput,
password: Option<String>,
dn: String,
) -> User {
User {
user_input: create_user::CreateUserInput {
id,
email,
display_name,
first_name,
last_name,
avatar: None,
},
user_input,
password,
dn,
}
@ -103,6 +92,8 @@ impl User {
)]
struct CreateUser;
pub type CreateUserInput = create_user::CreateUserInput;
#[derive(GraphQLQuery)]
#[graphql(
schema_path = "../schema.graphql",