@@ -61,10 +61,13 @@ func (h Handler) ListPlatformUsers(ctx context.Context, req *frontierv1beta1.Lis
6161 return nil , status .Errorf (codes .Internal , err .Error ())
6262 }
6363
64+ subjectRelationMap := make (map [string ]string )
65+
6466 // fetch users
6567 userIDs := utils .Map (utils .Filter (relations , func (r relation.Relation ) bool {
6668 return r .Subject .Namespace == schema .UserPrincipal
6769 }), func (r relation.Relation ) string {
70+ subjectRelationMap [r .Subject .ID ] = r .RelationName
6871 return r .Subject .ID
6972 })
7073 userPBs := make ([]* frontierv1beta1.User , 0 , len (userIDs ))
@@ -75,6 +78,10 @@ func (h Handler) ListPlatformUsers(ctx context.Context, req *frontierv1beta1.Lis
7578 return nil , status .Errorf (codes .Internal , err .Error ())
7679 }
7780 for _ , u := range users {
81+ if u .Metadata == nil {
82+ u .Metadata = make (map [string ]any )
83+ }
84+ u .Metadata ["relation" ] = subjectRelationMap [u .ID ]
7885 userPB , err := transformUserToPB (u )
7986 if err != nil {
8087 logger .Error (err .Error ())
@@ -88,6 +95,7 @@ func (h Handler) ListPlatformUsers(ctx context.Context, req *frontierv1beta1.Lis
8895 serviceUserIDs := utils .Map (utils .Filter (relations , func (r relation.Relation ) bool {
8996 return r .Subject .Namespace == schema .ServiceUserPrincipal
9097 }), func (r relation.Relation ) string {
98+ subjectRelationMap [r .Subject .ID ] = r .RelationName
9199 return r .Subject .ID
92100 })
93101 serviceUserPBs := make ([]* frontierv1beta1.ServiceUser , 0 , len (serviceUserIDs ))
@@ -98,6 +106,10 @@ func (h Handler) ListPlatformUsers(ctx context.Context, req *frontierv1beta1.Lis
98106 return nil , status .Errorf (codes .Internal , err .Error ())
99107 }
100108 for _ , u := range serviceUsers {
109+ if u .Metadata == nil {
110+ u .Metadata = make (map [string ]any )
111+ }
112+ u .Metadata ["relation" ] = subjectRelationMap [u .ID ]
101113 serviceUserPB , err := transformServiceUserToPB (u )
102114 if err != nil {
103115 logger .Error (err .Error ())
0 commit comments