From 6906e0ff5b4391a279c006753819c1d910d37a94 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 29 Jul 2026 21:48:02 +0000 Subject: [PATCH] Separate SCIM export email from event user name Load identity email for matched profiles and drop parsing userName as email; user_name column stays the event value. Signed-off-by: Cursor Agent Co-authored-by: Bryan FRIMIN --- pkg/coredata/membership_profile.go | 4 +++- pkg/iam/log_export_csv.go | 26 +++----------------------- pkg/iam/log_export_csv_test.go | 8 -------- 3 files changed, 6 insertions(+), 32 deletions(-) diff --git a/pkg/coredata/membership_profile.go b/pkg/coredata/membership_profile.go index c1919552a..49854d563 100644 --- a/pkg/coredata/membership_profile.go +++ b/pkg/coredata/membership_profile.go @@ -507,7 +507,7 @@ SELECT p.id, p.identity_id, p.organization_id, - ''::citext AS email_address, + i.email_address, p.source, p.state, p.full_name, @@ -540,6 +540,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.organization_id = @organization_id diff --git a/pkg/iam/log_export_csv.go b/pkg/iam/log_export_csv.go index c63812cd0..a3f8edf49 100644 --- a/pkg/iam/log_export_csv.go +++ b/pkg/iam/log_export_csv.go @@ -31,7 +31,6 @@ import ( "go.gearno.de/kit/pg" "go.probo.inc/probo/pkg/coredata" "go.probo.inc/probo/pkg/gid" - "go.probo.inc/probo/pkg/mail" "go.probo.inc/probo/pkg/page" ) @@ -227,12 +226,6 @@ func scimEventCSVRow( profilesByUserName map[string]scimProfileExportInfo, ) []string { profile := profilesByUserName[strings.ToLower(event.UserName)] - email := profile.email - fullName := profile.fullName - - if email == "" { - email = scimEmailFromUserName(event.UserName) - } return []string{ organizationName, @@ -241,8 +234,8 @@ func scimEventCSVRow( event.Method, event.Path, event.UserName, - email, - fullName, + profile.email, + profile.fullName, strconv.Itoa(event.StatusCode), stringPtrValue(event.ErrorMessage), event.IPAddress.String(), @@ -327,7 +320,7 @@ func loadSCIMProfileExportInfo( key := strings.ToLower(*profile.UserName) result[key] = scimProfileExportInfo{ - email: scimEmailFromUserName(*profile.UserName), + email: profile.EmailAddress.String(), fullName: profileFullName(profile), } } @@ -366,19 +359,6 @@ func uniqueNonEmptyStrings(values []string) []string { return out } -func scimEmailFromUserName(userName string) string { - userName = strings.TrimSpace(userName) - if userName == "" { - return "" - } - - if _, err := mail.ParseAddr(userName); err == nil { - return userName - } - - return "" -} - func profileFullName(profile *coredata.MembershipProfile) string { if profile.FormattedName != nil && *profile.FormattedName != "" { return *profile.FormattedName diff --git a/pkg/iam/log_export_csv_test.go b/pkg/iam/log_export_csv_test.go index 52f70662c..303061350 100644 --- a/pkg/iam/log_export_csv_test.go +++ b/pkg/iam/log_export_csv_test.go @@ -26,14 +26,6 @@ import ( "github.com/stretchr/testify/assert" ) -func TestScimEmailFromUserName(t *testing.T) { - t.Parallel() - - assert.Equal(t, "user@example.com", scimEmailFromUserName("user@example.com")) - assert.Equal(t, "", scimEmailFromUserName("not-an-email")) - assert.Equal(t, "", scimEmailFromUserName("")) -} - func TestUniqueNonEmptyStrings(t *testing.T) { t.Parallel()