diff --git a/internal/auth/repository/eventsourcing/eventstore/auth_request.go b/internal/auth/repository/eventsourcing/eventstore/auth_request.go index 395848fe11..f4fea523ce 100644 --- a/internal/auth/repository/eventsourcing/eventstore/auth_request.go +++ b/internal/auth/repository/eventsourcing/eventstore/auth_request.go @@ -818,17 +818,19 @@ func (repo *AuthRequestRepo) usersForUserSelection(request *domain.AuthRequest) if err != nil { return nil, err } - users := make([]domain.UserSelection, len(userSessions)) - for i, session := range userSessions { - users[i] = domain.UserSelection{ - UserID: session.UserID, - DisplayName: session.DisplayName, - UserName: session.UserName, - LoginName: session.LoginName, - ResourceOwner: session.ResourceOwner, - AvatarKey: session.AvatarKey, - UserSessionState: model.UserSessionStateToDomain(session.State), - SelectionPossible: request.RequestedOrgID == "" || request.RequestedOrgID == session.ResourceOwner, + users := make([]domain.UserSelection, 0) + for _, session := range userSessions { + if request.RequestedOrgID == "" || request.RequestedOrgID == session.ResourceOwner { + users = append(users, domain.UserSelection{ + UserID: session.UserID, + DisplayName: session.DisplayName, + UserName: session.UserName, + LoginName: session.LoginName, + ResourceOwner: session.ResourceOwner, + AvatarKey: session.AvatarKey, + UserSessionState: model.UserSessionStateToDomain(session.State), + SelectionPossible: request.RequestedOrgID == "" || request.RequestedOrgID == session.ResourceOwner, + }) } } return users, nil diff --git a/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go b/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go index 82c66f6bb6..52b1b2a90c 100644 --- a/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go +++ b/internal/auth/repository/eventsourcing/eventstore/auth_request_test.go @@ -401,12 +401,6 @@ func TestAuthRequestRepo_nextSteps(t *testing.T) { SelectionPossible: true, ResourceOwner: "orgID1", }, - { - UserID: "id2", - LoginName: "loginname2", - SelectionPossible: false, - ResourceOwner: "orgID2", - }, }, }}, nil,