Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 15 additions & 4 deletions apps/docs/content/docs/search/people.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ An organization admin can open **People → Directory sync** and connect one aut

| Source | How to connect |
| --- | --- |
| **SCIM provisioning** | Enable your organization's [SCIM provisioning connection](/platform/enterprise/scim), then select **SCIM provisioning** in People. Map core `title`, enterprise `department`, and enterprise `manager.value`. The manager value is the manager's SCIM resource ID in the same connection. |
| **Okta** | Enter your Okta organization domain and an [API token](https://developer.okta.com/docs/guides/create-an-api-token/main/) that can read all intended users. Sim reads active users and resolves managers using the Okta user ID in `profile.managerId`. |
| **SCIM provisioning** | Enable your organization's [SCIM provisioning connection](/platform/enterprise/scim), then select **SCIM provisioning** in People. Map core `title`, enterprise `department`, `employeeNumber`, and `manager.value`. The manager value can name the manager by SCIM resource ID or any key in [Finding managers](#finding-managers). |
| **Okta** | Enter your Okta organization domain and an [API token](https://developer.okta.com/docs/guides/create-an-api-token/main/) that can read all intended users. Sim reads active users and finds each manager from `profile.managerId`, as described in [Finding managers](#finding-managers). |
| **Microsoft Entra ID** | [Register an application](https://learn.microsoft.com/en-us/entra/identity-platform/quickstart-register-app) in your Microsoft commercial-cloud tenant, grant the Microsoft Graph **application** permission `User.Read.All`, and obtain admin consent. Enter the tenant ID, application (client) ID, and client secret **value**. Sim obtains an access token when a sync needs to read Microsoft Graph and uses direct reports to build the chart. |

Select **Connect and sync** to start the first refresh. Sim stores the Okta token or Entra client secret encrypted. Use **Update credentials** and **Save and sync** to rotate them for the same directory.
Expand All @@ -40,6 +40,17 @@ Okta and Entra can include colleagues who have never signed in to Sim. Directory

The directory controls the name, title, department, and reporting line of the people it supplies. Okta and Entra also supply location. SCIM uses an address marked as a work address when one is available. Correct these fields in the source. Removing a manager upstream clears the source reporting line. An active person whose manager is absent from the directory appears without that manager. When an entry leaves the source, its directory-only profile disappears. An active Sim member can still appear with their manually recorded profile.

### Finding managers [#finding-managers]

A person's manager value can name the manager in any of four ways. Sim tries them in this order and uses the first that matches:

1. The manager's account ID in the source: the Okta user ID, Entra object ID, or SCIM resource ID.
2. Their employee number: Okta `employeeNumber`, Entra `employeeId`, or SCIM enterprise `employeeNumber`. HR systems such as Workday often fill `managerId` this way.
3. Their email.
4. Their username.

Emails and usernames match regardless of letter case. If the first matching key belongs to more than one person, such as two people with one employee number, Sim links no manager and shows a warning.

### Review sync warnings [#review-sync-warnings]

A sync publishes every account it can read. An account with a problem gets a warning instead of failing the sync, and Sim never changes your directory. Many warnings, such as service accounts, need no action. Fix an account at the source and its warning clears after the next sync.
Expand All @@ -53,11 +64,11 @@ A shared email is claimed when one of the accounts sharing it uses it as its use
| **Resolved automatically** | Several accounts share a claimed email. | Publishes the claiming account and leaves the others out. | Nothing. To include the others, give each its own email. |
| **Frozen since last sync** | An account in the chart has a missing or invalid email, or an unclaimed shared email. | Keeps its last published details, including its manager, until fixed. | Give it a valid, unique email of up to 320 characters, or claim the shared email with its username. |
| **Skipped** | A new account has a missing, invalid, or unclaimed shared email, or another account took its previous email. | Leaves it out. | Nothing, if it doesn't belong in the chart. Otherwise give it a valid, unique email. |
| **Changed** | A title, department, location, or manager isn't text, or managers form a loop, including someone managing themselves. | Publishes the account. The field keeps its last value, or stays empty for someone new. Everyone in a loop loses their manager. | Correct the field or break the loop. |
| **Changed** | A title, department, location, or manager isn't text, a manager value matches more than one person, or managers form a loop, including someone managing themselves. | Publishes the account. The field keeps its last value, or stays empty for someone new. An account whose manager matches several people, and everyone in a loop, has no manager. | Correct the field, make the manager value unique, or break the loop. |

The username is the Okta `login`, the Entra user principal name, or the SCIM `userName`. Emails and usernames match regardless of letter case and surrounding spaces. An empty Okta `email` or Entra `mail` falls back to the username. Names, titles, departments, and locations over 2,048 characters are shortened without a warning.

A manager who isn't in the chart is dropped without a warning, and their reports appear at the top until the manager is published.
A manager value that matches nobody in the chart, such as a departed manager, is dropped without a warning, and their reports appear at the top until the manager is published.

### Check a sync or recover from a failure

Expand Down
15 changes: 11 additions & 4 deletions apps/sim/ee/scim/lib/repository/people-profiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,13 @@ function projectedPeople(
>`left(${scimUser.attributes} #>> '{enterprise,manager,value}',${UNRESOLVED_MANAGER_LENGTH})`,
login: sql<string>`left(${scimUser.userName},${DIRECTORY_TEXT_MAX_LENGTH})`,
titleUnreadable: memberOnly ? sql<boolean>`false` : extraAttributeUnreadable('title'),
// An identifier is never shortened: one over the limit cannot match anyone, so it is left out.
employeeNumber: memberOnly
? sql<null>`null`
: sql<
string | null
>`(select value from btrim(${scimUser.attributes} #>> '{enterprise,employeeNumber}') value
where char_length(value) between 1 and ${DIRECTORY_TEXT_MAX_LENGTH})`,
})
.from(scimUser)
.innerJoin(user, eq(user.id, scimUser.userId))
Expand Down Expand Up @@ -158,19 +165,19 @@ export async function stageScimDirectory(
)
const source = projectedPeople(tx, organizationId, expectedConnectionId, false)
const [result] = await tx.execute<{ complete: boolean; total: string }>(sql`
WITH source(external_id,email,name,location,title,timezone,department,manager_external_id,login,title_unreadable) AS (${source}),
WITH source(external_id,email,name,location,title,timezone,department,manager_external_id,login,title_unreadable,employee_number) AS (${source}),
zones AS (SELECT lower(name) AS zone_key, min(name) AS zone_name FROM pg_timezone_names GROUP BY 1),
checked AS (
SELECT source.*,
coalesce(char_length(email) <= 320 AND email ~ ${z.regexes.email.source}, false) AS usable
FROM source
),
staged AS (
INSERT INTO ${peopleDirectoryStage} (organization_id,run_id,external_id,proposed_id,email,login,issue,issue_fields,
name,title,department,location,timezone,manager_external_id,reports_complete)
INSERT INTO ${peopleDirectoryStage} (organization_id,run_id,external_id,proposed_id,email,login,employee_number,
issue,issue_fields,name,title,department,location,timezone,manager_external_id,reports_complete)
SELECT ${organizationId},${runId},external_id,gen_random_uuid()::text,
CASE WHEN usable THEN email ELSE nullif(left(email,320),'') END,
nullif(btrim(login),''),
nullif(btrim(login),''),employee_number,
CASE WHEN NOT usable THEN 'invalid_email' WHEN title_unreadable THEN 'field_cleared' END,
CASE WHEN usable AND title_unreadable THEN ARRAY['title'] END,
coalesce(nullif(btrim(name),''),nullif(email,''),external_id),nullif(title,''),
Expand Down
10 changes: 9 additions & 1 deletion apps/sim/lib/api/contracts/people-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,13 @@ export const PEOPLE_SYNC_ISSUE_PREVIEW_SIZE = 3

/** One account the last publish skipped, kept or changed, and why. */
const syncIssue = z.object({
kind: z.enum(['duplicate_email', 'invalid_email', 'field_cleared', 'manager_cleared']),
kind: z.enum([
'duplicate_email',
'invalid_email',
'field_cleared',
'manager_cleared',
'manager_ambiguous',
]),
externalId: z.string(),
/** The address as the source gave it; missing or malformed for `invalid_email`. */
email: z.string().nullable(),
Expand All @@ -93,6 +99,8 @@ const syncIssue = z.object({
fields: z.array(directoryIssueFieldSchema),
/** How a shared email was settled; null for every other kind. */
resolution: z.enum(['auto', 'needs_review']).nullable(),
/** The manager reference several accounts match, for `manager_ambiguous`; null for every other kind. */
reference: z.string().nullable(),
/** The chart still shows this account's last published details. */
keptPrevious: z.boolean(),
/** The first publish that recorded this issue for the account. */
Expand Down
6 changes: 5 additions & 1 deletion apps/sim/lib/people/provider-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ const oktaPage = z
state: z.unknown(),
countryCode: z.unknown(),
managerId: z.unknown(),
employeeNumber: optionalText.catch(null),
timezone: optionalText.catch(null),
// Okta has no standard start date; these are the custom attribute names HR feeds use.
startDate: optionalText.catch(null),
Expand All @@ -70,6 +71,7 @@ const entraPage = z.object({
department: z.unknown(),
officeLocation: z.unknown(),
employeeHireDate: optionalText.catch(null),
employeeId: optionalText.catch(null),
manager: z.unknown(),
})
)
Expand Down Expand Up @@ -111,7 +113,7 @@ function usersEndpoint(input: DirectoryAccess, appOnly: boolean): URL {
const url = new URL('https://graph.microsoft.com/v1.0/users')
url.searchParams.set(
'$select',
'id,displayName,mail,userPrincipalName,accountEnabled,jobTitle,department,officeLocation,employeeHireDate'
'id,displayName,mail,userPrincipalName,accountEnabled,jobTitle,department,officeLocation,employeeHireDate,employeeId'
)
if (appOnly) url.searchParams.set('$filter', 'accountEnabled eq true')
else url.searchParams.set('$expand', 'manager($select=id)')
Expand Down Expand Up @@ -184,6 +186,7 @@ function parseDirectoryPage(
name: person.displayName || mail || person.userPrincipalName || person.id,
email: accountEmail(person.mail, person.userPrincipalName),
login: person.userPrincipalName || null,
employeeNumber: person.employeeId || null,
title: read(person.jobTitle, displayText, 'title') || null,
department: read(person.department, displayText, 'department') || null,
location: read(person.officeLocation, displayText, 'location') || null,
Expand Down Expand Up @@ -217,6 +220,7 @@ function parseDirectoryPage(
id,
email: accountEmail(profile.email, profile.login),
login: profile.login || null,
employeeNumber: profile.employeeNumber || null,
title: read(profile.title, displayText, 'title') || null,
department: read(profile.department, displayText, 'department') || null,
location: cleared.includes('location')
Expand Down
5 changes: 5 additions & 0 deletions apps/sim/lib/people/sync/issue-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ export function describeIssue(
outcome: category === 'kept' ? 'Kept with details from the last sync' : 'Left out',
}
case 'changed':
if (issue.kind === 'manager_ambiguous')
return {
problem: `Manager ${issue.reference ?? ''} matches more than one account`,
outcome: 'No manager linked',
}
return issue.kind === 'manager_cleared'
? { problem: 'Manager is part of a reporting loop', outcome: 'Manager removed' }
: {
Expand Down
54 changes: 54 additions & 0 deletions apps/sim/lib/people/sync/issues.integration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ interface OktaAccount {
title?: unknown
department?: string
managerId?: string
employeeNumber?: string
}

beforeAll(async () => {
Expand Down Expand Up @@ -281,6 +282,59 @@ it('publishes an account whose field is not text, keeping the last good value fo
expect(status.issueCounts.changed).toBe(2)
})

it('links a manager the directory names by employee number, email or login, in any case', async () => {
await sync([
{ id: 'boss', email: email('boss'), login: 'Boss.Admin', employeeNumber: 'W100' },
{ id: 'by-id', email: email('by-id'), managerId: 'boss' },
{ id: 'by-number', email: email('by-number'), managerId: 'W100' },
{ id: 'by-email', email: email('by-email'), managerId: ' BOSS@example.test ' },
{ id: 'by-login', email: email('by-login'), managerId: 'boss.admin' },
])
const published = await chart()
for (const id of ['by-id', 'by-number', 'by-email', 'by-login'])
expect(published.get(id)?.managerExternalId).toBe('boss')
expect(await issues()).toEqual([])
})

it('links a manager reference by the first key that matches: Okta ID, then employee number, then email, then login', async () => {
await sync([
{ id: 'lead', email: email('lead') },
{ id: 'other', email: email('other'), employeeNumber: 'lead' },
{ id: 'report', email: email('report'), managerId: 'lead' },
{ id: 'numbered', email: email('numbered'), employeeNumber: 'chief' },
{ id: 'named', email: email('named'), login: 'chief' },
{ id: 'staff', email: email('staff'), managerId: 'chief' },
{ id: 'mailed', email: email('head') },
{ id: 'logged', email: email('logged'), login: email('head') },
{ id: 'crew', email: email('crew'), managerId: email('head') },
])
const published = await chart()
expect(published.get('report')?.managerExternalId).toBe('lead')
expect(published.get('staff')?.managerExternalId).toBe('numbered')
expect(published.get('crew')?.managerExternalId).toBe('mailed')
expect(await issues()).toEqual([])
})

it('warns about a manager reference several accounts share, and silently drops one that names nobody', async () => {
await sync([
{ id: 'twin-a', email: email('twin-a'), employeeNumber: 'E7' },
{ id: 'twin-b', email: email('twin-b'), employeeNumber: 'E7' },
{ id: 'shared', email: email('shared'), managerId: 'E7' },
{ id: 'departed', email: email('departed'), managerId: 'someone-deactivated' },
])
const published = await chart()
expect(published.get('shared')?.managerExternalId).toBeNull()
expect(published.get('departed')?.managerExternalId).toBeNull()
expect(await issues()).toEqual([
expect.objectContaining({
kind: 'manager_ambiguous',
externalId: 'shared',
reference: 'E7',
category: 'changed',
}),
])
})

it('leaves an unchanged issue row unwritten on the next publish', async () => {
const accounts = [
{ id: 'a', login: 'no address' },
Expand Down
Loading
Loading