Skip to content
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

feat(rest-api-client): add space.updateSpaceMembers() method #2603

Merged
merged 17 commits into from
Mar 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions examples/rest-api-client-demo/src/space.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,42 @@ export class Space {
console.log(error);
}
}

public async updateSpaceMembers() {
const spaceMembers = {
id: SPACE_ID,
members: [
{
entity: {
type: "USER" as const,
code: "user1",
},
isAdmin: true,
includeSubs: false,
},
{
entity: {
type: "USER" as const,
code: "user2",
},
isAdmin: false,
includeSubs: false,
},
{
entity: {
type: "GROUP" as const,
code: "group1",
},
isAdmin: false,
includeSubs: true,
},
],
};

try {
console.log(await this.client.space.updateSpaceMembers(spaceMembers));
} catch (error) {
console.log(error);
}
}
}
25 changes: 25 additions & 0 deletions packages/rest-api-client/docs/space.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- [getSpace](#getSpace)
- [deleteSpace](#deleteSpace)
- [updateSpaceBody](#updateSpaceBody)
- [updateSpaceMembers](#updateSpaceMembers)

## Overview

Expand Down Expand Up @@ -116,3 +117,27 @@ An empty object.
#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/update-space-body/

### updateSpaceMembers

Updates the members of a Space.

#### Parameters

| Name | Type | Required | Description |
| --------------------- | :--------------: | :---------: | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| id | Number or String | Yes | The space ID. |
| members | Array | Yes | A list of members of the Space. <br />At least one Space Administrator must be specified.<br /> Inactive and deleted users cannot be specified. |
| members[].entity | Object | Yes | The entity information of the Space member. <br />Guest users cannot be specified. |
| members[].entity.type | String | Yes | The entity type of the Space member.<br /><ul><li><strong>USER</strong>: User</li><strong>Group</strong>: Group</li><strong>ORGANIZATION</strong>: Department</li><ul> |
| members[].entity.code | String | Yes | The code of the entity. |
| members[].isAdmin | Boolean | Conditional | The Space Administration settings of the user.<br /><ul><strong>true</strong>: The member will be the Administrator of the Space.<br /><li><strong>false</strong>: The member will not be the Administrator of the Space.<br />At least 1 Space Administrator is required to be set in the API call.</li></ul><br />If ignored, this value is false. |
| members[].includeSubs | Boolean | Optional | The "Include Affiliated Departments" settings of the department.<br /><ul><strong>true</strong>: Affiliated departments will be included.<br /><li><strong>false</strong>: Affiliated departments will not be included.</li></ul><br />If ignored, this value is false. |

#### Returns

An empty object.

#### Reference

- https://kintone.dev/en/docs/kintone/rest-api/spaces/update-space-members/
12 changes: 11 additions & 1 deletion packages/rest-api-client/src/client/SpaceClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { SpaceID, Space } from "./types";
import type { SpaceID, Space, SpaceMemberForRequest } from "./types";
import { BaseClient } from "./BaseClient";

export class SpaceClient extends BaseClient {
Expand All @@ -22,4 +22,14 @@ export class SpaceClient extends BaseClient {
});
return this.client.put(path, params);
}

public updateSpaceMembers(params: {
id: SpaceID;
members: SpaceMemberForRequest[];
}): Promise<{}> {
const path = this.buildPathWithGuestSpaceId({
endpointName: "space/members",
});
return this.client.put(path, params);
}
}
42 changes: 42 additions & 0 deletions packages/rest-api-client/src/client/__tests__/SpaceClient.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,48 @@ describe("SpaceClient", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});

describe("updateSpaceMembers", () => {
const params = {
id: SPACE_ID,
members: [
{
entity: {
code: "user1",
type: "USER" as const,
},
isAdmin: true,
},
{
entity: {
code: "user2",
type: "USER" as const,
},
isAdmin: false,
},
{
entity: {
code: "group1",
type: "GROUP" as const,
},
isAdmin: false,
includeSubs: true,
},
],
};
beforeEach(async () => {
await spaceClient.updateSpaceMembers(params);
});
it("should pass the path to the http client", () => {
expect(mockClient.getLogs()[0].path).toBe("/k/v1/space/members.json");
});
it("should send a PUT request", () => {
expect(mockClient.getLogs()[0].method).toBe("put");
});
it("should pass id, members parameters to the http client", () => {
expect(mockClient.getLogs()[0].params).toEqual(params);
});
});
});

describe("SpaceClient with guestSpaceId", () => {
Expand Down
7 changes: 7 additions & 0 deletions packages/rest-api-client/src/client/types/space/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { App } from "../app";
import type { Entity } from "../entity";

type AttachedApp = Pick<
App,
Expand Down Expand Up @@ -30,3 +31,9 @@ export type Space = {
attachedApps: AttachedApp[];
fixedMember: boolean;
};

export type SpaceMemberForRequest = {
entity: Entity;
isAdmin?: boolean;
includeSubs?: boolean;
};
Loading