diff --git a/pkg/coredata/membership_profile.go b/pkg/coredata/membership_profile.go index 5a5d392b1..e24d2e655 100644 --- a/pkg/coredata/membership_profile.go +++ b/pkg/coredata/membership_profile.go @@ -506,7 +506,7 @@ SELECT p.id, p.identity_id, p.organization_id, - ''::citext AS email_address, + i.email_address, p.source, p.state, p.full_name, @@ -541,6 +541,8 @@ SELECT p.updated_at FROM iam_membership_profiles p +INNER JOIN identities i + ON i.id = p.identity_id WHERE p.%s AND p.id = ANY(@profile_ids) diff --git a/pkg/iam/log_export_csv.go b/pkg/iam/log_export_csv.go index 9df1a124b..d0c1ec282 100644 --- a/pkg/iam/log_export_csv.go +++ b/pkg/iam/log_export_csv.go @@ -307,28 +307,13 @@ func loadSCIMProfileExportInfo( return scimProfileExportLookup{}, fmt.Errorf("cannot load SCIM export profiles: %w", err) } - identityIDs := make([]gid.GID, 0, len(profiles)) - for _, profile := range profiles { - identityIDs = append(identityIDs, profile.IdentityID) - } - - var identities coredata.Identities - if err := identities.LoadByIDs(ctx, conn, identityIDs); err != nil { - return scimProfileExportLookup{}, fmt.Errorf("cannot load SCIM profile identity emails: %w", err) - } - - emailByIdentityID := make(map[gid.GID]string, len(identities)) - for _, identity := range identities { - emailByIdentityID[identity.ID] = identity.EmailAddress.String() - } - lookup := scimProfileExportLookup{ byProfileID: make(map[gid.GID]scimProfileExportInfo, len(profiles)), byUserName: make(map[string]scimProfileExportInfo, len(profiles)), } for _, profile := range profiles { info := scimProfileExportInfo{ - email: emailByIdentityID[profile.IdentityID], + email: profile.EmailAddress.String(), fullName: profileFullName(profile), }