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 <cursoragent@cursor.com>

Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
Cursor Agent
2026-07-29 21:48:02 +00:00
parent 6cbf16814c
commit 6906e0ff5b
3 changed files with 6 additions and 32 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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()