feat(authorization): add role assignment methods#1474
feat(authorization): add role assignment methods#1474swaroopAkkineniWorkos merged 3 commits intoENT-4372-base-authorization-branchfrom
Conversation
|
@greptile do a first pass review plz |
Greptile OverviewGreptile SummaryThis PR implements four role assignment methods for the WorkOS Node SDK's authorization module: Key Changes:
Testing: Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client
participant SDK as Authorization SDK
participant Serializer
participant API as WorkOS API
Note over Client,API: List Role Assignments
Client->>SDK: listRoleAssignments(options)
SDK->>API: GET /authorization/organization_memberships/{id}/role_assignments
API-->>SDK: RoleAssignmentListResponse (snake_case)
SDK->>Serializer: deserializeRoleAssignment()
Serializer-->>SDK: RoleAssignment (camelCase)
SDK-->>Client: RoleAssignmentList
Note over Client,API: Assign Role
Client->>SDK: assignRole(options)
SDK->>Serializer: serializeAssignRoleOptions()
Serializer-->>SDK: SerializedOptions (snake_case)
SDK->>API: POST /authorization/organization_memberships/{id}/role_assignments
API-->>SDK: RoleAssignmentResponse (snake_case)
SDK->>Serializer: deserializeRoleAssignment()
Serializer-->>SDK: RoleAssignment (camelCase)
SDK-->>Client: RoleAssignment
Note over Client,API: Remove Role (by resource)
Client->>SDK: removeRole(options)
SDK->>Serializer: serializeRemoveRoleOptions()
Serializer-->>SDK: Query params (snake_case)
SDK->>API: DELETE /authorization/organization_memberships/{id}/role_assignments?params
API-->>SDK: 204 No Content
SDK-->>Client: void
Note over Client,API: Remove Role Assignment (by ID)
Client->>SDK: removeRoleAssignment(options)
SDK->>API: DELETE /authorization/organization_memberships/{id}/role_assignments/{ra_id}
API-->>SDK: 204 No Content
SDK-->>Client: void
|
| organizationMembershipId: string; | ||
| roleSlug: string; | ||
| resourceId?: string; | ||
| resourceExternalId?: string; |
There was a problem hiding this comment.
I wonder if we should actually make resource argument this for all endpoints
resource: {id: string} | {external_id: string, type_slug: string}
Because we also have it for remove/assign role options
It could be a union of types
type ResourceOptions = {id: string} | {external_id: string, type_slug: string}[3:17 PM]export interface RemoveRoleOptions {
organizationMembershipId: string;
roleSlug: string;
resource: ResourceOptions
}
src/authorization/authorization.ts
Outdated
| await this.workos.delete(`/authorization/resources/${resourceId}`); | ||
| } | ||
|
|
||
| // phase 3 |
There was a problem hiding this comment.
| // phase 3 |
There was a problem hiding this comment.
removed
686a33c to
e1f0d82
Compare
| }, | ||
| "created_at": "2024-01-15T09:30:00.000Z", | ||
| "updated_at": "2024-01-15T09:30:00.000Z" | ||
| } No newline at end of file |
There was a problem hiding this comment.
updated
| const testOrgId = 'org_01HXYZ123ABC456DEF789ABC'; | ||
| const testResourceId = 'authz_resource_01HXYZ123ABC456DEF789ABC'; | ||
| const testOrgMembershipId = 'om_01HXYZ123ABC456DEF789ABC'; | ||
| const testRoleAssignmentId = 'ra_01HXYZ123ABC456DEF789ABC'; |
There was a problem hiding this comment.
nit the ids are prefixed with role_assignment_
There was a problem hiding this comment.
updated
1685f82
into
ENT-4372-base-authorization-branch
Adding these endpoints to the sdk #1471 ``` getResource() ~ GET /authorization/resources/{resource_id} createResource() ~ POST /authorization/resources updateResource() ~ PATCH /authorization/resources/{resource_id} deleteResource() ~ DELETE /authorization/resources/{resource_id} ``` #1473 ``` check() | POST /authorization/organization_memberships/{om_id}/check ``` #1472 ``` listResources() | GET /authorization/organizations/{org_id}/resources getResourceByExternalId() | GET /authorization/organizations/{org_id}/resources/{type}/{external_id} updateResourceByExternalId() | PATCH /authorization/organizations/{org_id}/resources/{type}/{external_id} deleteResourceByExternalId() | DELETE /authorization/organizations/{org_id}/resources/{type}/{external_id} ``` #1474 ``` listRoleAssignments() | GET /authorization/organization_memberships/{om_id}/role_assignments assignRole() | POST /authorization/organization_memberships/{om_id}/role_assignments removeRole() | DELETE /authorization/organization_memberships/{om_id}/role_assignments removeRoleAssignment() | DELETE /authorization/organization_memberships/{om_id}/role_assignments/{ra_id} ``` #1478 ``` listResourcesForMembership() | GET /authorization/organization_memberships/{om_id}/resources listMembershipsForResource() | GET /authorization/resources/{resource_id}/organization_memberships listMembershipsForResourceByExternalId() | GET /authorization/organizations/{org_id}/resources/{type}/{external_id}/organization_memberships ```
linear: https://linear.app/workos/issue/ENT-4372/sdk-updates
I decided to break up the work for ENT-4372 into a smaller pr's that we can be easily reviewed and merge them into ENT-4372-base-authorization-branch. Then we can have one final merge that merges ENT-4372-base-authorization-branch into the main.
desc: the goal of this pr is to implement the following endpoints in the node sdk.
listRoleAssignments() ~ https://github.com/workos/workos/blob/1bf21e074e2cde476d83660ca41e05853fa081b8/packages/api/src/authorization/authorization-role-assignments.controller.ts#L83
assignRole() ~ https://github.com/workos/workos/blob/1bf21e074e2cde476d83660ca41e05853fa081b8/packages/api/src/authorization/authorization-role-assignments.controller.ts#L140
removeRole() ~ https://github.com/workos/workos/blob/1bf21e074e2cde476d83660ca41e05853fa081b8/packages/api/src/authorization/authorization-role-assignments.controller.ts#L205
removeRoleAssignment() ~ https://github.com/workos/workos/blob/1bf21e074e2cde476d83660ca41e05853fa081b8/packages/api/src/authorization/authorization-role-assignments.controller.ts#L264