mirror of
https://github.com/nitnelave/lldap.git
synced 2023-04-12 14:25:13 +00:00
migration-tool: Import users' avatars
This commit is contained in:
parent
686bdc0cb1
commit
2ca083541e
1
Cargo.lock
generated
1
Cargo.lock
generated
@ -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",
|
||||||
|
@ -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"
|
||||||
|
@ -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(
|
||||||
|
crate::lldap::CreateUserInput {
|
||||||
id,
|
id,
|
||||||
email,
|
email,
|
||||||
display_name,
|
display_name,
|
||||||
first_name,
|
first_name,
|
||||||
last_name,
|
last_name,
|
||||||
|
avatar: avatar.map(base64::encode),
|
||||||
|
},
|
||||||
password,
|
password,
|
||||||
entry.dn,
|
entry.dn,
|
||||||
))
|
))
|
||||||
|
@ -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",
|
||||||
|
Loading…
Reference in New Issue
Block a user