-
Notifications
You must be signed in to change notification settings - Fork 46
feat(authorization): add role assignment methods #1474
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
swaroopAkkineniWorkos
wants to merge
24
commits into
ENT-4372-base-authorization-branch
Choose a base branch
from
ENt-4372-Role-Assignment
base: ENT-4372-base-authorization-branch
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
310eeb1
Authorization Resources endpoints for Internal ID
swaroopAkkineniWorkos 685643c
lol
swaroopAkkineniWorkos 107fc6c
Merge branch 'main' into ENT-4372-Internal-ID
swaroopAkkineniWorkos ea2628e
lol
swaroopAkkineniWorkos 543b121
lol
swaroopAkkineniWorkos c2734e8
moar
swaroopAkkineniWorkos 5037673
lol
swaroopAkkineniWorkos ca6f2d1
lol
swaroopAkkineniWorkos dfdd37d
lol
swaroopAkkineniWorkos 43a0765
lol
swaroopAkkineniWorkos b61be8a
pretty
swaroopAkkineniWorkos 0b65b75
moar
swaroopAkkineniWorkos 9281d60
remove
swaroopAkkineniWorkos 24f6758
moar
swaroopAkkineniWorkos ea41192
moar
swaroopAkkineniWorkos 6fb444c
moar
swaroopAkkineniWorkos 5689bee
moar
swaroopAkkineniWorkos 1cb2d25
Merge branch 'main' into ENT-4372-Internal-ID
swaroopAkkineniWorkos db6530c
review
swaroopAkkineniWorkos 9288c1a
feat(authorization): add role assignment methods
swaroopAkkineniWorkos 79dfc40
moar
swaroopAkkineniWorkos 096a178
moar
swaroopAkkineniWorkos 8203a5a
moar
swaroopAkkineniWorkos 686a33c
moar
swaroopAkkineniWorkos File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| { | ||
| "object": "authorization_resource", | ||
| "id": "authz_resource_01HXYZ123ABC456DEF789ABC", | ||
| "external_id": "doc-456", | ||
| "name": "Q4 Budget Report", | ||
| "description": "Financial report for Q4 2025", | ||
| "resource_type_slug": "document", | ||
| "organization_id": "org_01HXYZ123ABC456DEF789ABC", | ||
| "parent_resource_id": "authz_resource_01HXYZ123ABC456DEF789XYZ", | ||
| "created_at": "2024-01-15T09:30:00.000Z", | ||
| "updated_at": "2024-01-15T09:30:00.000Z" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "object": "list", | ||
| "data": [ | ||
| { | ||
| "object": "role_assignment", | ||
| "id": "ra_01HXYZ123ABC456DEF789ABC", | ||
| "role": { | ||
| "slug": "editor" | ||
| }, | ||
| "resource": { | ||
| "id": "resource_01HXYZ123ABC456DEF789XYZ", | ||
| "external_id": "doc-123", | ||
| "resource_type_slug": "document" | ||
| }, | ||
| "created_at": "2024-01-15T09:30:00.000Z", | ||
| "updated_at": "2024-01-15T09:30:00.000Z" | ||
| } | ||
| ], | ||
| "list_metadata": { | ||
| "before": null, | ||
| "after": "ra_01HXYZ123ABC456DEF789ABC" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| { | ||
| "object": "role_assignment", | ||
| "id": "ra_01HXYZ123ABC456DEF789ABC", | ||
| "role": { | ||
| "slug": "editor" | ||
| }, | ||
| "resource": { | ||
| "id": "resource_01HXYZ123ABC456DEF789XYZ", | ||
| "external_id": "doc-123", | ||
| "resource_type_slug": "document" | ||
| }, | ||
| "created_at": "2024-01-15T09:30:00.000Z", | ||
| "updated_at": "2024-01-15T09:30:00.000Z" | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/authorization/interfaces/assign-role-options.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| export interface AssignRoleOptions { | ||
| organizationMembershipId: string; | ||
| roleSlug: string; | ||
| resourceId?: string; | ||
| resourceExternalId?: string; | ||
| resourceTypeSlug?: string; | ||
| } | ||
|
|
||
| export interface SerializedAssignRoleOptions { | ||
| role_slug: string; | ||
| resource_id?: string; | ||
| resource_external_id?: string; | ||
| resource_type_slug?: string; | ||
| } |
54 changes: 54 additions & 0 deletions
54
src/authorization/interfaces/authorization-resource.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| export interface AuthorizationResource { | ||
| object: 'authorization_resource'; | ||
| id: string; | ||
| externalId: string; | ||
| name: string; | ||
| description: string | null; | ||
| resourceTypeSlug: string; | ||
| organizationId: string; | ||
| parentResourceId: string | null; | ||
| createdAt: string; | ||
| updatedAt: string; | ||
| } | ||
|
|
||
| export interface AuthorizationResourceResponse { | ||
| object: 'authorization_resource'; | ||
| id: string; | ||
| external_id: string; | ||
| name: string; | ||
| description: string | null; | ||
| resource_type_slug: string; | ||
| organization_id: string; | ||
| parent_resource_id: string | null; | ||
| created_at: string; | ||
| updated_at: string; | ||
| } | ||
|
|
||
| export interface CreateAuthorizationResourceOptions { | ||
| externalId: string; | ||
| name: string; | ||
| description?: string | null; | ||
| resourceTypeSlug: string; | ||
| organizationId: string; | ||
| parentResourceId?: string | null; | ||
| } | ||
|
|
||
| export interface SerializedCreateAuthorizationResourceOptions { | ||
| external_id: string; | ||
| name: string; | ||
| description?: string | null; | ||
| resource_type_slug: string; | ||
| organization_id: string; | ||
| parent_resource_id?: string | null; | ||
| } | ||
|
|
||
| export interface UpdateAuthorizationResourceOptions { | ||
| resourceId: string; | ||
| name?: string; | ||
| description?: string | null; | ||
| } | ||
|
|
||
| export interface SerializedUpdateAuthorizationResourceOptions { | ||
| name?: string; | ||
| description?: string | null; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 4 additions & 0 deletions
4
src/authorization/interfaces/list-role-assignments-options.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| import { PaginationOptions } from '../../common/interfaces/pagination-options.interface'; | ||
| export interface ListRoleAssignmentsOptions extends PaginationOptions { | ||
| organizationMembershipId: string; | ||
| } |
4 changes: 4 additions & 0 deletions
4
src/authorization/interfaces/remove-role-assignment-options.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| export interface RemoveRoleAssignmentOptions { | ||
| organizationMembershipId: string; | ||
| roleAssignmentId: string; | ||
| } |
14 changes: 14 additions & 0 deletions
14
src/authorization/interfaces/remove-role-options.interface.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| export interface RemoveRoleOptions { | ||
| organizationMembershipId: string; | ||
| roleSlug: string; | ||
| resourceId?: string; | ||
| resourceExternalId?: string; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wonder if we should actually make resource argument this for all endpoints Because we also have it for remove/assign role options It could be a union of types |
||
| resourceTypeSlug?: string; | ||
| } | ||
|
|
||
| export interface SerializedRemoveRoleOptions { | ||
| role_slug: string; | ||
| resource_id?: string; | ||
| resource_external_id?: string; | ||
| resource_type_slug?: string; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| export interface RoleAssignmentRole { | ||
| slug: string; | ||
| } | ||
|
|
||
| export interface RoleAssignmentResource { | ||
| id: string; | ||
| externalId: string; | ||
| resourceTypeSlug: string; | ||
| } | ||
|
|
||
| export interface RoleAssignmentResourceResponse { | ||
| id: string; | ||
| external_id: string; | ||
| resource_type_slug: string; | ||
| } | ||
|
|
||
| export interface RoleAssignment { | ||
| object: 'role_assignment'; | ||
| id: string; | ||
| role: RoleAssignmentRole; | ||
| resource: RoleAssignmentResource; | ||
| createdAt: string; | ||
| updatedAt: string; | ||
| } | ||
|
|
||
| export interface RoleAssignmentResponse { | ||
| object: 'role_assignment'; | ||
| id: string; | ||
| role: RoleAssignmentRole; // Note: role.slug is already snake_case compatible | ||
| resource: RoleAssignmentResourceResponse; | ||
| created_at: string; | ||
| updated_at: string; | ||
| } | ||
|
|
||
| export interface RoleAssignmentList { | ||
| object: 'list'; | ||
| data: RoleAssignment[]; | ||
| listMetadata: { | ||
| before: string | null; | ||
| after: string | null; | ||
| }; | ||
| } | ||
|
|
||
| export interface RoleAssignmentListResponse { | ||
| object: 'list'; | ||
| data: RoleAssignmentResponse[]; | ||
| list_metadata: { | ||
| before: string | null; | ||
| after: string | null; | ||
| }; | ||
| } |
17 changes: 17 additions & 0 deletions
17
src/authorization/serializers/assign-role-options.serializer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,17 @@ | ||
| import { | ||
| AssignRoleOptions, | ||
| SerializedAssignRoleOptions, | ||
| } from '../interfaces/assign-role-options.interface'; | ||
|
|
||
| export const serializeAssignRoleOptions = ( | ||
| options: AssignRoleOptions, | ||
| ): SerializedAssignRoleOptions => ({ | ||
| role_slug: options.roleSlug, | ||
| ...(options.resourceId && { resource_id: options.resourceId }), | ||
| ...(options.resourceExternalId && { | ||
| resource_external_id: options.resourceExternalId, | ||
| }), | ||
| ...(options.resourceTypeSlug && { | ||
| resource_type_slug: options.resourceTypeSlug, | ||
| }), | ||
| }); |
19 changes: 19 additions & 0 deletions
19
src/authorization/serializers/authorization-resource.serializer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { | ||
| AuthorizationResource, | ||
| AuthorizationResourceResponse, | ||
| } from '../interfaces/authorization-resource.interface'; | ||
|
|
||
| export const deserializeAuthorizationResource = ( | ||
| resource: AuthorizationResourceResponse, | ||
| ): AuthorizationResource => ({ | ||
| object: resource.object, | ||
| id: resource.id, | ||
| externalId: resource.external_id, | ||
| name: resource.name, | ||
| description: resource.description, | ||
| resourceTypeSlug: resource.resource_type_slug, | ||
| organizationId: resource.organization_id, | ||
| parentResourceId: resource.parent_resource_id, | ||
| createdAt: resource.created_at, | ||
| updatedAt: resource.updated_at, | ||
| }); |
19 changes: 19 additions & 0 deletions
19
src/authorization/serializers/create-authorization-resource-options.serializer.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import { | ||
| CreateAuthorizationResourceOptions, | ||
| SerializedCreateAuthorizationResourceOptions, | ||
| } from '../interfaces/authorization-resource.interface'; | ||
|
|
||
| export const serializeCreateResourceOptions = ( | ||
| options: CreateAuthorizationResourceOptions, | ||
| ): SerializedCreateAuthorizationResourceOptions => ({ | ||
| organization_id: options.organizationId, | ||
| resource_type_slug: options.resourceTypeSlug, | ||
| external_id: options.externalId, | ||
| name: options.name, | ||
| ...(options.description !== undefined && { | ||
| description: options.description, | ||
| }), | ||
| ...(options.parentResourceId !== undefined && { | ||
| parent_resource_id: options.parentResourceId, | ||
| }), | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.