zitadel/pkg/auth/api/grpc/user_session_converter.go
Livio Amstutz e7b139ba2c
fix: preferred login name (#231)
* fix: add preferred login name to my user sessions and get user info from view

* fix: my user in auth
2020-06-17 16:43:53 +02:00

38 lines
1.2 KiB
Go

package grpc
import (
auth_req_model "github.com/caos/zitadel/internal/auth_request/model"
usr_model "github.com/caos/zitadel/internal/user/model"
)
func userSessionViewsFromModel(userSessions []*usr_model.UserSessionView) []*UserSessionView {
converted := make([]*UserSessionView, len(userSessions))
for i, s := range userSessions {
converted[i] = userSessionViewFromModel(s)
}
return converted
}
func userSessionViewFromModel(userSession *usr_model.UserSessionView) *UserSessionView {
return &UserSessionView{
Sequence: userSession.Sequence,
AgentId: userSession.UserAgentID,
UserId: userSession.UserID,
UserName: userSession.UserName,
LoginName: userSession.LoginName,
DisplayName: userSession.DisplayName,
AuthState: userSessionStateFromModel(userSession.State),
}
}
func userSessionStateFromModel(state auth_req_model.UserSessionState) UserSessionState {
switch state {
case auth_req_model.UserSessionStateActive:
return UserSessionState_USERSESSIONSTATE_ACTIVE
case auth_req_model.UserSessionStateTerminated:
return UserSessionState_USERSESSIONSTATE_TERMINATED
default:
return UserSessionState_USERSESSIONSTATE_UNSPECIFIED
}
}