@@ -2,6 +2,7 @@ use jsonwebtoken::{errors::Error, DecodingKey, EncodingKey, Header, TokenData, V
22use once_cell:: sync:: Lazy ;
33use sea_orm:: prelude:: Uuid ;
44use serde:: { Deserialize , Serialize } ;
5+ use serde_json:: Value as JsonValue ;
56use std:: collections:: HashMap ;
67
78use entity:: { client, resource, resource_group, session, user} ;
@@ -18,15 +19,24 @@ pub struct Resource {
1819 pub client_id : Uuid ,
1920 pub client_name : String ,
2021 pub group_name : String ,
21- pub identifiers : HashMap < String , String > ,
22+ #[ serde( skip_serializing_if = "Option::is_none" ) ]
23+ pub identifiers : Option < HashMap < String , JsonValue > > ,
2224}
2325
2426impl Resource {
25- fn from ( client : & client:: Model , resource_group : resource_group:: Model , resources : Vec < resource:: Model > ) -> Self {
26- let mut identifiers = HashMap :: new ( ) ;
27- for resource in resources {
28- identifiers. insert ( resource. name , resource. value ) ;
29- }
27+ fn from ( client : & client:: Model , resource_group : resource_group:: Model , resources : Option < Vec < resource:: Model > > ) -> Self {
28+ let identifiers = resources. map ( |resources| {
29+ resources
30+ . into_iter ( )
31+ . map ( |resource| {
32+ let value = match serde_json:: from_str ( & resource. value ) {
33+ Ok ( json_value) => json_value,
34+ Err ( _) => JsonValue :: String ( resource. value ) ,
35+ } ;
36+ ( resource. name , value)
37+ } )
38+ . collect ( )
39+ } ) ;
3040
3141 Self {
3242 client_id : client. id ,
@@ -66,7 +76,7 @@ impl JwtUser {
6676 last_name : user. last_name . unwrap_or_else ( || "" . into ( ) ) ,
6777 email : user. email . clone ( ) ,
6878 phone : user. phone . unwrap_or_else ( || "" . into ( ) ) ,
69- resource : Some ( Resource :: from ( client, resource_group, resources) ) ,
79+ resource : Some ( Resource :: from ( client, resource_group, Some ( resources) ) ) ,
7080 }
7181 }
7282
0 commit comments