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" version = "0.3.0-alpha.1"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"base64",
"graphql_client 0.11.0", "graphql_client 0.11.0",
"ldap3", "ldap3",
"lldap_auth", "lldap_auth",

View File

@ -6,6 +6,7 @@ authors = ["Valentin Tolmer <valentin@tolmer.fr>"]
[dependencies] [dependencies]
anyhow = "*" anyhow = "*"
base64 = "0.13"
rand = "0.8" rand = "0.8"
requestty = "0.4.1" requestty = "0.4.1"
serde = "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("name"))
.or_else(|| get_optional_attribute("displayName")); .or_else(|| get_optional_attribute("displayName"));
let first_name = get_optional_attribute("givenName"); 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 = let password =
get_optional_attribute("userPassword").or_else(|| get_optional_attribute("password")); get_optional_attribute("userPassword").or_else(|| get_optional_attribute("password"));
Ok(User::new( Ok(User::new(
id, crate::lldap::CreateUserInput {
email, id,
display_name, email,
first_name, display_name,
last_name, first_name,
last_name,
avatar: avatar.map(base64::encode),
},
password, password,
entry.dn, entry.dn,
)) ))

View File

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