Sync title in SCIM and Gbridge

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-02-19 16:11:59 +04:00
parent a9e4e991b3
commit c3a65c123a
5 changed files with 79 additions and 11 deletions

View File

@@ -112,6 +112,9 @@ func (s *Bridge) Run(ctx context.Context) (created, updated, deleted, deactivate
if existingSCIM.DisplayName != pu.DisplayName {
needsUpdate = true
}
if existingSCIM.Title != pu.Title {
needsUpdate = true
}
if needsUpdate {
if !s.dryRun {

View File

@@ -39,6 +39,7 @@ type (
GivenName string `json:"-"`
FamilyName string `json:"-"`
Active bool `json:"active"`
Title string `json:"title"`
}
Users []User
@@ -130,6 +131,7 @@ func (c *Client) CreateUser(ctx context.Context, user *User) error {
"primary": true,
},
},
"title": user.Title,
}
body, err := json.Marshal(payload)
@@ -178,6 +180,7 @@ func (c *Client) UpdateUser(ctx context.Context, userID string, user *User) erro
"primary": true,
},
},
"title": user.Title,
}
body, err := json.Marshal(payload)

View File

@@ -18,6 +18,7 @@ package googleworkspace
import (
"context"
"encoding/json"
"fmt"
"net/http"
"strings"
@@ -82,6 +83,36 @@ func (p *Provider) ListUsers(ctx context.Context) (scimclient.Users, error) {
continue
}
var title string
if u.Organizations == nil {
title = ""
}
data, err := json.Marshal(u.Organizations)
if err != nil {
title = ""
}
var orgs []admin.UserOrganization
if err := json.Unmarshal(data, &orgs); err != nil {
title = ""
}
// Prefer the primary organization's title
for _, org := range orgs {
if org.Primary && org.Title != "" {
title = org.Title
}
}
// Fall back to the first organization with a title
for _, org := range orgs {
if org.Title != "" {
title = org.Title
}
}
allUsers = append(
allUsers,
scimclient.User{
@@ -90,6 +121,7 @@ func (p *Provider) ListUsers(ctx context.Context) (scimclient.Users, error) {
GivenName: u.Name.GivenName,
FamilyName: u.Name.FamilyName,
Active: !u.Suspended && !u.Archived,
Title: title,
},
)
}