Select only SCIM export profile columns by user name
The batch loader no longer scans into MembershipProfile with placeholder email and organization name columns from dropped identity and organization joins. Signed-off-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: Bryan FRIMIN <bryan@frimin.fr>
This commit is contained in:
@@ -495,7 +495,25 @@ WHERE
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *MembershipProfiles) LoadByOrganizationIDAndUserNames(
|
type (
|
||||||
|
MembershipProfileByUserNameRow struct {
|
||||||
|
UserName *string `db:"user_name"`
|
||||||
|
FullName string `db:"full_name"`
|
||||||
|
FormattedName *string `db:"formatted_name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
MembershipProfileByUserNameRows []*MembershipProfileByUserNameRow
|
||||||
|
)
|
||||||
|
|
||||||
|
func (p *MembershipProfileByUserNameRow) DisplayName() string {
|
||||||
|
if p.FormattedName != nil && *p.FormattedName != "" {
|
||||||
|
return *p.FormattedName
|
||||||
|
}
|
||||||
|
|
||||||
|
return p.FullName
|
||||||
|
}
|
||||||
|
|
||||||
|
func (rows *MembershipProfileByUserNameRows) LoadByOrganizationIDAndUserNames(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
conn pg.Querier,
|
conn pg.Querier,
|
||||||
scope Scoper,
|
scope Scoper,
|
||||||
@@ -504,40 +522,9 @@ func (p *MembershipProfiles) LoadByOrganizationIDAndUserNames(
|
|||||||
) error {
|
) error {
|
||||||
q := `
|
q := `
|
||||||
SELECT
|
SELECT
|
||||||
p.id,
|
|
||||||
p.identity_id,
|
|
||||||
p.organization_id,
|
|
||||||
'' AS email_address,
|
|
||||||
p.source,
|
|
||||||
p.state,
|
|
||||||
p.full_name,
|
|
||||||
p.kind,
|
|
||||||
p.additional_email_addresses,
|
|
||||||
p.position,
|
|
||||||
p.contract_start_date,
|
|
||||||
p.contract_end_date,
|
|
||||||
'' AS organization_name,
|
|
||||||
p.user_name,
|
p.user_name,
|
||||||
p.external_id,
|
p.full_name,
|
||||||
p.nickname,
|
p.formatted_name
|
||||||
p.locale,
|
|
||||||
p.timezone,
|
|
||||||
p.profile_url,
|
|
||||||
p.preferred_language,
|
|
||||||
p.given_name,
|
|
||||||
p.family_name,
|
|
||||||
p.formatted_name,
|
|
||||||
p.middle_name,
|
|
||||||
p.honorific_prefix,
|
|
||||||
p.honorific_suffix,
|
|
||||||
p.employee_number,
|
|
||||||
p.department,
|
|
||||||
p.cost_center,
|
|
||||||
p.enterprise_organization,
|
|
||||||
p.division,
|
|
||||||
p.manager_value,
|
|
||||||
p.created_at,
|
|
||||||
p.updated_at
|
|
||||||
FROM
|
FROM
|
||||||
iam_membership_profiles p
|
iam_membership_profiles p
|
||||||
WHERE
|
WHERE
|
||||||
@@ -554,17 +541,17 @@ WHERE
|
|||||||
}
|
}
|
||||||
maps.Copy(args, scope.SQLArguments())
|
maps.Copy(args, scope.SQLArguments())
|
||||||
|
|
||||||
rows, err := conn.Query(ctx, q, args)
|
rowsResult, err := conn.Query(ctx, q, args)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot query profiles by user names: %w", err)
|
return fmt.Errorf("cannot query profiles by user names: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
profiles, err := pgx.CollectRows(rows, pgx.RowToAddrOfStructByName[MembershipProfile])
|
profiles, err := pgx.CollectRows(rowsResult, pgx.RowToAddrOfStructByName[MembershipProfileByUserNameRow])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("cannot collect profiles by user names: %w", err)
|
return fmt.Errorf("cannot collect profiles by user names: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
*p = profiles
|
*rows = profiles
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -312,7 +312,7 @@ func loadSCIMProfileExportInfo(
|
|||||||
return map[string]scimProfileExportInfo{}, nil
|
return map[string]scimProfileExportInfo{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var profiles coredata.MembershipProfiles
|
var profiles coredata.MembershipProfileByUserNameRows
|
||||||
if err := profiles.LoadByOrganizationIDAndUserNames(
|
if err := profiles.LoadByOrganizationIDAndUserNames(
|
||||||
ctx,
|
ctx,
|
||||||
conn,
|
conn,
|
||||||
@@ -332,7 +332,7 @@ func loadSCIMProfileExportInfo(
|
|||||||
key := strings.ToLower(*profile.UserName)
|
key := strings.ToLower(*profile.UserName)
|
||||||
result[key] = scimProfileExportInfo{
|
result[key] = scimProfileExportInfo{
|
||||||
email: scimEmailFromUserName(*profile.UserName),
|
email: scimEmailFromUserName(*profile.UserName),
|
||||||
fullName: profileFullName(profile),
|
fullName: profile.DisplayName(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -383,14 +383,6 @@ func scimEmailFromUserName(userName string) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func profileFullName(profile *coredata.MembershipProfile) string {
|
|
||||||
if profile.FormattedName != nil && *profile.FormattedName != "" {
|
|
||||||
return *profile.FormattedName
|
|
||||||
}
|
|
||||||
|
|
||||||
return profile.FullName
|
|
||||||
}
|
|
||||||
|
|
||||||
func stringPtrValue(value *string) string {
|
func stringPtrValue(value *string) string {
|
||||||
if value == nil {
|
if value == nil {
|
||||||
return ""
|
return ""
|
||||||
|
|||||||
Reference in New Issue
Block a user