Skip to content

Conversation

@kendallstrautman
Copy link
Contributor

Description

This PR adds the roles property to directory user and SSO profile entities to support multiple roles. It also adjusts the serialization of role and roles on the organization membership to match the RoleResponse.

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 25, 2025

ENT-4666 PHP

Comment on lines +9 to +11
*
* @property RoleResponse|null $role
* @property array<RoleResponse>|null $roles
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The other properties need to be added here but didn't want to conflate this PR.

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

greptile-apps bot commented Nov 26, 2025

Greptile Overview

Greptile Summary

Added support for multiple roles (roles property) to directory users and SSO profiles, and standardized role serialization across directory users, SSO profiles, and organization memberships to use RoleResponse objects.

  • Added roles property to DirectoryUser and Profile classes to support multiple roles per user
  • Implemented constructFromResponse method in DirectoryUser and OrganizationMembership to properly serialize role and roles as RoleResponse objects
  • Updated test fixtures across DirectorySyncTest, SSOTest, and UserManagementTest to include role/roles data
  • Changed test assertions from assertSame to assertEquals to properly compare objects by value rather than identity

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk
  • The changes follow established patterns in the codebase, are well-tested with comprehensive test coverage, and implement straightforward property additions with proper serialization
  • No files require special attention

Important Files Changed

File Analysis

Filename Score Overview
lib/Resource/DirectoryUser.php 5/5 Added role and roles properties with proper serialization to RoleResponse objects
lib/Resource/Profile.php 5/5 Added roles property to support multiple roles, consistent with existing role pattern
lib/Resource/OrganizationMembership.php 5/5 Added constructFromResponse to properly serialize role and roles as RoleResponse objects
tests/WorkOS/DirectorySyncTest.php 5/5 Updated fixtures and assertions to include role/roles data and changed to assertEquals for object comparison
tests/WorkOS/SSOTest.php 5/5 Updated SSO profile fixtures to include roles array for testing multiple role support
tests/WorkOS/UserManagementTest.php 5/5 Updated organization membership fixtures and changed assertions from assertSame to assertEquals for RoleResponse objects

Sequence Diagram

sequenceDiagram
    participant API as WorkOS API
    participant SDK as PHP SDK
    participant Resource as Resource Classes
    participant App as Application Code

    Note over API,App: API Response Processing Flow

    API->>SDK: Return JSON with role/roles data
    Note right of API: {role: {slug: "admin"},<br/>roles: [{slug: "admin"}]}
    
    SDK->>Resource: constructFromResponse(response)
    Resource->>Resource: parent::constructFromResponse(response)
    Note right of Resource: Sets raw values from response
    
    Resource->>Resource: Check isset(response["role"])
    Resource->>Resource: Create new RoleResponse(slug)
    Note right of Resource: Converts role array to RoleResponse object
    
    Resource->>Resource: Check isset(response["roles"])
    loop For each role in roles array
        Resource->>Resource: Create new RoleResponse(slug)
    end
    Note right of Resource: Converts roles array to RoleResponse[]
    
    Resource->>SDK: Return resource instance
    SDK->>App: DirectoryUser/Profile/OrganizationMembership
    Note right of App: role and roles are now RoleResponse objects
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.

6 files reviewed, no comments

Edit Code Review Agent Settings | Greptile

@kendallstrautman kendallstrautman merged commit 2aab862 into main Dec 3, 2025
5 checks passed
@kendallstrautman kendallstrautman deleted the feature/ent-4666-php branch December 3, 2025 00:15
@greptile-apps greptile-apps bot mentioned this pull request Dec 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants