resource memberships#1478
resource memberships#1478swaroopAkkineniWorkos merged 17 commits intoENT-4372-base-authorization-branchfrom
Conversation
7e6cf0e to
1740ace
Compare
|
@greptile review plz |
|
@greptile re-review plz. Look at the api implementation linked in the description as part of your review. The sdk should implement calling them |
Greptile OverviewGreptile SummaryImplements three new endpoints for querying relationships between organization memberships and resources:
Key Implementation Details:
Code Quality:
Confidence Score: 5/5
Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as SDK Client
participant SDK as Authorization Module
participant API as WorkOS API
Note over Client,API: listResourcesForMembership Flow
Client->>SDK: listResourcesForMembership(organizationMembershipId, permissionSlug, parent...)
SDK->>SDK: serializeListResourcesForMembershipOptions()
SDK->>API: GET /authorization/organization_memberships/{om_id}/resources
API-->>SDK: AuthorizationResourceListResponse
SDK->>SDK: deserializeAuthorizationResource() for each item
SDK-->>Client: AuthorizationResourceList
Note over Client,API: listMembershipsForResource Flow
Client->>SDK: listMembershipsForResource(resourceId, permissionSlug)
SDK->>SDK: serializeListMembershipsForResourceOptions()
SDK->>API: GET /authorization/resources/{resource_id}/organization_memberships
API-->>SDK: AuthorizationOrganizationMembershipListResponse
SDK->>SDK: deserializeAuthorizationOrganizationMembership() for each item
SDK-->>Client: AuthorizationOrganizationMembershipList
Note over Client,API: listMembershipsForResourceByExternalId Flow
Client->>SDK: listMembershipsForResourceByExternalId(orgId, typeSlug, externalId, permissionSlug)
SDK->>SDK: serializeListMembershipsForResourceOptions()
SDK->>API: GET /authorization/organizations/{org_id}/resources/{type}/{external_id}/organization_memberships
API-->>SDK: AuthorizationOrganizationMembershipListResponse
SDK->>SDK: deserializeAuthorizationOrganizationMembership() for each item
SDK-->>Client: AuthorizationOrganizationMembershipList
Last reviewed commit: 2eefd57 |
| }; | ||
| } | ||
|
|
||
| export interface AuthorizationOrganizationMembership { |
There was a problem hiding this comment.
I think we already have types for organization membership because it's used with the organization memberships API. It uses the same JSON type so we should probably use the same interface.
|
|
||
| export interface OrganizationMembershipList { | ||
| object: 'list'; | ||
| data: OrganizationMembership[]; |
There was a problem hiding this comment.
I think we'll need to create a base type because this interface includes a non-optional role field but it's not in the server response
vs
| // test this | ||
| async removeRole(options: RemoveRoleOptions): Promise<void> { | ||
| await this.workos.delete( | ||
| await this.workos.deleteWithBody( |
There was a problem hiding this comment.
changed to deleteWithBody because the delete role assignment API expects the identifying fields in the request body, and delete() doesn't send a body.
| AuthorizationOrganizationMembershipResponse, | ||
| } from '../interfaces/organization-membership-list.interface'; | ||
|
|
||
| export const deserializeAuthorizationOrganizationMembership = ( |
There was a problem hiding this comment.
This should be in the userland package for base organization membership
| } | ||
|
|
||
| export interface AuthorizationOrganizationMembershipResponse extends BaseOrganizationMembershipResponse { | ||
| organization_name?: string; |
There was a problem hiding this comment.
I think we should remove this because authz doesn't use it
| options: ListResourcesForMembershipOptions, | ||
| ): SerializedListResourcesForMembershipOptions => ({ | ||
| permission_slug: options.permissionSlug, | ||
| ...(options.limit !== undefined && { limit: options.limit }), |
There was a problem hiding this comment.
Is there a common helper for the pagination params?
| } | ||
|
|
||
| export interface OrganizationMembershipResponse extends BaseOrganizationMembershipResponse { | ||
| organization_name: string; |
There was a problem hiding this comment.
this should be in the base
bfc197d
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.
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
listResourcesForMembership() ~ https://github.com/workos/workos/blob/main/packages/api/src/authorization/authorization.controller.ts#L221
listOrganizationMembershipsForResource() ~ https://github.com/workos/workos/blob/main/packages/api/src/authorization-resources/authorization-resources.controller.ts#L411
listOrganizationMembershipsForResourceByExternalId() ~ https://github.com/workos/workos/blob/main/packages/api/src/authorization-resources/authorization-resources-by-external-id.controller.ts#L135