Skip to content

Conversation

@kendallstrautman
Copy link
Contributor

@kendallstrautman kendallstrautman commented Nov 26, 2025

Description

Adds the roles field to directory user and sso profile to support multiple roles.

Documentation

Does this require changes to the WorkOS Docs? E.g. the API Reference or code snippets need updates.

  • Yes

If yes, link a related docs PR and add a docs maintainer as a reviewer. Their approval is required.

@linear
Copy link

linear bot commented Nov 26, 2025

ENT-4659 Python

@kendallstrautman kendallstrautman marked this pull request as ready for review November 26, 2025 20:24
@kendallstrautman kendallstrautman requested a review from a team as a code owner November 26, 2025 20:24
@greptile-apps
Copy link
Contributor

greptile-apps bot commented Nov 26, 2025

Greptile Overview

Greptile Summary

Added the roles field to DirectoryUser and Profile models to support multiple role assignments, consistent with the existing pattern from OrganizationMembership.

  • Added roles: Optional[Sequence[InlineRole]] to DirectoryUser model in workos/types/directory_sync/directory_user.py:41
  • Added roles: Optional[Sequence[ProfileRole]] to Profile model in workos/types/sso/profile.py:25
  • Updated test fixtures to include the new roles field with sample data
  • Maintains backward compatibility by keeping the existing role field and making roles optional

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes follow established patterns from previous multi-role support (Add multiple roles support #473), are purely additive (new optional fields), maintain backward compatibility, include proper test coverage updates, and use consistent type definitions across the codebase
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
workos/types/sso/profile.py 5/5 Added roles field as optional sequence to support multiple roles in SSO profiles
workos/types/directory_sync/directory_user.py 5/5 Added roles field as optional sequence to support multiple roles in directory users
tests/utils/fixtures/mock_profile.py 5/5 Updated mock profile fixture to include roles field with test data
tests/utils/fixtures/mock_directory_user.py 5/5 Updated mock directory user fixture to include roles field with test data
tests/test_sso.py 5/5 Added roles=None to magic link profile test fixture for consistency

Sequence Diagram

sequenceDiagram
    participant API as WorkOS API
    participant SDK as Python SDK
    participant App as Application
    
    Note over API,App: SSO Profile with Multiple Roles
    App->>SDK: sso.get_profile_and_token(code)
    SDK->>API: POST /sso/token
    API-->>SDK: {profile: {..., role: {slug: "admin"}, roles: [{slug: "admin"}]}, access_token: "..."}
    SDK->>SDK: Parse Profile model (includes roles field)
    SDK-->>App: ProfileAndToken(profile, access_token)
    
    Note over API,App: Directory Sync User with Multiple Roles
    App->>SDK: directory_sync.get_user(user_id)
    SDK->>API: GET /directory_users/{user_id}
    API-->>SDK: {..., role: {slug: "member"}, roles: [{slug: "member"}]}
    SDK->>SDK: Parse DirectoryUser model (includes roles field)
    SDK-->>App: DirectoryUser with roles
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

Copy link
Contributor

@csrbarber csrbarber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants