MCPcopy Create free account
hub / github.com/bytebase/bytebase / convertToUser

Function convertToUser

backend/api/v1/user_service.go:717–749  ·  view source on GitHub ↗
(ctx context.Context, iamManager *iam.Manager, user *store.UserMessage)

Source from the content-addressed store, hash-verified

715}
716
717func convertToUser(ctx context.Context, iamManager *iam.Manager, user *store.UserMessage) (*v1pb.User, error) {
718 groups, err := iamManager.GetUserGroups(ctx, common.GetWorkspaceIDFromContext(ctx), user.Email)
719 if err != nil {
720 return nil, err
721 }
722
723 workspaceID := common.GetWorkspaceIDFromContext(ctx)
724 convertedUser := &v1pb.User{
725 Name: common.FormatUserEmail(user.Email),
726 State: convertDeletedToState(user.MemberDeleted),
727 Email: user.Email,
728 Phone: user.Phone,
729 Title: user.Name,
730 Profile: &v1pb.User_Profile{
731 LastLoginTime: user.Profile.LastLoginTime,
732 LastChangePasswordTime: user.Profile.LastChangePasswordTime,
733 Source: user.Profile.Source,
734 },
735 Groups: groups,
736 Workspace: common.FormatWorkspace(workspaceID),
737 }
738
739 if user.MFAConfig != nil {
740 convertedUser.MfaEnabled = user.MFAConfig.OtpSecret != ""
741 // Only expose temporary MFA secrets and recovery codes to the user themselves
742 if currentUser, ok := GetUserFromContext(ctx); ok && currentUser.ID == user.ID {
743 convertedUser.TempOtpSecret = user.MFAConfig.TempOtpSecret
744 convertedUser.TempRecoveryCodes = user.MFAConfig.TempRecoveryCodes
745 convertedUser.TempOtpSecretCreatedTime = user.MFAConfig.TempOtpSecretCreatedTime
746 }
747 }
748 return convertedUser, nil
749}
750
751func validateEndUserEmail(email string) error {
752 if common.IsServiceAccountEmail(email) {

Callers 11

GetUserMethod · 0.85
BatchGetUsersMethod · 0.85
GetCurrentUserMethod · 0.85
ListUsersMethod · 0.85
CreateUserMethod · 0.85
UpdateUserMethod · 0.85
UndeleteUserMethod · 0.85
UpdateEmailMethod · 0.85
SignupMethod · 0.85
finalizeLoginMethod · 0.85

Calls 6

FormatUserEmailFunction · 0.92
FormatWorkspaceFunction · 0.92
convertDeletedToStateFunction · 0.85
GetUserFromContextFunction · 0.85
GetUserGroupsMethod · 0.80

Tested by

no test coverage detected