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:
@@ -507,7 +507,7 @@ SELECT
|
|||||||
p.id,
|
p.id,
|
||||||
p.identity_id,
|
p.identity_id,
|
||||||
p.organization_id,
|
p.organization_id,
|
||||||
''::citext AS email_address,
|
i.email_address,
|
||||||
p.source,
|
p.source,
|
||||||
p.state,
|
p.state,
|
||||||
p.full_name,
|
p.full_name,
|
||||||
@@ -540,6 +540,8 @@ SELECT
|
|||||||
p.updated_at
|
p.updated_at
|
||||||
FROM
|
FROM
|
||||||
iam_membership_profiles p
|
iam_membership_profiles p
|
||||||
|
INNER JOIN identities i
|
||||||
|
ON i.id = p.identity_id
|
||||||
WHERE
|
WHERE
|
||||||
p.%s
|
p.%s
|
||||||
AND p.organization_id = @organization_id
|
AND p.organization_id = @organization_id
|
||||||
|
|||||||
@@ -31,7 +31,6 @@ import (
|
|||||||
"go.gearno.de/kit/pg"
|
"go.gearno.de/kit/pg"
|
||||||
"go.probo.inc/probo/pkg/coredata"
|
"go.probo.inc/probo/pkg/coredata"
|
||||||
"go.probo.inc/probo/pkg/gid"
|
"go.probo.inc/probo/pkg/gid"
|
||||||
"go.probo.inc/probo/pkg/mail"
|
|
||||||
"go.probo.inc/probo/pkg/page"
|
"go.probo.inc/probo/pkg/page"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -227,12 +226,6 @@ func scimEventCSVRow(
|
|||||||
profilesByUserName map[string]scimProfileExportInfo,
|
profilesByUserName map[string]scimProfileExportInfo,
|
||||||
) []string {
|
) []string {
|
||||||
profile := profilesByUserName[strings.ToLower(event.UserName)]
|
profile := profilesByUserName[strings.ToLower(event.UserName)]
|
||||||
email := profile.email
|
|
||||||
fullName := profile.fullName
|
|
||||||
|
|
||||||
if email == "" {
|
|
||||||
email = scimEmailFromUserName(event.UserName)
|
|
||||||
}
|
|
||||||
|
|
||||||
return []string{
|
return []string{
|
||||||
organizationName,
|
organizationName,
|
||||||
@@ -241,8 +234,8 @@ func scimEventCSVRow(
|
|||||||
event.Method,
|
event.Method,
|
||||||
event.Path,
|
event.Path,
|
||||||
event.UserName,
|
event.UserName,
|
||||||
email,
|
profile.email,
|
||||||
fullName,
|
profile.fullName,
|
||||||
strconv.Itoa(event.StatusCode),
|
strconv.Itoa(event.StatusCode),
|
||||||
stringPtrValue(event.ErrorMessage),
|
stringPtrValue(event.ErrorMessage),
|
||||||
event.IPAddress.String(),
|
event.IPAddress.String(),
|
||||||
@@ -327,7 +320,7 @@ func loadSCIMProfileExportInfo(
|
|||||||
|
|
||||||
key := strings.ToLower(*profile.UserName)
|
key := strings.ToLower(*profile.UserName)
|
||||||
result[key] = scimProfileExportInfo{
|
result[key] = scimProfileExportInfo{
|
||||||
email: scimEmailFromUserName(*profile.UserName),
|
email: profile.EmailAddress.String(),
|
||||||
fullName: profileFullName(profile),
|
fullName: profileFullName(profile),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -366,19 +359,6 @@ func uniqueNonEmptyStrings(values []string) []string {
|
|||||||
return out
|
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 {
|
func profileFullName(profile *coredata.MembershipProfile) string {
|
||||||
if profile.FormattedName != nil && *profile.FormattedName != "" {
|
if profile.FormattedName != nil && *profile.FormattedName != "" {
|
||||||
return *profile.FormattedName
|
return *profile.FormattedName
|
||||||
|
|||||||
@@ -26,14 +26,6 @@ import (
|
|||||||
"github.com/stretchr/testify/assert"
|
"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) {
|
func TestUniqueNonEmptyStrings(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user