From 049a36050670bfa1d42f17785e633e8ad95705ed Mon Sep 17 00:00:00 2001 From: Bojidar Marinov Date: Thu, 1 Aug 2024 00:55:07 +0300 Subject: [PATCH] server: Lookup first_name/last_name in the right list of attributes (#943) Note the std::mem::take(&mut user.attributes) further up that zeroes out user.attributes --- server/src/infra/graphql/query.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/server/src/infra/graphql/query.rs b/server/src/infra/graphql/query.rs index 4e34fce..5332d70 100644 --- a/server/src/infra/graphql/query.rs +++ b/server/src/infra/graphql/query.rs @@ -296,29 +296,26 @@ impl User { } fn first_name(&self) -> &str { - self.user - .attributes + self.attributes .iter() - .find(|a| a.name.as_str() == "first_name") - .map(|a| a.value.unwrap()) + .find(|a| a.attribute.name.as_str() == "first_name") + .map(|a| a.attribute.value.unwrap()) .unwrap_or("") } fn last_name(&self) -> &str { - self.user - .attributes + self.attributes .iter() - .find(|a| a.name.as_str() == "last_name") - .map(|a| a.value.unwrap()) + .find(|a| a.attribute.name.as_str() == "last_name") + .map(|a| a.attribute.value.unwrap()) .unwrap_or("") } fn avatar(&self) -> Option { - self.user - .attributes + self.attributes .iter() - .find(|a| a.name.as_str() == "avatar") - .map(|a| String::from(&a.value.unwrap::())) + .find(|a| a.attribute.name.as_str() == "avatar") + .map(|a| String::from(&a.attribute.value.unwrap::())) } fn creation_date(&self) -> chrono::DateTime { @@ -716,6 +713,8 @@ mod tests { id email creationDate + firstName + lastName uuid attributes { name @@ -831,6 +830,8 @@ mod tests { "email": "bob@bobbers.on", "creationDate": "1970-01-01T00:00:00.042+00:00", "uuid": "b1a2a3a4-b1b2-c1c2-d1d2-d3d4d5d6d7d8", + "firstName": "Bob", + "lastName": "Bobberson", "attributes": [{ "name": "first_name", "value": ["Bob"],