Skip to content

Commit 5c83985

Browse files
konlanxCopilot
andauthored
fix(core): add response bodies for organization user endpoints (#8626)
* fix(core, api): add respone bodies for organization user endpoints - Added body to `/api/organizations/{id}/users` - Added body to `/api/organizations/{id}/users/{userId}/roles` * fix(core, api): add response bodies for organization user endpoints - Added changeset * fix(core, api): add response bodies for organization user endpoints - Added unit tests * fix(core, api): add response bodies for organization user endpoints - Fixed changeset file - Reorganized tests into two files * fix(core): add response bodies for organization user endpoints - Review suggestions Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * fix(core, api): add response bodies for organization user endpoints - review suggestions * fix(core, api): add response bodies for organization user endpoints - review suggestions --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent d2c6642 commit 5c83985

7 files changed

Lines changed: 432 additions & 352 deletions

File tree

.changeset/bright-planes-dance.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
"@logto/integration-tests": patch
3+
"@logto/core": patch
4+
---
5+
6+
return response bodies from organization user and role assignment APIs
7+
8+
- POST `/organizations/:id/users` now returns `{ userIds: string[] }` echoing the user IDs that were sent with the request
9+
- POST `/organizations/:id/users/:userId/roles` now returns `{ organizationRoleIds: string[] }` with the final deduplicated role IDs that were assigned, resolved from any provided role names

packages/core/src/routes/organization/user/index.openapi.json

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,23 @@
2525
},
2626
"responses": {
2727
"201": {
28-
"description": "Users were added to the organization successfully."
28+
"description": "Users were added to the organization successfully.",
29+
"content": {
30+
"application/json": {
31+
"schema": {
32+
"type": "object",
33+
"properties": {
34+
"userIds": {
35+
"type": "array",
36+
"items": {
37+
"type": "string"
38+
},
39+
"description": "An array of user IDs processed from the request. This may include IDs that were already members of the organization."
40+
}
41+
}
42+
}
43+
}
44+
}
2945
},
3046
"422": {
3147
"description": "At least one of the IDs provided is not valid. For example, the organization ID or user ID does not exist."
@@ -180,7 +196,23 @@
180196
},
181197
"responses": {
182198
"201": {
183-
"description": "Roles were assigned to the user successfully."
199+
"description": "Roles were assigned to the user successfully.",
200+
"content": {
201+
"application/json": {
202+
"schema": {
203+
"type": "object",
204+
"properties": {
205+
"organizationRoleIds": {
206+
"type": "array",
207+
"items": {
208+
"type": "string"
209+
},
210+
"description": "An array of organization role IDs that were assigned to the user, deduplicated and resolved from any provided role names."
211+
}
212+
}
213+
}
214+
}
215+
}
184216
},
185217
"422": {
186218
"description": "The user is not a member of the organization; or at least one of the IDs provided is not valid. For example, the organization ID or organization role ID does not exist; or at least one of the role names provided is not valid. For example, the organization role name does not exist."

packages/core/src/routes/organization/user/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export default function userRoutes(
5454
koaGuard({
5555
params: z.object({ id: z.string().min(1) }),
5656
body: z.object({ userIds: z.string().min(1).array().nonempty() }),
57+
response: z.object({ userIds: z.string().min(1).array() }),
5758
status: [201, 403, 422],
5859
}),
5960
async (ctx, next) => {
@@ -72,6 +73,7 @@ export default function userRoutes(
7273
...userIds.map((userId) => ({ organizationId: id, userId }))
7374
);
7475

76+
ctx.body = { userIds };
7577
ctx.status = 201;
7678

7779
// Trigger hook event

packages/core/src/routes/organization/user/role-relations.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export default function userRoleRelationRoutes(
7474
organizationRoleIds: z.string().min(1).array().optional(),
7575
organizationRoleNames: z.string().min(1).array().optional(),
7676
}),
77+
response: z.object({ organizationRoleIds: z.string().min(1).array() }),
7778
status: [201, 422],
7879
}),
7980
async (ctx, next) => {
@@ -110,6 +111,7 @@ export default function userRoleRelationRoutes(
110111
}))
111112
);
112113

114+
ctx.body = { organizationRoleIds: roleIds };
113115
ctx.status = 201;
114116
return next();
115117
}

packages/integration-tests/src/api/organization.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,10 @@ export class OrganizationApi extends ApiFactory<Organization, Omit<CreateOrganiz
4646
});
4747
}
4848

49-
async addUsers(id: string, userIds: string[]): Promise<void> {
50-
await authedAdminApi.post(`${this.path}/${id}/users`, { json: { userIds } });
49+
async addUsers(id: string, userIds: string[]): Promise<{ userIds: string[] }> {
50+
return authedAdminApi
51+
.post(`${this.path}/${id}/users`, { json: { userIds } })
52+
.json<{ userIds: string[] }>();
5153
}
5254

5355
async replaceUsers(id: string, userIds: string[]): Promise<void> {
@@ -71,10 +73,12 @@ export class OrganizationApi extends ApiFactory<Organization, Omit<CreateOrganiz
7173
userId: string,
7274
organizationRoleIds: string[],
7375
organizationRoleNames?: string[]
74-
): Promise<void> {
75-
await authedAdminApi.post(`${this.path}/${id}/users/${userId}/roles`, {
76-
json: { organizationRoleIds, organizationRoleNames },
77-
});
76+
): Promise<{ organizationRoleIds: string[] }> {
77+
return authedAdminApi
78+
.post(`${this.path}/${id}/users/${userId}/roles`, {
79+
json: { organizationRoleIds, organizationRoleNames },
80+
})
81+
.json<{ organizationRoleIds: string[] }>();
7882
}
7983

8084
async replaceUserRoles(

0 commit comments

Comments
 (0)